threejs-webgl-rain-effect
Skill4 starsChanged 17 days agoMITView on GitHub
Adds clear / rain / thunderstorm weather to a three.js scene driven by one eased wetness value — GPU rain streaks in a camera-following box slanted by wind, rain rings on the water, lightning with Poisson strikes, multi-pulse flashes and delayed Web Audio thunder, denser colder fog, slate/ink storm sky, darker clouds, dimmed sun/moon/stars/god rays, wind gusts and wet (darker, glossier) materials — using a base×factors pattern so nothing compounds. Use when adding rain, storm, lightning, thunder, weather cycle, wet surfaces or overcast mood to WebGL/R3F.
In this repository30 other files it gives its agents.
- threejs-blender-glb-pipelineSkill
- threejs-boat-buoyancy-steeringSkill
- threejs-camera-guided-tourSkill
- threejs-cinematic-loading-screenSkill
- threejs-day-cycle-lightingSkill
- threejs-dreamy-glass-hudSkill
- threejs-first-person-bvh-walkSkill
- threejs-fish-school-boidsSkill
- threejs-floating-island-landmarkSkill
- threejs-ghibli-night-modeSkill
- threejs-ghibli-sky-cloudsSkill
- threejs-ghibli-toon-shadingSkill
- threejs-glb-realism-pipelineSkill
- threejs-gpu-butterfliesSkill
- threejs-headless-visual-verificationSkill
- threejs-hud-objective-markersSkill
- threejs-night-lights-lanternsSkill
- threejs-object-interactionSkill
- threejs-open-world-streamingSkill
- threejs-postprocessing-anime-gradeSkill
- threejs-procedural-vegetationSkill
- threejs-shell-fur-renderingSkill
- threejs-skeletonless-character-animationSkill
- threejs-stylized-rock-materialSkill
- threejs-webaudio-generative-soundtrackSkill
- threejs-webgl-performance-profilingSkill
- threejs-webgl-realistic-waterSkill
- threejs-webgl-underwater-effectSkill
- threejs-webgl-wake-simulationSkill
- threejs-webgl-waterfall-effectSkill
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 66
Keep it on layer 1 so the refraction pass skips it.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Weather: clear, rain and thunderstorm
One number, WEATHER.rain (clear 0, rain 0.7, storm 1), eases toward the selected mode and the
whole scene reads it: rain streaks and water rings scale with it, the sky and clouds go slate by
day and ink by night, the sun dims, fog thickens, materials get wet, and above ~0.75 lightning
starts.
Stack: three.js WebGLRenderer (vanilla or R3F) with ShaderMaterial / onBeforeCompile
patches; assumes a sun-update function (applySun) that writes lights and sky, and optionally a
night blend (threejs-ghibli-night-mode).
When to use
- You want rain, a storm, lightning and thunder, or a weather toggle.
- Storm tints "stick" after returning to clear, or light intensities drift/compound over time.
- Rain looks like a static texture or pops when the camera moves.
Paste-ready prompt
Add weather to
{{scene}}. One eased wetness value (clear 0, rain 0.7, storm 1) drives:
- GPU rain streaks in a camera-following box, slanted by the wind, faded at the lens and the box edge
- rain rings on the water
- lightning: Poisson strikes, multi-pulse flashes, a cold directional burst, the fill light and fog lifted, delayed brown-noise thunder
- denser, colder fog; a slate/ink sky; darker clouds; dimmer sun, moon, stars and god rays; wind gusts
- wet materials: roughness down, colour darker
Alternate a clear day and a storm night across page loads (
?weather=overrides). Expose everything in lil-gui with.listen(), plus a HUD button that cycles the modes. Verify that clear → storm → clear returns to the exact starting light values.
Implementation
State: base × factors (the important part)
- Never multiply lights in place every frame.
applySunwrites the clean state; the weather captures it as a base; each frame writesbase × factors. - Before
applySunruns, restore the base (weatherUndo), because a night blend that skips half its writes in pure day would otherwise capture storm-tinted values as the new base. - Order inside
applySun:weatherUndo() → applyDay() → applyNight(k) → captureBase() → applyWeather(). applySunruns long before the weather module exists. Guard it with a hoistedvar weatherReady = false(set true at the end of the weather module), not aconst, which would hit the temporal dead zone.- Overcast:
darkness d = min(1, rain·1.25)·0.75; sun ×(1 − 0.85·d), hemi ×(1 − .25d), ambient ×(1 − .2d), exposure ×(1 − .18d). At 29 % less sun a rainy day still looked sunny. - Sky stops lerp toward
0x6f7880 / 0x8a939a / 0xa3aaae(day) and0x10151f / 0x1a2230 / 0x2a3240(night); clouds toward0x7a8290 / 0x565d69 / 0x2c313b. Moon ×(1 − .8r), god rays ×(1 − r), stars ×(1 − .92r). - Fog (after the frame sets its base): density
+= rain·0.016; colour toward0x8c969dby day /0x232a36by night ×d·.85. - Code:
references/weather-state.js.
Rain streaks (GPU)
- One instanced quad (6 vertices), up to ~14 000 instances,
instanceCount = RAIN_MAX·density·smoothstep(rain, .02, .4). - Box 26 × 14 × 26 m centred on the camera:
p = cam + (fract(seed − t·speed/box) − .5)·box, x/z drifted by the wind. Speed ~9.5 m/s ± 20 %. - Streak axis = the fall vector
normalize(wind.x, −speed, wind.z); width axis =cross(fall, view). Length 0.32–0.54 m, width 1.2–2 cm. - Alpha fades under the water surface, at the box edge (30–50 % of the box) and right against the
lens (0.9–2.6 m);
(1 − vT)·vT·4tapers each streak. Colour = sky hemisphere colour lerped to pale grey, ×0.55 at night; flashes brighten it (1 + flash·2.5). - Keep it on layer 1 so the refraction pass skips it; hide it underwater; add it to the GTAO-hidden list.
- Code:
references/rain-streaks.js.
Rain rings on the water
In the water normal: a jittered cell grid (two offset layers, ~2.6 cells/m). Each cell's ring
radius is fract(t·rate + hash)·.42, profile sin((L − R)·44)·exp(−((L − R)·13)²)·(1 − age),
and step(hash, rain·.9 + .1) thins the rings at light rain. Fade by 1/(1 + dist·.06).
The same uRain uniform drives rock/terrain wetness (see threejs-stylized-rock-material).
Lightning and thunder
- Poisson process above rain 0.75: next strike at
t − ln(1 − U)·60/(rate·(r − .7)/.3),rate≈ 5 strikes/min at full storm. Seed the first one from the live clock (t + 3..9 s). - Each strike: 2–4 pulses
[offset, amp], flashk = max(amp·exp(−14·(age − offset))). - Flash light: a cold
DirectionalLight(0xdfe6ff)placed high at a random azimuth, intensityk·7; hemi+k·1.6, ambient+k·.5; sky, clouds and fog lerp toward pale blue-white. - Thunder: 4 s of brown noise with a long
(1 − i/len)^1.6tail, low-pass 160–280 Hz, delayed 1.2–3.4 s, gain ∝ rain. Only after the visitor's gesture has started audio.
Wind and wet materials
- Gusts:
uWind = base·(1 + r·1.4·(.75 + .25 sin(.37t) + .15 sin(1.3t)))— trees, grass, swings follow. - Wet: roughness ×
(1 − .5w), colour ×(1 − .2w), withw = rain·wet·2. Take the list only after the models load, record originals once, rescale only whenwmoves > 0.01, and skip materials another system recolours (the night's white-dim list). - Hide fireflies when rain > 0.35.
Modes and UI
Alternate clear day / storm night across page loads (store the last mode in localStorage, in a
try block), ?weather=clear|rain|storm overrides. A HUD button cycles clear → rain → storm.
lil-gui controllers use .listen() so they follow the eased values; a "⚡ strike now" button helps testing.
Pitfalls
- In-place multiplication compounds — values drift every frame (the same bug sent a tour's god-ray strength to 1e167). Always write absolute values from a base.
- TDZ:
const weatherReadyreferenced by an earlyapplySunthrows; use hoistedvar. - Capturing the base after a partial write (the night blend skipping writes in pure day) bakes storm tints in. Undo first, then write the day, then capture.
- Wet-material list taken too early misses every GLB material.
- Timers seeded with small absolute values (
next: 8) fire at once because the frame clock is page time; seed from the first step'st. - Rain in the refraction/AO passes prints dark streak sheets; keep it on layer 1 and AO-hidden.
Verify
- clear → storm → clear: light intensities, sky and cloud colours return to the exact starting values.
- Storm by day and by night, from eye level and looking down on water (rings visible, streaks not blocking the lens), a forced strike, and underwater (no rain).
- Watch the lil-gui wetness value ease over the transition time (~6 s).
Related skills
threejs-day-cycle-lighting · threejs-ghibli-night-mode · threejs-webgl-realistic-water ·
threejs-stylized-rock-material · threejs-ghibli-sky-clouds · threejs-webaudio-generative-soundtrack ·
threejs-webgl-performance-profiling
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

