Log inGet started
Package

heightFog.renderFeature

Newest version

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

README.md

heightFog

The render pass behind the HeightFog component and the fog module. Fog over a scene comes from adding that component to an entity; this feature runs while its density is above 0.

Two compute programs, run as three dispatches:

  1. height_fog_light reads the light of the surroundings at the camera of the view being drawn (the scene's ambient term, the captured sky and reflection probes, the light-probe volumes, averaged over every direction) into one texel.
  2. height_fog reconstructs each pixel's world position from @scene.depth and the drawn camera's inverse view-projection (@frame.camera), integrates the height-falloff density along the view ray analytically from start to the surface, and composes surface * exp(-tau) + light * (1 - exp(-tau)). light is the fog's colour times the scene's sun (@frame.light, through a Henyey-Greenstein lobe) plus the surroundings' light from the first pass, so with every light dark the fog only dims what is behind it.

Working in world space is what lets density vary with altitude and what lets the medium respond to view direction — neither is expressible from screen depth alone.

height_fog runs twice per view. Once the opaque scene is lit (afterOpaqueLit, after the cloud layer's sky composite) it fogs the sky the opaque scene left: a sky pixel takes the fog of its whole view ray, the lit medium where the fog never thins and the column the ray climbs through where it does. What the transparent phase then draws over that sky (a world-space label, a glass pane, a particle) stands in front of it, as does a Volume composited over it. In the medium stage, after the transparent phase, it fogs every surface the frame's depth holds (the water a transparent draw wrote depth for included) up to its own distance, and leaves the sky as the first dispatch made it. height_fog_light runs ahead of both.

Parameters arrive through the heightfog_params buffer, which the feature packs from its settings.

Because the camera rides @frame.camera, the fog is correct in offscreen captures and render-to-texture cameras at their own resolutions, not only in the live viewport.

The passes declare environmentCapture = false: the sky fallback and the reflection probes the fog is lit by are captured without it, so each capture holds the light of the scene as it stands, and a reflecting surface is seen through the fog in front of it.