Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Screen artifact from Light sources with shadow map PCF filter enabled #2502

Open
BlackCurtainStudio opened this issue Oct 24, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@BlackCurtainStudio
Copy link

Release Type: Official Release

Version: 4.2.0.2232

Platform(s): Windows

Describe the bug
Point Light and Spot Light with shadow map PCF filter enabled produces a black screen artifact randomly.

To Reproduce
Steps to reproduce the behavior:

  1. Create new project
  2. Add a Point Light or Spot Light
  3. Enable shadows
  4. Enable PCF filter
  5. Move around camera and the artifact should eventually appear across the screen

Expected behavior
No screen artifacts should appear.

Screenshots
Image

@BlackCurtainStudio BlackCurtainStudio added the bug Something isn't working label Oct 24, 2024
@Basewq
Copy link
Contributor

Basewq commented Oct 25, 2024

I've reproduced this issue with a spotlight in the MyGame template - it even shows up in the editor.
After a lot of time inside RenderDoc, my conclusion is the following lines:

float4 shadowPosition = mul(float4(shadowPositionWS, 1.0), WorldToShadowCascadeUV[cascadeIndex + lightIndex * TCascadeCountBase]);
shadowPosition.z -= DepthBiases[lightIndex];
shadowPosition.xyz /= shadowPosition.w;

My understanding is that the first line transforms the pixel position (from world space) into "shadow map texture space".
This calculation occurs for every pixel on screen and basically every pixel that's nowhere near the spotlight/shadow should theoretically be "outside" the UV space of the shadow map. The problem is that there are some weird angles where this matrix calculation causes shadowPosition.w to be zero then the division by w causes xyz to be infinite and the subsequent shadow calculations produce garbage results (ie. NaN).

I think the solution might be to do an early exit check if the pixel isn't actually within the shadow map uv space?
Any graphics guru able to chime in?

I couldn't reproduce this issue with the point light, I think it needs a more precise setup to reproduce it, though I suspect it should have the same issue.

@tebjan
Copy link
Member

tebjan commented Oct 25, 2024

@Basewq thanks a lot for investigating. I've also traced this bug down to the shadow maps, but couldn't find the correct line.

I'll have a look at it!

This has been reported several times:
#325

@BlackCurtainStudio
Copy link
Author

BlackCurtainStudio commented Oct 25, 2024

I can confirm the issue is in the editor as well. Here's an example with a Point Light. However, the issue disappears when using Type DualParaboloid.
Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants