Skip to content

Volumetric Fog System - #221

Open
xDanielBellido wants to merge 23 commits into
mainfrom
feature/VolumetricFog
Open

Volumetric Fog System#221
xDanielBellido wants to merge 23 commits into
mainfrom
feature/VolumetricFog

Conversation

@xDanielBellido

@xDanielBellido xDanielBellido commented Aug 21, 2026

Copy link
Copy Markdown

Volumetric Fog System

This PR adds a new Volumetric Fog system based on the main architecture described by Bart Wronski at SIGGRAPH 2014.

The effect uses a camera-frustum-aligned froxel grid represented by three Texture3D resources.

Volumetric Fog frustum space

The implementation is divided into two main passes:

  • Volumetric Fog Compute
  • Volumetric Fog Apply

Volumetric Fog Compute

VolumetricFogComputePass calculates the fog in three steps using three compute shaders.

1. Medium Generation

The first compute shader generates the participating-medium properties for each froxel, including:

  • Scattering
  • Extinction
  • Optional animated density using noise and wind

2. Volumetric Lighting

The second compute shader calculates how the directional light affects the medium.

Lighting is evaluated using the Henyey-Greenstein phase function, while the existing Cascaded Shadow Maps are sampled to introduce volumetric shadowing.

3. Volumetric Integration

The final compute shader integrates the medium and lighting information along the camera depth.

It applies Beer-Lambert extinction while accumulating scattering and transmittance through the froxel volume.

The result is stored in VolumetricFog_Integrated, which is later used to composite the fog into the scene.

Volumetric Fog 3D textures and compute stages


Volumetric Fog Apply

VolumetricFogApplyPass uses a fullscreen pixel shader to apply the computed volumetric fog to the final scene.

For each screen pixel, the shader reads the scene depth to determine how far into VolumetricFog_Integrated it should sample.

It then retrieves the accumulated fog color and transmittance from the 3D texture and combines them with SCENE_HDR.

In simple terms:

The compute stage prepares the volumetric fog data, while the final pixel shader uses that data to composite the fog into the rendered scene.

APPLY

Current Render Pipeline

renderpipeline

Scene Configuration

Volumetric Fog is controlled globally from the Scene Configuration panel, allowing designers to tune the effect without changing code.

Volumetric Fog Scene Configuration

Main Settings

Enabled

Turns the Volumetric Fog system on or off.

Density

Controls how much fog is present in the scene.

Higher values make the fog thicker and more visible.

Scattering Coefficient

Controls how strongly the fog scatters incoming light toward the camera.

Higher values make illuminated fog and light shafts more noticeable.

Extinction Coefficient

Controls how quickly light is lost while travelling through the fog.

Higher values make distant objects fade more strongly behind the fog.

Anisotropy

Controls the direction in which light is scattered using the Henyey-Greenstein phase function.

  • 0 — Light is scattered equally in all directions.
  • Positive values — More light is scattered forward, in the same general direction as the incoming light.
  • Negative values — More light is scattered backward, toward the light source.

Max Distance

Defines how far from the camera the volumetric fog is calculated.

A larger value allows the fog to cover a greater distance, while a smaller value concentrates the volumetric grid closer to the camera.


Optional Density Animation

Designers can optionally animate the fog density using procedural noise.

The available controls are:

  • Animate Density
  • Noise Scale
  • Noise Strength
  • Wind Direction
  • Wind Speed

The noise is evaluated in world space, which means the fog remains stable when the camera moves while the density field itself moves according to the configured wind direction and speed.

When density animation is disabled, the system returns to the original homogeneous fog behaviour.


Debug Views

The Scene Configuration also provides several visualization modes for inspecting the individual stages of the volumetric pipeline:

  • Final
  • Medium / Extinction Slice
  • Lighting Slice
  • Lighting Slice - No Shadows
  • Accumulated Scattering
  • Transmittance

The slice-based visualization modes also expose a Debug Slice value, allowing different depths of the froxel volume to be inspected.

These debug modes are intended to make it easier to isolate problems between medium generation, lighting, shadowing, and volumetric integration.


Result

https://www.youtube.com/watch?v=NFbbfVbdO9s

VolumetricFog-1ST_IT_RES3 - Copy - Copy

Reorder the render pipeline so the camera depth buffer is generated before shadow rendering. Run the GPU min/max depth reduction and shadow frustum compute passes per viewport, then use the generated shadow data in both the shadow map and deferred lighting passes.
Remove the legacy bounds-based shadow fitting path and use the GPU-generated shadow data buffer as the sole source for directional shadow matrices and settings. Simplify shadow frame data, remove frame-global shadow reuse, and keep a safe disabled-shadow fallback when depth fitting is unavailable.
Extend Texture depth-stencil handling to create, access, and release individual DSVs for texture array slices while preserving existing 2D depth texture behaviour
Add configurable cascade count, split intervals, and Fit to Scene/Fit to Cascade modes to directional shadow settings, including editor controls, validation, and serialization.
Extend GPU shadow frustum fitting to partition the depth-fitted camera range and generate light view-projection matrices for each configured cascade while preserving the existing single-frustum shadow path
Add a cascaded depth texture array and render each configured directional shadow cascade into its own array slice while preserving the legacy shadow map for validation
Update deferred lighting to select the appropriate shadow cascade per fragment and sample the corresponding Texture2DArray slice while preserving shadow bias, strength, and PCF filtering
Add an optional per-cascade colour tint to visualise cascade selection during deferred lighting, using the existing shadow data layout.
Add debug visualization for the depth-fitted camera frustum and individual CSM cascade sub-frustum. Tint colour only visible in Game View.
Add serializable VolumetricFogSettings to Scene, preserve them through play-mode snapshots, and expose them in Scene Configuration.
Add Texture3D UAV support and create the volumetric fog medium, lighting, and integrated 3D resources.
Add the frustum-aligned volumetric grid definition with exponential depth distribution and per-view grid constants for volumetric fog.
Add a compute pass that writes global scattering and extinction coefficients into the volumetric medium Texture3D
Add per-froxel directional in-scattering using Henyey-Greenstein phase evaluation over the volumetric medium
Sample the existing cascaded shadow map from volumetric compute lighting and make the CSM readable from both compute and pixel shaders
Accumulate volumetric in-scattering and Beer-Lambert transmittance along froxel depth using a 2D compute pass
Composite accumulated volumetric scattering and transmittance into the HDR scene using full-resolution depth
Add debug visualization modes for volumetric medium, lighting, shadow contribution, accumulated scattering, and transmittance
Add optional world-space Perlin density animation with configurable noise and wind controls for volumetric fog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant