Log inGet started
Package

height_fog.computeShader

Newest version

This package holds more than this page lists. See all of its files in its world.

README.md

height_fog

Fogs the scene by depth and by height, so the air thickens toward the ground and toward the horizon at once.

Each pixel's view ray is integrated analytically through the exponential height profile density * exp(-heightFalloff * (y - heightRef)), from the point start along the ray to the surface (or, for the sky, to the end of the medium). What is behind is dimmed by exp(-tau) of that optical depth, and the medium adds the light it scatters toward the camera times 1 - exp(-tau): the scene's sun (@frame.light) through a Henyey-Greenstein phase function and the cloud layer's shadow, and the light of the surroundings at the camera (fog_light, written by height_fog_light), both scaled per channel by the fog's colour. With every light dark the fog adds nothing.

The cloud layer's shadow (cloud_shadow) is read at four points along the ray, each the middle of an equal share of the light the fog scatters toward the camera (the optical depth inverted along the ray), and their mean scales the sun's share: fog under a cloud takes less of the sun, and the sun reaches the fog through the gaps between clouds. With no cloud layer casting a shadow the mean is 1 and no point is read.

heightfog_pass names which pixels a dispatch fogs: [0].x 1 fogs the sky the opaque scene left (a pixel at the far end of @scene.depth) and passes every surface through, 0 fogs the surfaces the frame's depth holds and passes the sky through. The feature runs the sky dispatch ahead of the transparent phase and the surface dispatch after it.

Includes

  • @builtin::shaderModules.surface_flags
  • @builtin::shaderModules.frame_light
  • @builtin::systems.volumetrics.shaders.cloud_shadow

Bindings

namekind
scene_colortexture2d
scene_depthtexture_depth
scene_normaltexture2d
frame_cambuffer, read vec4<f32>
scene_lightbuffer, read vec4<f32>
fog_lighttexture2d
heightfog_paramsbuffer, read vec4<f32>
heightfog_passbuffer, read vec4<f32>
cloud_shadow_maptexture2d
cloud_shadow_smpsampler
cloud_shadowbuffer, read vec4<f32>
fog_outstorage2d (rgba16f)