-
-
Notifications
You must be signed in to change notification settings - Fork 21.2k
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
Implement 3D shadows in the GL Compatibility renderer #77496
Conversation
In practice, we can't expect every mobile project to be using fully baked lightmaps (either for package size reasons or because levels are procedurally generated), so I think improving performance of rendering multiple real-time lights with shadows is key. Even if you use fully baked lightmaps, lights have to be manually hidden after baking so they don't take up rendering time, and this means dynamic objects won't receive direct light (dynamic capture currently doesn't have an option to store direct light). We also currently lack lightmap support in the Compatibility rendering method anyway.
Are there any alternative approaches that could be used, such as dithering? While Godot currently defaults to hard shadows on mobile, I feel like it should be possible to have something better on mobile in 2023. |
Directional Light doesn't work properly for me, I'm using your custom godot 4.1 dev build |
I've created testing projects to compare shadow rendering performance in 3.x and 4.x:
Here are the results on my machine (Linux, GeForce RTX 4090). All tests are done in 3840×2160:
This error message is frequently spammed in the editor:
Footnotes
|
This comment was marked as off-topic.
This comment was marked as off-topic.
Please open a separate issue with a minimal reproduction project attached. |
I can see why. That said, I would still try to, at least, do the directional light in a single pass merged with the non shadowed lights. Directional + non shadowed lights is the most common way to do lighting on mobile, so this as single pass is ideal. I know this would break if you have more than one directional light, but we could have a setting Also shadow filter is ok and expected to be non-pcf on mobile by default (only enable linear interpolation so it does hardware accelerated PCF4, which is per spec on GLES3). |
@Calinou I am surprised performance is not similar to Godot GLES2 to be honest. We really should aim for as closest as that if possible. |
I already have a plan. I will move the calculation of the additional lights to after the tonemapping step in the shader. That way, we can have the first light with shadows calculated in the original pass, but still in sRGB space. Should be enough to improve performance a little bit and ensure we get the best performance possible when using only a few lights. |
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.
My bad had missed some in my first pass
582692c
to
fa026d3
Compare
fa026d3
to
cb7200b
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.
Absolutely outstanding work!!
I still wonder why the GLES2 version of Godot 3 is faster, what do we do different there? |
@reduz maybe it's faster because we don't do any of the HDR lighting calculations? All lighting is kept LDR while here we do some conversions to/from HDR while we write out LDR? |
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'll find some time to properly test this in VR as soon as I can but as far as I can tell this looks sublime! Amazing stuff Clay!
Those measurements were taken with the old version of this PR. Back then we did an additional pass per light with shadows. Now the base pass includes one shadowed light so it is much faster |
I've run benchmarks again on the latest revision of this PR (rebased against
Directional shadow rendering still appears broken in the running project, even though it works in the editor: In comparison, this is how the scene looks like in Forward+ (disregard the FPS count here, I resized my window quickly): Visual comparison in the editor:
|
Woohoo! Thanks! |
Just noting a comment from the top post:
I'll investigate that outstanding bug and any new reports ASAP |
Fixes: #66596
Implementation of 3D shadows for the Compatibility renderer
Implementation based on godotengine/godot-proposals#3959
Main approach
Particularly this uses a multipass approach to lighting so that we can benefit from prefetch when using hard shadows. In practice this means:
Comments
There is still one outstanding bug where shadow atlas textures are getting out of date with multiple shadowed lights in the scene.
Pictures:
Linear vs sRGB blending
Lighting in linear space (no shadows)
Lighting in sRGB space
Lighting in sRGB space with reduced brightness and attenuation
Compatibility vs Forward+
Compatibility
Forward+