vol_scatter.computeShader
- README.md3.6 KB
- bindings.yaml1.5 KB
- shader.wgsl13.8 KB
This package holds more than this page lists. See all of its files in its world.
README.md
vol_scatter
Marches each view ray through the medium, accumulating the light the scene's
sun (@frame.light), its parallel lights and the medium's surroundings scatter
toward the camera, and the transmittance left behind it. The lights standing
somewhere are vol_lights'.
The surroundings light the medium as they light a surface standing in it: the
scene's ambient term, the sky and reflection probes the environment captured
and the baked light-probe volumes, averaged over every direction
(zpbr_surroundings_in_scatter, the light media_view lights a
ParticipatingMedium by). The ray is cut into four stretches, and each reads
them once, at the distance where the medium it holds stands (its samples'
distances, without the per-pixel jitter, weighted by what each holds), and
applies them to its samples' weight. Two neighbouring rays so read their
surroundings at neighbouring points, and the light changes along a ray as
smoothly as the air it crosses. The sky reaches each point as far as the point
sees it, past the static geometry (the sky-visibility field) and past every
surface standing over it (zero_overhead_openness over overhead_map, the
overhead cover map the feature draws), so the air under a canopy or a roof takes
the share of the sky it sees. The medium's skyLight (vol_params[5].x) scales
what it takes. Haze in front of the sky so stands in for the sky it hides, by
day and by night, and with the sun, every light, the ambient term and the sky
dark the medium scatters nothing.
The sun and a parallel light arrive the same at every sample of a ray, so the
march sums each sample's weight (how much medium it holds and how much of the
way back is still clear) and applies the lights to the sums once per ray. The
sun's share is gated by a short march back toward it against the depth buffer,
which carves shafts where an occluder blocks it, and scaled by the share of
the sun the cloud layer lets through at the sample (cloud_shadow), so the
air under a cloud is dark and a gap between clouds lets a shaft through; its samples are a straight
line through the projection, so each one's clip-space position is the previous
one's plus a step, with no matrix product per sample.
Consecutive renders of a view share each ray's samples: a render marches every other sample and lays its half beside the half the previous render marched, taken from the texel where the end of the ray stood in that render. A ray with no previous render (a view's first, its first after a cut, a one-shot capture), one the previous render saw end at another distance, and one that falls off the previous picture march every sample themselves.
Includes
scattering_common@builtin::shaderModules.frame_light@builtin::shaderModules.ambient_light
Bindings
| name | kind |
|---|---|
scene_depth | texture_depth |
frame_cam | buffer (@frame.camera: its inverse view-projection, position, previous view-projection and view-projection) |
lights | buffer (@scene.lights) |
vol_params | buffer |
scene_light | buffer (@frame.light) |
environment_map | textureCubeArray (@scene.environment) |
environment_sampler | sampler (@scene.environmentSampler) |
zero_environment | buffer (@scene.reflectionProbes) |
scatter_prev | texture2d (the previous render's half) |
length_prev | texture2d (how long each of the previous render's rays was) |
scatter_state | buffer (the history target's state) |
history_out | storage2d (rgba16f) |
length_out | storage2d (r32f) |
scatter_out | storage2d (rgba16f) |