-
-
Notifications
You must be signed in to change notification settings - Fork 21.9k
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
Add Soft Very Low shadow quality mode for 3D #53992
Add Soft Very Low shadow quality mode for 3D #53992
Conversation
What is the rationale behind offsetting the texture lookup by +-PI pixels? To me this just looks like a jittered single pixel lookup. Dithering is usually implemented with a threshold function where the pixel is set to 0 if under the threshold and 1 if over. |
To be fair, I copied the existing code and tried to adapt it the best I could. It looks a little strange with DirectionalLights (one axis seems more dithered than the other), but point lights look fine to me. There is probably a better way to do it, but I don't know how. |
The existing code uses a spiral-shaped kernel to offset the shadow texture lookups. Importantly, the length of the offset is determined by the kernel and the blur amount, not by Also, if you want to add a jitter to the single sample mode, it should be added as another enum to the shadow sample quality setting godot/servers/rendering_server.cpp Line 2798 in a4fbb67
Right now, the lowest setting is Hard (Fastest) If you want to continue with this PR, I suggest adding an enum named Soft Very Low (Fast) that also uses only 1 texture sample. You will also have to add a new quality selection here:godot/servers/rendering/renderer_rd/renderer_scene_render_rd.cpp Lines 2696 to 2701 in a4fbb67
I suggest changing hard shadows to 0 samples, and then in the shader check if 0 samples are used, then use the non-offset version of the code:godot/servers/rendering/renderer_rd/shaders/scene_forward_lights_inc.glsl Lines 330 to 332 in a4fbb67
e.g. change this to
This way, when only 1 sample is selected, then the proper offsetting code will automatically be used. Being honest though, I doubt the performance benefit of using a single texture lookup vs 4 will be worthwhile on any hardware. I think for low end hardware it would be best to use Hard shadows. |
Is that still required if #53961 is merged? That PR adds a global toggle to disable shadow dithering, which will make it possible to achieve hard shadows again. |
#53961 doesn't produce hard shadows, it just removes the per-pixel rotation of the vogel disk. I'm not really sure what the benefit of doing that would be. Note especially, that the calculations for rotating the vogel disk still take place, so there will be no performance benefit. I'm not sure that a global override to produce hard shadows makes sense. In other words, why would we take more than one sample when calculating hard shadows? |
Indeed, there is no benefit in doing so. I can look at adding a separate setting for hard + jittered shadows, but I'd prefer having #53961 settled first since I'm not sure how they'll interact together.
Several people requested a way to disable dithering while still using soft shadows, which is currently not possible in The issue I linked to isn't particularly a new concern. I remember seeing people wanting to disable dithering as soon as the new soft shadows were pushed to |
For clarity, there is no dithering involved in soft shadows. At any rate, #53961 doesn't eliminate noise either, it removes the per-pixel rotation which decreases the "grainy" noise, but it leaves the noise created by using vogel disk sampling. Further, in the issue you linked, the user was asking for a way to blur the shadows further to get a smooth gradient. In the example screenshots in #53961 the visual noise from the "disabled" version is much more jarring then having per-pixel rotations enabled. I'm not sure there is any value in disabling per-pixel rotations while leaving the vogel disk sampling intact. But if we do, we should do it in a way that does not substantially increase visual noise. Perhaps allowing PCF as an option would do the trick? |
25f67f6
to
016fcca
Compare
I agree your suggestion makes more sense in the end. I reworked this PR to add a Soft Very Low quality setting as requested. |
0da6381
to
06913c3
Compare
This can be used to improve 3D shadow rendering quality at little performance cost. Unlike the existing Hard setting which is limited to variable shadow blur only, it works with both fixed blur and variable blur.
06913c3
to
e87ec8e
Compare
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.
Looks great! Thanks for sticking to it and responding to feedback!
Thanks! |
This can be used to improve 3D shadow rendering quality at little performance cost. Unlike the existing Hard setting which is limited to variable shadow blur only, it works with both fixed blur and variable blur.
Preview
Hard
Soft Very Low (new)
Performs nearly as well as Hard with better quality. It's more grainy than Soft Low, so using lower blur values is recommended.
Soft Low
Editor comparison
Performance estimations are included in the top-right corner of every image.Edit: These estimations are inaccurate because the CPU time measurement is also taken into account. In practice, I can get a more significant performance boost with shadow quality set to Soft Very Low.
DirectionalLight3D (fixed blur)
DirectionalLight3D (variable blur)
SpotLight3D (fixed blur)
OmniLight3D (variable blur)