-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Make 2D shadows respect z_index
#93881
base: master
Are you sure you want to change the base?
Conversation
z_index
We took a look at this in today's rendering meeting and agreed that this seems like a useful new feature however:
|
Thank you for coming back to this PR! Regarding #64939, if I remember correctly there was no easy fix for it without rewriting a big part of the shader and rendering code. I recall that the As for the canvas layers, I don't actually think it would be that much of a performance difference since you usually have them on separate layers which would need a shadow map update anyway. Either way it should be a somewhat simple fix, probably by maintaining Anyway, I will fix this and the merge conflicts and hopefully get this PR into a somewhat mergeable state. Might take a few days, since I don't have much time at the moment, sorry. |
This PR adds the ability to sort 2D light occluders using their z_index. Helps with #64939. Now, light occluders only cast shadows on objects that have a lower or equal z_index. I had written another PR that did the same as this one a while ago (#86689), but I didn't really like the approach I took since it was on the GPU side. It also now works on directional lights and on both forward+ and mobile renderers.
Old shadows on the left, new ones on the right:
![LightComp](https://private-user-images.githubusercontent.com/47889291/345274970-5cf4f8e1-79f1-4ac0-a15a-6ae2c22d4503.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkxMzUzOTMsIm5iZiI6MTczOTEzNTA5MywicGF0aCI6Ii80Nzg4OTI5MS8zNDUyNzQ5NzAtNWNmNGY4ZTEtNzlmMS00YWMwLWExNWEtNmFlMmMyMmQ0NTAzLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA5VDIxMDQ1M1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTQ4ZjVjMDYwN2Y1MWMxYmQ1N2Q1MThhNjg3MWQzMGZhZTdjNjExMjE2MzNlNjUxYjU5MTcyYThkZmM1YWVjYTkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.0CpdUGcZD8t7ELN6FjdqEkCsoAo6s-OFfcmB1ish-nY)
This approach doesn't modify any shaders or low-level graphics code, and instead uses only the CPU. This is achieved by calculating the shadow map inside
RendererCanvasRenderRD
instead ofRendererViewport
. The shadow map gets recalculated if the lowest z_index of all active occluders is smaller than the current object's z_index, since the occluder then has to be removed from the shadow map.Performance-wise, in the best-case scenario where only one z_layer is used for all objects, the performance is the same since the shadow map is only calculated once. In the worst-case scenario, the shadow map gets calculated as many times as there are z_layers occupied by occluders. This shouldn't be a problem because usually you only need a few z_layers for occluders.
I hope that this PR can get merged since I feel like 2D shadows are currently unusable. This is still my first time contributing, so please let me know if I need to change or add anything!