bevy/crates/bevy_pbr/src/render
Daniel Chia 0a881ab37f
Cascaded shadow maps: Fix prepass ortho depth clamping (#8877)
# Objective

- Fixes #8645

## Solution

Cascaded shadow maps use a technique commonly called shadow pancaking to
enhance shadow map resolution by restricting the orthographic projection
used in creating the shadow maps to the frustum slice for the cascade.
The implication of this restriction is that shadow casters can be closer
than the near plane of the projection volume.

Prior to this PR, we address clamp the depth of the prepass vertex
output to ensure that these shadow casters do not get clipped, resulting
in shadow loss. However, a flaw / bug of the prior approach is that the
depth that gets written to the shadow map isn't quite correct - the
depth was previously derived by interpolated the clamped clip position,
resulting in depths that are further than they should be. This creates
artifacts that are particularly noticeable when a very 'long' object
intersects the near plane close to perpendicularly.

The fix in this PR is to propagate the unclamped depth to the prepass
fragment shader and use that depth value directly.

A complementary solution would be to use
[DEPTH_CLIP_CONTROL](https://docs.rs/wgpu/latest/wgpu/struct.Features.html#associatedconstant.DEPTH_CLIP_CONTROL)
to request `unclipped_depth`. However due to the relatively low support
of the feature on Vulkan (I believe it's ~38%), I went with this
solution for now to get the broadest fix out first.

---

## Changelog

- Fixed: Shadows from directional lights were sometimes incorrectly
omitted when the shadow caster was partially out of view.

---------

Co-authored-by: Carter Anderson <mcanders1@gmail.com>
2023-06-21 22:00:19 +00:00
..
clustered_forward.wgsl Wgpu 0.15 (#7356) 2023-01-29 20:27:30 +00:00
fog.rs Allow tuples and single plugins in add_plugins, deprecate add_plugin (#8097) 2023-06-21 20:51:03 +00:00
fog.wgsl Apply codebase changes in preparation for StandardMaterial transmission (#8704) 2023-05-30 14:21:53 +00:00
light.rs update bitflags to 2.3 (#8728) 2023-06-01 08:41:42 +00:00
mesh_bindings.wgsl update wgpu to 0.13 (#5168) 2022-07-14 21:17:16 +00:00
mesh_functions.wgsl bevy_pbr: Fix tangent and normal normalization (#5666) 2022-08-18 21:54:40 +00:00
mesh_types.wgsl Temporal Antialiasing (TAA) (#7291) 2023-03-27 22:22:40 +00:00
mesh_vertex_output.wgsl update wgpu to 0.13 (#5168) 2022-07-14 21:17:16 +00:00
mesh_view_bindings.wgsl Screen Space Ambient Occlusion (SSAO) MVP (#7402) 2023-06-18 21:05:55 +00:00
mesh_view_types.wgsl EnvironmentMapLight support for WebGL2 (#7737) 2023-02-20 00:02:40 +00:00
mesh.rs Allow tuples and single plugins in add_plugins, deprecate add_plugin (#8097) 2023-06-21 20:51:03 +00:00
mesh.wgsl bevy_pbr: Fix incorrect and unnecessary normal-mapping code (#5766) 2022-11-03 20:37:32 +00:00
mod.rs Add Distance and Atmospheric Fog support (#6412) 2023-01-29 15:28:56 +00:00
parallax_mapping.wgsl Webgpu support (#8336) 2023-05-04 22:07:57 +00:00
pbr_ambient.wgsl Screen Space Ambient Occlusion (SSAO) MVP (#7402) 2023-06-18 21:05:55 +00:00
pbr_bindings.wgsl Add parallax mapping to bevy PBR (#5928) 2023-04-15 10:25:14 +00:00
pbr_functions.wgsl Screen Space Ambient Occlusion (SSAO) MVP (#7402) 2023-06-18 21:05:55 +00:00
pbr_lighting.wgsl EnvironmentMapLight, BRDF Improvements (#7051) 2023-02-09 16:46:32 +00:00
pbr_prepass.wgsl Cascaded shadow maps: Fix prepass ortho depth clamping (#8877) 2023-06-21 22:00:19 +00:00
pbr_types.wgsl Add parallax mapping to bevy PBR (#5928) 2023-04-15 10:25:14 +00:00
pbr.wgsl fix normal prepass (#8890) 2023-06-21 17:25:20 +00:00
shadows.wgsl Non-breaking change* from UK spellings to US (#8291) 2023-04-08 16:22:46 +00:00
skinning.wgsl bevy_pbr: Normalize skinned normals (#6543) 2022-11-11 03:31:57 +00:00
utils.wgsl Screen Space Ambient Occlusion (SSAO) MVP (#7402) 2023-06-18 21:05:55 +00:00
wireframe.wgsl update wgpu to 0.13 (#5168) 2022-07-14 21:17:16 +00:00