Log inGet started
Package

cloud_raymarch.computeShader

Newest version

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 frame to frame, 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 a ray over the sky carries its cloud through the air to the camera at the cloud's mean depth, so distant clouds fade into the horizon's haze. Without one the clouds take the scene's sun and the preset's sky.

It writes scene-linear light premultiplied by coverage, with coverage in alpha; the display stage tone-maps it with the rest of the frame.

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).