r3f-materials
enzed/r3f-skills
Choose and configure React Three Fiber surface materials, PBR, transparency, and transmission.
What is r3f-materials?
Guidance for selecting and configuring Three.js materials in React Three Fiber, including PBR surfaces, transparency, glass, and custom shaders. Use this when building 3D mesh appearance, optimizing material cost, or implementing advanced effects like transmission and reflection.
- Select appropriate material types (meshBasicMaterial, meshStandardMaterial, meshPhysicalMaterial, meshToonMaterial, ShaderMaterial) based on visual and performance needs
- Configure PBR properties: metalness, roughness, color, emissive, and texture maps with correct color spaces
- Implement transparency and glass using opacity, alphaTest, depthWrite, and physical transmission with IOR and thickness
- Use environment lighting and Lightformer for realistic PBR surface rendering
- Manage material lifetime, sharing, cloning, and texture disposal in React Three Fiber's declarative model
- Optimize transmission and reflection passes with Drei helpers (MeshTransmissionMaterial, MeshReflectorMaterial)
How to install r3f-materials
npx skills add https://github.com/enzed/r3f-skills --skill r3f-materials- React Three Fiber 9+ and React 19 (examples use these versions)
- Three.js renderer and WebGL context (WebGPU compatibility varies by material type)
- Drei library for advanced materials like MeshTransmissionMaterial and MeshReflectorMaterial (optional)
How to use r3f-materials
- 1.Inspect your installed Fiber, Three.js, and Drei versions to confirm compatibility
- 2.Choose a material type from the reference table based on your visual need and constraints
- 3.Configure PBR properties (metalness, roughness, color, maps) using correct color spaces (sRGB for color/emissive, NoColorSpace for roughness/metalness/normal)
- 4.For transparency, enable `transparent` for alpha blending or use `alphaTest` for cutouts; use physical transmission for glass with `thickness` and IOR
- 5.For advanced effects, use Drei helpers like MeshTransmissionMaterial or MeshReflectorMaterial, starting with low resolution and measuring GPU cost
- 6.Test the result under intended lighting, output pipeline, and overlap scenarios; validate shadows and repeated mount/unmount behavior
Use cases
- Building realistic PBR surfaces with metallic or dielectric properties and environment lighting
- Creating transparent or glass objects with proper depth sorting and physical transmission
- Debugging geometry and normals using meshNormalMaterial or inspecting texture color spaces
- Implementing stylized or toon shading for non-photorealistic rendering
- Optimizing GPU cost by choosing the least complex material that meets visual requirements
- React Three Fiber developers building 3D web experiences
- Graphics engineers optimizing material and rendering performance
- Game or visualization developers implementing PBR or stylized surfaces
- Developers working with glTF models and inherited material configurations
r3f-materials FAQ
Use meshStandardMaterial for ordinary PBR surfaces. Use meshPhysicalMaterial only if you need clearcoat, transmission, or sheen; it requires more shader work and should have those features enabled only when needed.
For glass, use physical transmission with `opacity={1}`, a meaningful `thickness`, and appropriate IOR. For ordinary transparency, enable `transparent` and set `opacity < 1`. For cutouts (foliage, decals), consider `alphaTest` to avoid sorting artifacts.
PBR appearance changed across recent Three.js releases. Validate with controlled lighting and exposure rather than blindly adding lights or color conversion. Check the Three.js migration guide.
Share materials when objects should have identical appearance. Clone before changing one instance's color, maps, or uniforms. Disposing a material does not dispose its textures, so manage texture lifecycle separately.
Drei helpers like MeshTransmissionMaterial and MeshReflectorMaterial add scene renders. Start with low resolution and samples, measure GPU cost before enabling backside passes or independent buffers per object.
Full instructions (SKILL.md)
Source of truth, from enzed/r3f-skills.
name: r3f-materials description: Choose and configure React Three Fiber surface materials, PBR, transparency, and transmission. Use for mesh appearance and material cost; use shader guidance for custom GLSL or TSL code.
React Three Fiber materials
Inspect the installed renderer, Three.js, Fiber, and Drei versions first. Examples use Fiber 9 / React 19 with WebGL. Do not assume Drei shader-based materials work unchanged with WebGPU.
Choose the least complex material that fits
| Need | Starting point | Constraint |
|---|---|---|
| Unlit artwork or UI surface | meshBasicMaterial | Still participates in output color/tone-mapping policy |
| Ordinary PBR surface | meshStandardMaterial | Metals especially need an environment or suitable lights |
| Clearcoat, transmission, sheen | meshPhysicalMaterial | Enable only needed features; more shader work |
| Stylized lighting | meshToonMaterial | Needs lights; gradient maps need appropriate filtering |
| Normal debugging | meshNormalMaterial | Useful for geometry/normal inspection |
| Custom shading | ShaderMaterial or node material | Match WebGL/GLSL versus WebGPU/TSL |
PBR surface with environment lighting
Mount below Canvas. This small procedural environment avoids a remote preset dependency.
import { Environment, Lightformer } from '@react-three/drei'
export default function Example() {
return (
<>
<Environment resolution={64} frames={1}>
<Lightformer position={[0, 3, 2]} scale={[5, 5, 1]} intensity={3} />
</Environment>
<mesh>
<sphereGeometry args={[1, 32, 24]} />
<meshStandardMaterial color="goldenrod" metalness={1} roughness={0.3} />
</mesh>
</>
)
}
PBR and color decisions
- Use metalness near 0 for dielectrics and near 1 for bare metals; intermediate values usually describe mixtures or texture filtering. Roughness controls microsurface response, not opacity.
- Color/albedo and emissive textures use sRGB; roughness, metalness, normal, AO, and masks use
NoColorSpace. Preserve correctly loaded glTF texture metadata. - Maps multiply scalar settings: a metalness map with
metalness={0}has no effect; an emissive map needs a nonblack emissive color. - A normal map alters shading; a displacement map alters vertices and needs enough geometry subdivisions. Normal maps do not alter the silhouette.
- An emissive surface does not illuminate nearby geometry or automatically produce a halo. Add appropriate lighting and a bloom pipeline when those effects are required.
- PBR appearance changed across recent Three.js releases. Validate with controlled lighting/exposure; do not blindly compensate for an upgrade with extra lights or color conversion.
Transparency and glass
opacity < 1needstransparentfor ordinary alpha blending. For cutout foliage or decals, consideralphaTestto avoid sorting artifacts; choose soft transparency only when required.depthWrite={false}can help some transparent layers but is not a universal fix. Test overlap order, backfaces, and intersection with opaque objects.- Use physical transmission for glass, generally with opacity 1 and a meaningful
thickness/IOR. Transmission is not equivalent to ordinary transparency. - Drei
MeshTransmissionMaterialandMeshReflectorMaterialadd scene renders. Start with low resolution/samples, and measure before enabling backside passes or one independent buffer per object. - A shared transmission sampler is cheaper in some scenes but cannot reproduce all visibility between transparent/transmissive objects. Read the helper's documentation before choosing it.
- Do not enable
DoubleSideeverywhere: it changes rendering cost and may hide incorrect winding or normals.
Lifetime and updates
- Share materials when objects should share appearance. Clone before changing one instance's color, maps, or uniforms; a cached glTF material may be used elsewhere.
- R3F owns declarative material children. Externally allocated/shared materials need explicit lifecycle ownership. Disposing a material does not dispose its textures.
- Animate ordinary material properties through typed refs. Value changes such as roughness or color do not require
needsUpdate; shader feature changes such as adding/removing a map can require recompilation. - Material arrays require matching geometry groups. An array alone does not assign arbitrary materials to faces.
Verify
Render under the intended lighting and output pipeline, then test transparent overlaps, shadows, and repeated mount/unmount. Compare GPU cost before adding transmission or reflection passes.
Sources
Related skills
More from enzed/r3f-skills and the wider catalog.

r3f-physics
Add Rapier physics simulation to React Three Fiber with rigid bodies, colliders, forces, and joints.

r3f-postprocessing
Configure React Three Fiber postprocessing: bloom, selection effects, ambient occlusion, and depth of field.

r3f-shaders
Implement custom GLSL or TSL materials in React Three Fiber with uniforms and vertex deformation.

r3f-textures
Configure textures in React Three Fiber: color spaces, UV channels, sampling, video, and render targets.

bb-browser
Browser automation with login state for accessing public and private information across 36+ platforms.

fusion-code-conventions
Enforce TypeScript, React, C#, and Markdown code conventions, ADR compliance, and intent documentation.