Three.js Matrix Digital Rain Shader
Digital rain in Three.js with columns of mirrored katakana and digits from a canvas glyph atlas, each falling at its own speed with a bright leading glyph and fading trail, wrapped around the viewer.
Key topics: three.js matrix rain, digital rain, glyph atlas, shader effect, katakana
Game Over
What this code does
- Glyph Atlas: half-width katakana and digits are drawn mirrored into a canvas texture once.
- Column Hash: every column gets its own speed and phase from a hash, and the head position wraps over time.
- Trails: glyphs behind the head fade with distance, and the leading glyph is drawn almost white.
- Glyph Flicker: each cell picks a new atlas glyph at its own random rate.
- Immersion: the rain covers the inside of a cylinder around the camera, plus a coded torus knot in front.
- Controls: fall speed, trail length, columns, color, centerpiece and auto look-around (drag to look).
Related Demos
Continue Learning
JavaScript Implementation
// Per-column falling heads with fading trails; glyphs come from a canvas atlas
const rainGLSL = `
vec2 g = vUv * vec2(160.0, 46.0);
vec2 cell = floor(g);
float seed = hash(vec2(cell.x, 7.0)); // each column has its own speed/phase
float head = fract(uTime * (0.4 + seed) * 0.08 + seed * 13.0) * 62.0;
float behind = head - (45.0 - cell.y); // rows behind the head
if (behind < 0.0 || behind > 16.0) discard;
float idx = floor(hash(cell + floor(uTime * 4.0)) * 64.0); // glyph flips over time
vec2 auv = (vec2(mod(idx, 8.0), floor(idx / 8.0)) + fract(g)) / 8.0;
float glyph = texture2D(uAtlas, vec2(auv.x, 1.0 - auv.y)).r;
gl_FragColor = vec4(vec3(0.13, 1.0, 0.4) * glyph * (1.0 - behind / 16.0), 1.0);`