LookMiddleweight
Custom shader materials
A surface you program yourself.
Writing your own surface: a small program decides the color of every point on the object. A plain sphere becomes a planet, a topographic map or a moving signal. Done carelessly, the object stops reacting to the lights in the scene.
- Breaks when
- lose lights and shadows unless you patch them back in
- Also called
- ShaderMaterial, onBeforeCompile, CSM
Prompts
Patched standard material
Keep MeshStandardMaterial’s lighting but replace its color with a procedural pattern: use onBeforeCompile to inject a uniform uTime and a 3D simplex noise into the fragment shader, and replace the diffuseColor line with contour lines of the noise (fract(n × 8) thresholded, anti-aliased with fwidth) in two colors. Shadows and the environment map must keep working; show the same mesh with the stock material next to it to prove nothing else changed.
Bare ShaderMaterial with lighting you wrote
A ShaderMaterial on a torus knot with vertex normals passed to the fragment shader, half-Lambert diffuse from one light uniform, a Fresnel rim, and a stepped specular. Uniforms: uLightDir, uColorA, uColorB, uTime. Explain what you lose compared with MeshStandardMaterial (shadows, env maps, fog) and how to add fog back with the built-in fog chunks.
Same effect in TSL
Write the contour-line material with Three.js TSL nodes for WebGPURenderer: MeshStandardNodeMaterial with colorNode built from mx_noise_float, fract, step and smoothstep nodes, animated by the time node. Confirm it also runs on the WebGL backend without changes.
Related
Resources · 5
- The Study of Shaders with React Three FiberMaximeHeckelsite · code · demoJul 22, 2026
- three.js example: WebAudio visualizermrdoobsite · code · demoJun 12, 2026
- THREE-CustomShaderMaterialInject GLSL into standard materials and keep the lighting.FarazzShaikhGitHub · code · demoMay 28, 2026
- @akellaProfile, not a post. Weekly shader livestream breakdowns.akellaXApr 3, 2026
- Three.js Shading Language (TSL)Write once, compiles to WGSL or GLSL.mrdoobGitHub · codeMar 8, 2026