threejs-shaders
Installation
SKILL.md
three.js Shaders and Materials
Role
Workflow for custom surface shading and shader effects in three.js without breaking the engine's lighting, shadows, or fog - which is where most custom shaders lose their AAA look. This skill owns the approach choice, effect recipes, integration rules, and QA. Scene setup, IBL, and post-processing live in threejs-pipeline; textures come from pbr-texture-gen.
Choosing the Approach
Work down this ladder; stop at the first level that covers the need.
- Built-in PBR materials.
MeshStandardMaterial+MeshPhysicalMaterialalready cover most AAA surfaces:clearcoat(car paint, lacquer),sheen(fabric, velvet),transmission+thickness+ior(glass, liquids),iridescence(soap, oil),anisotropy(brushed metal, hair). A custom shader for something a built-in property or a texture map already does is a maintenance liability, not an upgrade. - TSL node materials (
three/webgpu+three/tsl) for custom logic on new projects. TSL compiles to WGSL on WebGPU and GLSL on the automatic WebGL 2 fallback, so one implementation covers both. Assign nodes onMeshStandardNodeMaterial/MeshPhysicalNodeMaterial:colorNode,normalNode,roughnessNode,metalnessNode,emissiveNode,positionNode(vertex displacement),opacityNode. Engine lighting keeps working because you feed inputs into the PBR pipeline instead of replacing it. - GLSL on WebGLRenderer-only projects: patch built-ins with
material.onBeforeCompile(inject uniforms, replace#includechunks) so lights, shadows, and fog stay intact. Reserve rawShaderMaterialfor genuinely unlit work - skybox, FX quads, particles, post passes.