Volumetric Fog System - #221
Open
xDanielBellido wants to merge 23 commits into
Open
Conversation
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
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
The implementation is divided into two main passes:
Volumetric Fog Compute
VolumetricFogComputePasscalculates 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:
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 Apply
VolumetricFogApplyPassuses 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_Integratedit 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.
Current Render Pipeline
Scene Configuration
Volumetric Fog is controlled globally from the Scene Configuration panel, allowing designers to tune the effect without changing code.
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.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:
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:
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