Builtin Library
- ..
- README.md1.5 KB
- module.wgsl2.4 KB
README.md
light_falloff
How much of a light's emitted power reaches a point at a distance from it. The surfaces' light loop, the deferred lighting pass, the lightmap and probe bakes, the path tracer and every compute pass that weighs, shadows or scatters a point, spot or rect light take the distance term from here, so a light falls off the same way in realtime, in a bake and in the reference image.
Distances are in metres. A point or spot light's intensity is the light it
puts on a surface facing it one metre away; at d metres that surface takes
intensity / d^2. A light of intensity 4 lights a white surface 1 m below it
with 4, one 2 m below it with 1, and one 0.5 m below it with 16.
The module is engine-owned (zero::light_falloff): engine_bindings includes
it, so every program composes the engine's own copy. It binds nothing, so a
compute pass includes it on its own:
#include "@builtin::shaderModules.light_falloff"
let to_light = light_pos - p;
let dist = length(to_light);
let arriving = light_color * light_intensity * zero_punctual_falloff(dist, light_range);
zero_punctual_falloff(dist, radius): the inverse-square law, windowed to zero at the light's reachradiusby(1 - (dist / radius)^4)^2. WithinZERO_PUNCTUAL_SOURCE_RADIUS(1 cm) of the light it holds its value there.zero_area_falloff(dist, radius): the same window alone, for a rect light, whose solid angle carries its own falloff.