-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Improve PCSS #22272
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
base: main
Are you sure you want to change the base?
Improve PCSS #22272
Conversation
|
This is a draft because I'm not super convinced by this approach yet for the following reasons:
|
|
Using interleaved_gradient_noise based on screen UV instead of light local UV significantly improved the visual quality of the noise in the shadows. It is used for the random rotations of the sampling kernel. I think the size of the blocker search radius is supposed to be based on the tangent of the angle the light source covers. We actually have this information in our light uniform so I can try to plumb that through and make use of it so it's independent of shadow map resolution. The blur resolution calculation still looks wrong. But I also need to figure out why making it correct breaks things. :) After that, I think this should be ready to move out of draft and get more testing. And perhaps next up I'll try using a 'vogel disk' (a.k.a. golden spiral) sampling kernel pattern rather than the one from Jimenez 2014 (CoD:AW) or the DirectX MSAA pattern being used for blocker search. That should give good coverage of the sample kernel radius in an arbitrary number of samples (we could use lookups for say 4/8/16 samples but fall back to calculating the sample offsets on the fly for other values). |
|
I've split the screen uv part out into #22400 as it affects more than just PCSS and is less subjective. It's just a bug pretty much. |
This results in the PCSS soft shadows being harder close to the contact of the object with the receiving surface, and softer when there is more distance between them.
This removes some 'ghost' shadows that otherwise appear.
I've tried tweaking this to use the tangent of the light angle, but it doesn't seem to work better.
I've tried to correct the blur calculation, but it too seems to have issues I haven't been able to resolve yet.
I've tried vogel disk sampling a bit and it's not convincingly better yet. So I think a more thorough and separate investigation needs to be done. I'm marking this as ready for review. More tweaks can come later, but I think this is already much better. It needs testing on more scenes. |
Objective
Solution
mainsimplified down to thelight_size / cascade_diameter. The light size could be tweaked for this to look ok, but the softness of the shadows would be unintuitive for cascaded shadow maps given the interplay between the cascade configuration and the light size - if you change one you would have to tweak the other.128.0f / shadow_map_sizeequivalent to 128 texels, whereshadow_map_sizeis the texture dimensions of the cascade. At least for the shadow map size we use. Given all cascades use the same resolution, this is practically a constant:128.0 / 2048.0 = 0.0625in UV units. This means that each cascade will search smaller or larger regions for blockers depending on how close they are to the camera. It does feel like the blocker search. This came from this MIT-licensed code: https://github.com/PanosK92/SpartanEngine/blob/f0526aac0ed3197cc3ffb09d029f8b3bde8daf21/data/shaders/shadow_mapping.hlsl#L106Merged in Reduce aliasing and Moiré patterns in temporal shadow filtering #22400interleaved_gradient_noiseis supposed to use screen UV, not light local UV. Changing this removes aliasing and moirée in the noise and significantly improves directional/spot light soft shadow quality in both non-temporal and temporal modes.Testing
I've tested using the
pcssexample on an M4 Max.Showcase
Soft shadows off:

PCSS

main:PCSS on this PR:

Note how the shadow is harder at the base of the tree and softer around the leaves. I don't have a ground truth image of this scene to compare to, but this is at least more how it should be.