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.
The models
Section titled “The models”shader | Options beyond ambient |
|---|---|
lambert (default) | — |
phong | shininess, highlightColor |
cell | steps, smoothness |
fresnel | shininess, highlightColor |
matcap | shininess, highlightColor — takes no ambient |
anisotropic | shininess, smoothness, highlightColor, grain, grainScale, grainType |
glass | its 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.
Mesh materials are a different set
Section titled “Mesh materials are a different set”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.