Shader gradient
An animated WebGL mesh gradient that fills its box.
Installation
pnpm add @heyramzi/uiUsage
import { ShaderGradient } from "@heyramzi/ui/effects/shader-gradient";Keyboard and accessibility
- It's hidden from screen readers.
- With reduced motion on, it draws a still frame. It also pauses offscreen and in a hidden tab.
API reference
classstringcolor1string- Default
"#ff5005" - Warm stop. Any CSS color, including `var(--token)`. Read at the left edge of the plane.
color2string- Default
"#dbba95" - Middle stop. Read at the right edge of the plane.
color3string- Default
"#d0bce1" - Cool stop. Mixed in by the noise displacement, so it rides the crests and troughs.
bgColorstring- Default
"#000000" - Painted behind the mesh. The mesh covers the frame at the default camera, so it only shows at extreme angles.
animateboolean- Default
true - false freezes the field at `uTime`. Forced false when the visitor asks for reduced motion.
brightnessnumber- Default
1.2 - Ambient light. 1 is flat, above 1 lifts the whole field.
cAzimuthAnglenumber- Default
180 - Camera azimuth in degrees.
cPolarAnglenumber- Default
90 - Camera polar angle in degrees.
cDistancenumber- Default
3.6 - Camera distance from the origin.
fovnumber- Default
45 - Vertical field of view in degrees.
positionXnumber- Default
-1.4 positionYnumber- Default
0 positionZnumber- Default
0 rotationXnumber- Default
0 - Mesh rotation in degrees, applied in XYZ order.
rotationYnumber- Default
10 rotationZnumber- Default
50 uDensitynumber- Default
1.3 - Noise density. Higher packs more folds into the same plane.
uSpeednumber- Default
0.4 - Noise travel speed.
uStrengthnumber- Default
4 - Displacement amplitude. Drives how far color3 pushes into the mix.
uTimenumber- Default
0 - Starting time offset in seconds. Two instances with different offsets never sit on the same frame.
grainboolean- Default
true - Halftone dot screen over the render. This is the upstream `grain` switch.
grainRadiusnumber- Default
2 - Halftone dot radius in device pixels.
pixelDensitynumber- Default
1 - Render scale. 1 matches upstream and is enough for a gradient this smooth.
| Prop | Type | Default |
|---|---|---|
class | string | |
color1 Warm stop. Any CSS color, including `var(--token)`. Read at the left edge of the plane. | string | "#ff5005" |
color2 Middle stop. Read at the right edge of the plane. | string | "#dbba95" |
color3 Cool stop. Mixed in by the noise displacement, so it rides the crests and troughs. | string | "#d0bce1" |
bgColor Painted behind the mesh. The mesh covers the frame at the default camera, so it only shows at extreme angles. | string | "#000000" |
animate false freezes the field at `uTime`. Forced false when the visitor asks for reduced motion. | boolean | true |
brightness Ambient light. 1 is flat, above 1 lifts the whole field. | number | 1.2 |
cAzimuthAngle Camera azimuth in degrees. | number | 180 |
cPolarAngle Camera polar angle in degrees. | number | 90 |
cDistance Camera distance from the origin. | number | 3.6 |
fov Vertical field of view in degrees. | number | 45 |
positionX | number | -1.4 |
positionY | number | 0 |
positionZ | number | 0 |
rotationX Mesh rotation in degrees, applied in XYZ order. | number | 0 |
rotationY | number | 10 |
rotationZ | number | 50 |
uDensity Noise density. Higher packs more folds into the same plane. | number | 1.3 |
uSpeed Noise travel speed. | number | 0.4 |
uStrength Displacement amplitude. Drives how far color3 pushes into the mix. | number | 4 |
uTime Starting time offset in seconds. Two instances with different offsets never sit on the same frame. | number | 0 |
grain Halftone dot screen over the render. This is the upstream `grain` switch. | boolean | true |
grainRadius Halftone dot radius in device pixels. | number | 2 |
pixelDensity Render scale. 1 matches upstream and is enough for a gradient this smooth. | number | 1 |