Learning on Web Dev Open is free for all.

Immersive Web > The 3D mental modelLights, materials and what physical accuracy costs
Phase 07The 3D mental model337 of 434

Lights, materials and what physical accuracy costs

Roughness and metalness are a physical model with a price, and shadows are a second render of your whole scene.

Concept16 minAI adversary

A physically based material describes a surface by roughness, metalness and a base colour, and the shader evaluates a reflectance model per pixel per light. This is why materials and lights are not independent costs: adding a light recompiles a longer fragment shader that every covered pixel then runs. Three well-placed lights and an environment map beat eight lights in both quality and speed, essentially always.

Shadows are the expensive part and nobody says so. A shadow-casting light renders the whole scene again from the point of view of the light into a depth texture, every frame, and then every lit fragment samples that texture. Two shadow-casting lights means three renders of your geometry per frame. Bake what does not move, use one shadow-casting key light, and let a soft contact shadow under an object do the work a second light was going to do badly.

Not everything needs to be lit. An unlit material is one texture lookup and is correct for UI, background fields, glowing elements and anything stylised. Reaching for the physically based material by default is the graphics equivalent of reaching for a framework: fine when you need it, expensive when you do not, and the model will always reach for it.

You should now be able to

  • Choose between an unlit, a lambert and a physically based material
  • Estimate what one shadow-casting light costs
  • Explain why more lights make the shader longer, not the loop
Ask the community

Loading…