-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
[3.x] Add PCF25 shadow filtering option in the GLES3 renderer #54355
base: 3.x
Are you sure you want to change the base?
Conversation
Bit of a bodge, but as this is an enum rather than needing conditionals for each (i.e. you are either using 0, 5, 13 or 25) maybe you can get by with two conditional flags... 00 = 0 But yeah sounds like it could do with some looking at the conditional code to see if there's a better solution longterm. |
71cb8d3
to
c58391c
Compare
83c18d4
to
cc577b6
Compare
I applied @lawnjelly's solution to get the configuration option to work. I tested the PR on both GLES3 and GLES2, with and without asynchronous shader compilation. It works as expected in both renderers. Note that in GLES2, the PCF25 option is equivalent to the PCF13 option. It's possible to implement a higher quality shadow filter for GLES2, but it'd be very slow on the target hardware. |
cc577b6
to
85329ec
Compare
This is a high-quality shadow filter which results in smooth, stable shadows even for dynamic objects. Thanks to early bailing, PCF25 is faster than the old PCF13 implementation while looking better. It's also not that much slower compared to the new PCF13 implementation.
85329ec
to
13e679a
Compare
Rebased and tested again, it works as expected. I've changed the early bailing implementation to also take the center sample into account (also for the existing PCF13). This is a tad slower as it requires one more sample, but it leads to fewer artifacts, particularly with PCF25. This matches the implementation used in the 4.x Compatibility rendering method. |
#ifdef SHADOW_MODE_PCF_13 //ubershader-runtime | ||
float avg = textureProj(shadow, vec4(pos, depth, 1.0)); | ||
#ifdef SHADOW_MODE_PCF_LOW //ubershader-runtime | ||
#ifdef SHADOW_MODE_PCF_HIGH //ubershader-runtime |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do this? 🤔
#if defined(SHADOW_MODE_PCF_LOW) && defined(SHADOW_MODE_PCF_LOW)
This pattern seems to be used elsewhere in the shaders and it seems easier to follow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this messes with //ubershader-runtime
, unfortunately. We can use this approach in 4.x though where ubershaders aren't used in Compatibility.
I tried this out and it seems to work fine. Not really for this PR, but it strikes me at 25 samples, we should be making the PCF radius adjustable per light. With a uniform multiplier in Also I do wonder for PCF 25 whether a regular pattern gives the best results versus random (even fixed random pattern). Again maybe this should be adjustable in the future. Hopefully we can greatly improve shadows in 3.7. This is PCF25 with a 5x multiplier for |
There's an This feature also exists in 4.x already, but the Light3D Shadow Blur property only affects Forward+ and Mobile right now. I started working on a 4.x implementation for Compatibility, but didn't get it working yet: https://github.com/Calinou/godot/tree/compatibility-shadow-blur
#53967 can help further improve shadow filtering quality at the cost of visible noise, like in Forward+/Mobile in 4.x. |
Great! I'm keen for us to improve the shadows in 3.7, including e.g. fixed filter per light or PCSS or similar, and normal bias offset. We'll probably discuss these PRs in more detail over coming months and decide which approaches to go for. |
This is a high-quality shadow filter which results in smooth, stable shadows even for dynamic objects.
Thanks to early bailing, PCF25 is faster than the old PCF13 implementation while looking better. It's also not that much slower compared to the new PCF13 implementation.
Preview
PCF13 with 2048 shadow size (faster but less smooth)
shadow-filtering-pcf13-2048.mp4
PCF25 with 4096 shadow size (slower but smoother)
shadow-filtering-pcf25-4096.mp4