Builtin Library
- ..
- README.md2.7 KB
- module.wgsl10.1 KB
README.md
scene_lights
The scene's point, spot, area and distant lights as a render-feature compute
pass reads them from @scene.lights: each light's row, the light grid listing
the lights that can reach a place, and the diffuse light each one puts on a
surface point. The falloff, a spot's cone and a rect's integral over its face
are the ones the surfaces are shaded with, so a pass that lights a point
through this module puts on it the diffuse light a surface standing there takes
from the same lights. The shadow is the pass's own: rays zsl_shadow_ray aims,
or the shadow pages light_shadows reads.
The pass binds the scene's light buffer under this name:
# bindings.yaml
- { name: lights, kind: buffer, access: read, element: vec4<f32> }
ctx.enqueue {
kind = "compute", program = prog,
inputs = { lights = "@scene.lights" },
...
}
#include "@builtin::shaderModules.scene_lights"
let near = zsl_near(p);
for (var k = 0u; k < near.count; k = k + 1u) {
let i = zsl_near_light(near, k);
let a = zsl_arrival(i, p, n);
if (a.lit) {
let ray = zsl_shadow_ray(i, p, xi); // xi: a point drawn from [0, 1)^2
radiance += albedo * a.diffuse; // times the visibility along ray
}
}
| Function | What it answers |
|---|---|
zsl_light(i) | The light at row i: position, radius, colour, intensity, direction, cone, kind, two-sidedness, channels, a rect's span axes and half extents. |
zsl_near(p), zsl_near_light(near, k) | The lights that can reach p, the walk the surfaces' light loop takes: the grid's global list, then the lights of the bucket of the cell p stands in. |
zsl_arrival(i, p, n) | What light i puts on a point p facing n, unshadowed: diffuse, the irradiance over pi (times an albedo, the point's diffuse radiance from that light); toward and distance, the way to the light's position (a rect's centre; a distant light's distance is negative); lit, false where the light puts nothing on p. |
zsl_shadow_ray(i, p, xi) | A shadow ray from p toward light i: its unit direction in xyz and its length in w. A rect's ray goes to the point xi (0 to 1 on each axis) across its face, so rays drawn at points spread over the face and averaged read the share of the rect p sees; a point or spot light's goes to its position; a distant light's runs along the way its light arrives, with a negative length. |
zsl_reaches(light, object) | Whether a light's channel mask reaches a surface's; a mask of 0 sits on the default channel. |
zsl_punctual_falloff, zsl_area_falloff, zsl_rect_form_factor | The curves the arrival is made of. |