Your system asks for reduced motion, so VFX-JS draws nothing. Demos on this site show plain HTML.
Class
GlassEffect
effects/src/glass.ts:888 ↗import { GlassEffect } from "@vfx-js/effects";Turns the element's silhouette into a block of dispersive glass: the alpha is extruded into 3D and ray-traced with refraction, internal reflections and a rainbow split of the light.
vfx.add(img, { effect: new GlassEffect({ backdrop: "grid" }) });
The silhouette is the element's alpha (or the channel
sourceChannel picks), read back
when the effect starts and again when the element's aspect ratio
changes. Call refresh() after its
content changes. An opaque photo becomes a slab. The glass shows a
backdrop behind it, a procedural pattern or an image, not the page:
the output is opaque where the backdrop is seen and premultiplied over
transparency elsewhere.
The camera (OrbitCameraParams: yaw, pitch,
orbitAnimation, fov, …) works as in SwirlParticleEffect,
with angles in degrees. Its defaults here: the glass turned by yaw 29
and pitch 14, a faster orbit animation (orbitSpeed 3.3), and
zoom 0.7, so the glass is a little smaller than the element. Set drag: true to orbit it with
pointer drags that start on the element, and pointer: "tilt" to turn
it towards the pointer. With cameraOrigin: "viewport", set
pad: "fullscreen" to leave room for an off-centre element to lean out
of its rect.
All params are read every frame, so you can mutate params live.
- Implements
-
Effect - Interface members
-
disposeinitoutputRectrender
Constructors
new GlassEffect()
new GlassEffect(
initial?: Partial<GlassParams> = {},
opts?: GlassEffectOptions = {},
): GlassEffect
Properties
params
params: GlassParams
Methods
refresh
refresh(): void
Capture the element's silhouette again, for when its content
changed: an image's src swapped, a text edit. For an <img>,
call it after vfx.update(img) has reloaded the image.
The glass keeps the current shape until the new one has been read back (a few frames later), then switches to it. A change of the element's aspect ratio is recaptured automatically once its size settles; a change of size alone needs none.
Safe to call at any time and any number of times; a call while a capture is pending restarts it, so the latest content wins.
setParams
setParams(updates: Partial<GlassParams>): void