Three.js Subsurface Scattering (Translucent Materials)
Real-time translucency in Three.js using a back-face depth pre-pass for screen-space thickness, so thin parts like fingers and knot loops glow when back-lit, with jade, skin, wax and marble presets.
Key topics: three.js subsurface scattering, translucency, sss shader, skin shader, jade, thickness map
Game Over
What this code does
- Thickness Pass: back faces of translucent meshes write their view depth to a half-float render target.
- Screen-Space Thickness: the front pass subtracts its own depth from the back depth to get per-pixel thickness.
- Transmission: light behind the object contributes pow(V·−(L + N·distortion), p) · e^(−σ·thickness).
- Shader Injection: `onBeforeCompile` adds the term to `MeshStandardMaterial`, keeping normal PBR lighting.
- Layers: only translucent objects are drawn in the depth pass, using camera layers and an override material.
- Controls: on/off, presets, scatter color, absorption, normal distortion, power, scale, ambient transmission and light motion.
Related Demos
Continue Learning
JavaScript Implementation
// Fast translucency: thickness from a back-face depth pre-pass
// 1) render back faces' view depth: gl_FragColor = vec4(-mvPosition.z, 0, 0, 1) with side: THREE.BackSide
// 2) in the front pass, inject into MeshStandardMaterial before <opaque_fragment>:
const sssGLSL = `
float backZ = texture2D(uBackDepth, gl_FragCoord.xy / uResolution).r;
float thickness = max(backZ - vViewPosition.z, 0.0);
vec3 L = normalize(uLightView + vViewPosition); // view-space light direction
vec3 H = normalize(L + normal * 0.25); // distorted by the surface normal
float through = pow(clamp(dot(normalize(vViewPosition), -H), 0.0, 1.0), 2.5) * 3.5;
outgoingLight += diffuseColor.rgb * uScatterColor * through * exp(-thickness * 1.6);`