volumetrics.package
- ..
- README.md6.3 KB
- bindings.yaml3.3 KB
- shader.wgsl27.8 KB
This package holds more than this page lists. See all of its files in its world.
README.md
cloud_raymarch
The cloud layer's raymarcher: the one shader that draws a VolumetricSky.
The layer is a shell around the planet between two altitudes (cloud_shell),
so it reaches the horizon in every direction. Its clouds are formed where they
stand in the world: a weather map (cloud_weather) states coverage, cloud
type and density over each place; the cloud type sets the height profile
(stratus sheet, cumulus heap, cumulonimbus tower); and two tiling 3D noise
textures (cloud_noise) placed in world units form the clouds, the shape's
Perlin-Worley body thresholded by the coverage and the detail eroding its edge
into billows. The wind moves the noise through the world, so drift costs
nothing beyond the march.
Each ray is marched from where it enters the layer with steps that grow with distance: three at a time across empty air, and a third of one inside a cloud, entered by taking back the step that found it, so a distant cloud's edge is placed at the fine step rather than in bands at the coarse one. Each ray starts a share of a step in, the share uncorrelated between neighbouring cells and moving through a golden-ratio sequence from one render of a view to the next (the count of renders the view's accumulation has carried), so the temporal pass averages the grain a single render leaves. A ray ends where it leaves the layer, at the scene's surface, or at the march's reach (where the layer thins into the horizon's haze), and is lit by the sun through the cloud toward it (a cone of samples, Hillaire's multiple-scattering octaves, a two-lobe Henyey-Greenstein phase, powder on the shaded side) and by the sky, darker at a cloud's base than at its top.
The light is cloud_light's. With the scene's physical atmosphere the sun
reaches each sample through the air (white at noon, gold and red low, gone
once the planet hides it), the sky around the clouds is the atmosphere's own,
and every ray carries its cloud through the air to the camera at the cloud's
mean depth, over the sky and in front of a surface alike, so distant clouds
fade into the horizon's haze and a cloud in front of a far surface takes the
air of its own distance. Without
one the clouds take the scene's sun and the preset's sky.
Each sample's light becomes the colour it adds through the light response
(medium_light), and the density the march takes through medium_shape:
medium_physical, the light above, unless the sky names a response of its own
(lightResponse), which the layer draws with a program in which that
response's module stands in medium_physical's place
(@builtin::systems.volumetrics.mediumResponse). The response is handed the
sky's lightResponseParams at U[64..80).
It writes scene-linear light premultiplied by coverage, with coverage in alpha; the display stage tone-maps it with the rest of the frame.
Each cell records what its march was made from in the reuse record, a history
target with one pair of images per view: where its ray ended (the depth of the
surface along it, where that surface stands beyond where the ray enters the
layer), how many renders in a row it was marched from the same inputs, and the
reuse key (U[30], which moves with everything else the march reads). A cell
whose view's camera stood still, whose ray ended where it ended and whose key
held over U[31] renders marches nothing and keeps what it made; cloud_taa
carries its accumulation as it stood. A kept cell's record holds the end its
last march was made from and how far, in cells, the layer it shows has moved
across the view since (the record's a is 1 plus that distance, in steps of
1/1024 of a cell rounded up with the chance the remainder states), so a surface
or a camera creeping by less than a render's check sees brings the march back
once the creep reaches a part in 500 of the end or a quarter of a cell, however
little it moves in each render. The distance is where this render's
view-projection with no sub-pixel offset (@frame.camera [14..18)) places
the layer's point against where the previous render's ([5..9)) placed it,
taken as the change between the two matrices, so a camera that has not moved
adds exactly nothing, render after render, and a camera that moves by any
amount adds that amount.
The scene's depth is drawn through the projection's sub-pixel offset, so a cell
on a surface's silhouette reads the surface under some offsets and what stands
behind it (the sky, or a farther surface) under the others, and a cell on a
surface seen at a slant reads a nearer or farther point of it under each. Each
view walks the offsets in a fixed order (U[32] of them,
renderer.projectionJitter()), so while nothing moves every offset ends a
cell's ray where it ended it one walk back. The record holds two ends, each
with the offset it is checked at (the first in the record, the second in the
record's second-end target beside it), and its g holds which of the two each
render of the last walk ended at: a cell's ray has to end at the end the render
one walk back ended at, of the same kind (over the sky, before the layer, or on
a surface in it), within a part in 500 at the offset that end is checked at and
within the step the march takes through a cloud there at every other. A
settled sky behind a still surface keeps its silhouette's cells under the
jitter, whether the silhouette stands against the sky or against a farther
surface, and a surface that moves by any part of a pixel turns some offset to
another end and marches the cells it turned. A walk longer than eight offsets
is checked against the render before.
Bindings (see bindings.yaml): shape, detail, weather (texture3d),
noise_smp (repeating sampler), out_tex (storage2d rgba16f), U (the layout
is stated at the top of shader.wgsl), frame_cam (@frame.camera),
scene_depth (@scene.depth), scene_light (@frame.light), and the
physical atmosphere's atmo_params, transmittance_lut, multiscatter_lut
and skyview_lut (atmosphere.liveTables(), or stand-ins while no
atmosphere runs), hist_state (the layer's history target's state), and the
reuse record: reuse_out (storage2d rgba16f), reuse_prev and reuse_state,
and its second end: reuse_end2_out (storage2d rgba16f), reuse_end2_prev and
reuse_end2_state.