Skip to content

Materials

A shape’s material selects a shading model and its options. The type is a discriminated union on shader, so each model only accepts the options it understands.

<Sphere material={{ shader: 'phong', ambient: 0.2, shininess: 32 }} />

Omit shader and you get lambert.

shaderOptions beyond ambient
lambert (default)—
phongshininess, highlightColor
cellsteps, smoothness
fresnelshininess, highlightColor
matcapshininess, highlightColor — takes no ambient
anisotropicshininess, smoothness, highlightColor, grain, grainScale, grainType
glassits own page — see Glass

All of them accept roughness and roughnessScale.

anisotropic is fabric’s own — a directional grain, with grainType selecting between a dotted and a lined pattern. It is not the same thing as glass’s anisotropy, which smears the background sample rather than shading a surface.

Materials are selected by ID in the shader

Section titled “Materials are selected by ID in the shader”

updateSDFBuffers converts shader to a numeric ID stored in the shape record, and the fragment shader branches on it. The IDs are not contiguous — 5 is a retired slot. A wireframe material occupied it for one day in April and was removed.

You will not encounter the IDs unless you are adding a model, but the gap is deliberate rather than a bug.

A <Mesh> supports lambert, phong, roughness and glass. It does not share this list, and it is stripped from the bundle by separate markers. An option that works on a shape does not necessarily exist on a mesh — see Mesh engine.

Each model is a branch in one shader. Unused models are stripped at build time along with their WGSL, so a scene using only lambert does not carry the others.