npx skills add ...
npx skills add enzed/r3f-skills --skill r3f-shaders
Implement custom GLSL or TSL materials in React Three Fiber, including uniforms and vertex deformation. Use for shader code and shader debugging, rather than ordinary PBR settings or composer effects.
npx skills add enzed/r3f-skills --skill r3f-shaders
Inspect installed Fiber, Drei, Three.js, and renderer versions first. The example uses Fiber 9 / React 19 and WebGL. Preserve an existing project's versions.
shaderMaterial or a native <shaderMaterial>.ShaderMaterial and onBeforeCompile are not portable to it. Read WebGPU and TSL only when that renderer is relevant.Mount beneath Canvas. Keep the material class and extend call outside render; the local component avoids global JSX augmentation.
shaderMaterial creates uniform accessors: assign material.uTime. Native ShaderMaterial uses material.uniforms.uTime.value.material.needsUpdate for a value-only uniform change.key for hot reload; do not change React keys during animation.extend(Class) is available in Fiber 9. For a lowercase global element, augment ThreeElements with ThreeElement<typeof Class>; removed Object3DNode is not a replacement for material typing.${ anywhere in the GLSL, including in its comments, silently ends the string and breaks the module. Write shader comments without backticks and let the type-checker catch it rather than reading for it.normalMatrix * normal is view space; do not dot it with a world-space camera direction.Color are converted to the linear working space. Numeric uniform vectors are already linear; avoid converting them twice.SRGBColorSpace; data textures use NoColorSpace. Texture sampling and output conversion must match the material/renderer pipeline.instanceMatrix and any per-instance attributes. Skinning and morph targets likewise require their corresponding shader logic.Use onBeforeCompile only when retaining a built-in material's lighting is useful. Shader chunk names are version-sensitive: inspect the installed source, and render-test after a Three.js update.
Set the callback before first compilation. When a configuration changes generated GLSL, provide a matching customProgramCacheKey and trigger recompilation; keep animated values in uniforms. Do not assume .clone() or serialization preserves callbacks. Prefer node materials when the task already targets WebGPU.