/ghibli-threejs:threejs-webgl-underwater-effectfrom ghibli-threejs
Renders a convincing underwater view in three.js with Snell's window, total internal reflection, teal fog, light shafts, bubbles, and an over-under split lens when the camera crosses the water surface.
Ships in ghibli-threejs. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Drag the orbit below the waterline and the scene turns into a river seen from inside: a bright
circular window of the sky and banks overhead (squeezed into a ~97° cone), a mirror of the riverbed
around it, deep-teal fog, shafts of sunlight falling at the refracted angle, bubbles rising
past the lens, and a gentle wobble. While the lens is at the surface the frame splits: the banks above, the
riverbed below, a wavy meniscus between them. Built on the water from threejs-webgl-realistic-water (same
refraction/reflection targets, same patched MeshStandardMaterial, side: DoubleSide) in a
three.js WebGLRenderer + EffectComposer pipeline; works in R3F by doing the same in useFrame.
Let me drag the orbit camera below the water surface in
{{entry file}}. From below, show Snell's window (the world above within the 48.6° critical cone, total internal reflection outside it), a teal underwater fog, light shafts along the refracted sun direction, rising bubbles and a gentle wobble. Add an 'Underwater' preset view that starts underwater looking up at{{main subject}}. While the camera is at the surface, split the frame: above the live waterline show the world above the water, below it the underwater view, with a dark meniscus and a water film on the lens. Warm up the underwater shaders at load so the first dive doesn't hitch. Screenshot above, at the surface and below before and after.
maxPolarAngle to ~0.97π.controls.update(): clamp camera.y ≥ bed + 0.14; push it out of |y − waterHeight| < 0.05
so the near plane never slices the surface:
if (bed < -.1 && |y − hw| < .05) y = hw + (y < hw ? −.05 : .05).
With the over-under lens (§7) skip this push wherever the lens can split (bed ≤ −.25): the lens
handles the waterline itself, and the ±5 cm jump makes the split line leap.under = camera.y < waveHeight(x, z) && terrainHeight(x, z) < 0 (use the live wave height if
the water displaces, not y = 0).underlayers.set(0)), so the world above is available.(0, −1, 0)) to keep what's below the surface —
that's the total internal reflection image. The same flip works whether the cut is a clipping
plane or the mirror camera's oblique near plane (threejs-webgl-realistic-water §1).FogExp2 ≈ 0.17), hide sky dome, stars, rain and
above-water god rays; scene.background = fog colour; enable the underwater post pass.!gl_FrontFacing)float cosI = max(dot(-Nw, V), 0.);
vec2 wob = Nw.xz * .09 / (1. + surfZ*.08); // strong wobble
vec3 above = texture2D(tRefract, suv + wob).rgb * vec3(.82, 1., .98);
vec4 rcu = uReflMat * vec4(vWPos, 1.);
vec3 mirror = texture2D(tReflect, rcu.xy/rcu.w + wob*.6).rgb;
float win = smoothstep(.62, .70, cosI); // critical angle 48.6° → cos ≈ .66
vec3 col = mix(mirror*.9, above, win);
col += uSunColor * pow(max(dot(-V, uSunDir), 0.), 180.) * 6. * win; // the sun burning through
col += vec3(.6,.9,.85) * pow(1. - abs(cosI - .66)*6., 6.) * .08 * step(abs(cosI-.66), .16); // bright rim
under)sinR = sinI/1.33, down = (−sun.x/sinI·sinR, −cosR, −sun.z/sinI·sinR).
Fragment: core = |N·V|³ · (1 − |axis·V|⁴), depth fade
smoothstep(−.02, −.12, y)·smoothstep(−.9, −.25, y), streak noise, flicker, × .16 × exp(−dist·.12).p.xz += floor((cam.xz − p.xz)/5 + .5)·5), rising mod(y + t·(.10 + seed·.12), 1.2) − 1.1,
wobbling ±3 cm, discarded above y = 0, drawn as a ring with a highlight.±.0022
(sin(uv.y·22 + t·1.6), cos(uv.x·18 + t·1.3)), cyan grade c·(.72, 1, 1.04) + (0, .012, .016),
heavier vignette.See references/underwater-fx.js (shafts, bubbles, post pass, frame logic).
An underwater view that starts just below the surface looking up at the hero,
e.g. { pos: [3.4, −0.42, 3.4], target: [1.2, 1.4, −0.8] }.
The one-second hitch at the first crossing is shader compilation, not render cost: the
underwater pass, shafts, bubbles and (when the reflection is cut with renderer.clippingPlanes)
the clipped mirror pass of bed and fish all compile on that frame. Make the render loop a named
frame(); at the end of build() (before the loading screen lifts) jump to the underwater view
and render one frame, then one from above. Measured with a ?nowarm switch: first dive
163 ms cold → 10 ms warmed.
In a scene with hundreds of programs the warm-up frames themselves freeze the loading screen. Where
KHR_parallel_shader_compile exists, call renderer.compile() first, in slices of the scene's
children with a yield between them, and poll program.isReady(); compile() reaches invisible
objects too (the hidden shafts and bubbles), so the warm-up frames are left with the post passes
and shadow depth materials.
Treat the lens as a camera-facing plate L = band / tan(fov/2) metres tall (band ≈ 0.30 m: the camera
height over which, at level pitch, the waterline sweeps the whole frame). For a pixel at NDC (x, y):
side(x, y) = L·(x·tanH·right.y + y·tanV·up.y) − (waveHeight(lens point at x) − camera.y) // > 0 above water
Using right.y / up.y (not the forward vector) makes the line follow roll and pitch, and a steep look
down or up falls back to a single side on its own.
waveHeight at 5 points across the lens (camera + right·x·tanH·L) into a float uD[5].
Evaluate side at the frame's edges; if the sign never changes (±1 cm for the chop), render normally.min(y, hw − .06) (under = true), then to max(y, hw + .06), and restore it. The water shader picks its face with
gl_FrontFacing, so the camera has to be on each side of the surface. Set composer.renderToScreen = false. The
result is in readBuffer when the last enabled pass swaps, otherwise in writeBuffer. Copy the first result
to your own target before the second render reuses the buffers.px = side / fwidth(side) gives pixel distance to the line. Blend over
±1.2 px, darken with 1 − .55·exp(−px²/5) (the meniscus), add a bright crest at px ≈ 3, add a silvery
underside just below it, and warp the image above within 26 px so it sags toward the line (a water film on the
port). Add a little high-frequency chop so the line never looks ruled.camera.far ≈ 14 m: fog at 0.17 hides everything past about 12 m, and culling saves the most.
Share one shadow-map update between the passes. For offline capture, drop the cut, since it can give a far
boulder a hard edge.renderWorld(under) now runs twice per frame, so set every per-side visibility explicitly (sky, stars, god
rays, underFX, rain.visible = rainOn && !under). A toggle that is only ever turned off leaks into the
second pass.See references/over-under-lens.js (lens test, join shader, two-pass render, wiring).
|y| < 0.05 gives an ugly accidental split; nudge the
camera off the band. With the lens, don't nudge where it can split, or the line jumps (§1, §7).gl_FrontFacing is decided by the camera, not by a flag).frame() calls + gl.finish(), not rAF — direct calls work in a
hidden tab and give the compile cost exactly.gl_FrontFacing, so keep side: DoubleSide.?nowarm and without; compare the first-dive frame time.threejs-webgl-realistic-water · threejs-fish-school-boids · threejs-camera-guided-tour
· threejs-postprocessing-anime-grade · threejs-webgl-performance-profiling · threejs-cinematic-loading-screen
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Other plugins' skills for the same job
31 skills in this plugin
/threejs-blender-glb-pipelineBuilds a reference-image-driven asset pipeline from headless Blender to GLB for a three.js scene — an asset contract (units, axes, grounding, required mesh/material names, budgets, attachment numbers), one parallel subagent per asset group writing craft_<slug>.py generators, preview renders compared against the reference, measured-bounding-box placement in the web scene, Draco compression, and a scored asset quality pass. Use when the user has a reference picture and wants a 3D scene from it, asks to model props/trees/characters in Blender for three.js, export GLBs, fix glTF export issues (vertex-colour alpha, UV flip, axes, custom normals), compress models, or rate and improve every asset in a scene./threejs-boat-buoyancy-steeringFloats a boat (or any buoyant prop) on three.js water with Gerstner waves generated from one JS table that feeds both the GLSL vertex shader and a CPU waveHeight(), four-probe heave/pitch/roll damped springs, an arc-length drift lane that bends round rocks, click-to-steer W/A/S/D rowing with momentum and drag, an autopilot that pursues the lane back, and a chase camera that keeps the orbit. Use when the user wants a drifting or steerable boat, buoyancy, objects bobbing on waves, Gerstner waves on a river/lake, a boat autopilot, or a follow/chase camera behind a vehicle on water.npx claudepluginhub nicksonthc/ghibli-threejs --plugin ghibli-threejs