Skip to content

Public API

The package exports exactly three things:

import { MatrixRainWebGPU, isWebGPUSupported } from 'matrix-rain-webgpu';
import type {
MatrixRainProps,
RainOptions,
ParallaxOptions,
BloomOptions,
CrtOptions,
} from 'matrix-rain-webgpu';
  • MatrixRainWebGPU — the React component.
  • isWebGPUSupported() — a runtime feature check (see Getting started).
  • The option types, exported so you can build a config in a typed variable.

The component renders a single <canvas> that is positioned to fill its parent (position: absolute; inset: 0; pointer-events: none). You size it by sizing the parent. It never throws into your tree: if WebGPU is unavailable or init fails it renders null and reports once.

<div style={{ position: 'relative', width: '100%', height: '100dvh' }}>
<MatrixRainWebGPU />
</div>

Props are organized into groups. The base look lives in rain; the three effect layers — parallax, bloom, crt — are each Options | false: omit for defaults, pass an object to tune, pass false to disable.

PropTypeDefaultNotes
rainRainOptionssee belowGlyph size, density, step rate, trail length.
parallaxParallaxOptions | falsesee belowDepth illusion via per-column speed spread + far-dimming.
bloomBloomOptions | falsesee belowGlow post-process.
crtCrtOptions | falsesee belowScanlines + chromatic aberration.
pausedbooleanfalseFreeze on a settled static frame. The single off-state knob.
classNamestringForwarded to the <canvas>.
onError(err: Error) => voidCalled once if the renderer dies.
FieldTypeDefaultMeaning
fontSizenumber20Glyph cell size, in CSS pixels.
densitynumber0.95Probability (0..1) a column does not respawn each step — higher = sparser.
stepRatenumber10Logical simulation rate in Hz (rows advanced per second).
tailRange[number, number][8, 35][min, max] trail length in cells, rolled per column.
FieldTypeDefaultMeaning
speedRange[number, number][0.4, 1.5][min, max] per-column fall speed; the spread creates the depth illusion.
depthDimnumber0.3How strongly far (slow) columns are dimmed, 0 (flat) .. 1 (deep).

parallax={false} → uniform speed + no dimming (a flat field).

FieldTypeDefaultMeaning
intensitynumber1.5Glow strength multiplier on the extracted bright pass.
thresholdnumber0.8Brightness above which a pixel contributes to the glow (~0..2).
emissionnumber2How hot heads burn into the HDR target (1 = off). >1 pushes heads above the displayable range so bloom has real headroom — see Bloom.

bloom={false} skips the entire extract → blur → combine chain (a real GPU cost saving).

FieldTypeDefaultMeaning
scanlineStrengthnumber0.3Scanline darkening depth, 0 (none) .. 1 (heavy).
aberrationnumber1.0Chromatic-aberration offset in pixels (R/B split along x).

crt={false} swaps the final CRT pass for a plain passthrough.

function isWebGPUSupported(): boolean;

A synchronous best-effort check for navigator.gpu. Use it to decide whether to mount <MatrixRainWebGPU> or a fallback. The component does not feature-detect internally — it relies on the GPU root failing gracefully — so isWebGPUSupported() is the primary support gate for consumers.

onError is called once if the renderer dies — either init failure or a per-frame throw. After that the effect stays dead (no auto-retry). If you don’t pass onError, the error is console.error’d instead. Either way the component renders null and never throws into the host React tree — a background effect must not crash the page.