Skip to content

Improvement/shadowmap - #217

Closed
xDanielBellido wants to merge 13 commits into
mainfrom
improvement/Shadowmap
Closed

Improvement/shadowmap#217
xDanielBellido wants to merge 13 commits into
mainfrom
improvement/Shadowmap

Conversation

@xDanielBellido

Copy link
Copy Markdown

Directional shadow mapping improvement by adding Depth Buffer Fitting and Cascaded Shadow Maps (CSM).

Depth Buffer Fitting now uses the camera depth buffer on the GPU to calculate a tighter directional-light frustum, reducing wasted shadow-map space and avoiding GPU-to-CPU readback.

CSM divides the depth-fitted camera range into configurable cascades, generates a light projection for each one, and renders them into a Texture2DArray.

Debug tools can be found on the LightComponent, within the shadow settings. The Editor View shows the different cascades ranges of the Game Camera. The Game view shows the tint of each cascade.

11 CSM_Debug

The result is better shadow-map resolution usage and reduced aliasing, especially for geometry close to the camera.

Comparison

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.
@xDanielBellido

Copy link
Copy Markdown
Author

I close this PR because it's included in the Volumetric Fog System #221

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