Skip to content

Documentation / @ripl/3d / shadeSurface

Function: shadeSurface() ​

shadeSurface(normal, position, viewDirection, surface, lights, out): SurfaceIllumination

Defined in: 3d/src/core/shading.ts:163

Resolves the light arriving at a surface point, writing into out rather than allocating.

This is the single source of truth for the lighting model: the CPU painter calls it per face and the WGSL fragment shader mirrors it term for term, so the two backends agree by construction rather than by review. Falloff and cone attenuation match three.js's conventions so a rig tuned against those conventions reads the same here.

Parameters ​

ParameterTypeDescription
normalVector3The unit-length world-space surface normal.
positionVector3The world-space point being shaded.
viewDirectionVector3The unit-length direction from the surface towards the camera.
surfaceResolvedSurfaceThe surface's specular and emissive terms.
lightsResolvedLight[]The lights illuminating the scene.
outSurfaceIlluminationThe illumination to write into, reused across calls.

Returns ​

SurfaceIllumination

out, for convenience.