Skip to content

Use native depth clip control instead of manual DEPTH_CLAMP_ORTHO where possible #16078

@JMS55

Description

@JMS55

What problem does this solve or what need does it fill?

The DEPTH_CLAMP_ORTHO stuff we have for directional light shadow mapping uses a fragment shader. Having the fragment shader disables some really important hardware optimizations that exist for depth-only vertex-only passes.

What solution would you like?

For non-alpha masked draws, on supported platforms, use https://docs.rs/wgpu/latest/wgpu/struct.PrimitiveState.html#structfield.unclipped_depth instead of setting the DEPTH_CLAMP_ORTHO shader def.

Additionally when we do use DEPTH_CLAMP_ORTHO, we should not pass the entire clip_position_unclamped: vec4<f32> from the vertex shader to the fragment shader, we only need to pass the z value.

What alternative(s) have you considered?

We could remove DEPTH_CLAMP_ORTHO entirely, and instead expand the shadow view frustum either by some fixed amount, or based on the AABB's of entities in the scene.

Additional context

#8877
https://therealmjp.github.io/posts/shadow-maps/#disabling-z-clipping

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-RenderingDrawing game state to the screenC-FeatureA new feature, making something new possibleC-PerformanceA change motivated by improving speed, memory usage or compile timesD-ShadersThis code uses GPU shader languagesD-StraightforwardSimple bug fixes and API improvements, docs, test and examplesS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions