3D scene lighting
This page demonstrates Light3D with metallic-roughness PBR materials (a Cook-Torrance microfacet BRDF, like three.js MeshStandardMaterial): ambient light as a base, a cool directional fill, and a warm spot light orbiting the scene center. Three objects with different metallic / roughness settings make it easy to compare a rough dielectric, a polished metal, and a smooth dielectric.
Implementation references packages/webcomponents/examples/main.ts and Lesson 39 — 3D mesh rendering.
Interactive example
Notes
- Light types:
ambientcontributes color and intensity only;directional,point, andspotare packed into the scene light array (max 8 lights; see themesh3dshader). - Custom lights: spawning any
Light3Dreplaces the default ambient + directional bundle; if nodirectionalis provided, the renderer adds a weak directional fill so meshes are not fully black. - Coordinates:
positionanddirectionuse the same canvas world units asTransform3D(about 1 px in linked mode).directionpoints from the light toward the lit scene; the renderer normalizes it. - Spot lights:
innerConeAngleandouterConeAngleare in radians;range <= 0disables distance attenuation (same as the webcomponents example). - Materials:
Material3Duses a metallic-roughness workflow.metallic(0 = dielectric, 1 = metal) androughness(0 = mirror-smooth, 1 = fully rough) drive the Cook-Torrance specular response;baseColoris the albedo (and reflectance tint for metals). The legacyambient,diffuse,specular, andshininessfields are kept for backward compatibility —ambientstill scales the ambient term, butdiffuse/specular/shininessno longer affect shading. - Animation: each frame updates the spot via
spotLight.write(Light3D);MeshPipeline3Drepacks lights when the component changes.
Compared to the cube example
| Topic | cube-perspective | This page |
|---|---|---|
| Lights | Renderer default ambient + directional | Explicit multiple Light3D nodes |
| Objects | Single white cube | Three cubes with different material params |
| Motion | Mesh rotation only | Mesh rotation + spotlight orbit |
| Default tool | Select | Select (Pick3D requires the Select tool) |