Skip to content
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

Allow culling objects from individual shadow splits in DirectionalLight3D shadow rendering #3358

Closed
mrjustaguy opened this issue Sep 27, 2021 · 3 comments

Comments

@mrjustaguy
Copy link

mrjustaguy commented Sep 27, 2021

Describe the project you are working on

Open Environments lit by the Sun, With lots of High Poly Characters up close.

Describe the problem or limitation you are having in your project

Distant splits are rendering the High Poly Characters, which sees performance tank significantly when going from 2 splits to 4 splits, as each split is re-processing the geometry, but most of it isn't relevant to the 3rd and 4th split.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Add An option to allow picking which splits Mesh instances do(n't) appear in, on a per MeshInstance3D basis.

This would have to be a per Mesh setting, and probably couldn't be automated in any way, as it's difficult to tell if something that is in say split 1, is also relevant in split 4 for casting shadows or not, and can probably only be done by artists on a case by case basis

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Under Visibility add a Directional Shadow Visibility setting, that by default has all 4 splits turned on (visible)

This is wrong, after further consideration, I've found a hole in there, if the caster is casting to your direction, but is too far and gets culled by close splits, won't be in close splits, resulting in an unexpected cut off, much like the issue is with taking things out of distant splits
Also, a potential addition to this, that would be a fairly safe optimization (this one might already be present, but in case it isn't) would be to automatically not pass geometry which is outside of the scope of a given split (so the closest point of the Bounding Box is farther then the split's distance)
Example of what I mean with this:
(These are the default settings when DL is created)
split 1 "far" is 10m
split 2 "far" is 20m
split 3 "far" is 50m
split 4 "far" is 100m
If all of the 8 vertices of the Mesh AABB are all over 10m away from the Camera, Split 1 ignores the geometry of that Mesh
If all of the 8 vertices of the Mesh AABB are all over 20m away from the Camera, Split 2 ignores the geometry of that Mesh
and so on..

If this enhancement will not be used often, can it be worked around with a few lines of script?

No, as the Geometry is passed to all 4 splits regardless of everything, and according to the Performance information, each triangle is processed 4 times (1 for each split, so 2 splits halves the processed triangle count)

Is there a reason why this should be core and not an add-on in the asset library?

Directional Shadow Rendering is core.

@Calinou
Copy link
Member

Calinou commented Sep 27, 2021

This is a good idea to let users cull smaller objects from distant directional shadow rendering, but I wonder if it could be done automatically somehow (e.g. based on the mesh's AABB size). Most people won't bother tweaking the cull layers manually, as it requires a fair bit of trial and error to get it right without losing too much quality.

Also, a potential addition to this, that would be a fairly safe optimization (this one might already be present, but in case it isn't) would be to automatically not pass geometry which is outside of the scope of a given split (so the closest point of the Bounding Box is farther then the split's distance)

Are you sure this isn't already done by the rendering code? I'd check using RenderDoc to make sure.

@Calinou Calinou changed the title Directional Shadows Optimization Allow culling objects from individual shadow splits in DirectionalLight3D shadow rendering Sep 27, 2021
@Calinou Calinou added this to the 4.x milestone Sep 27, 2021
@mrjustaguy
Copy link
Author

mrjustaguy commented Sep 27, 2021

I've been thinking about this issue, a bit, and I came up with several ideas, but all would have flaws that would incorrectly in some cases drop out shadows in distant splits where they were actually affecting something, so for removing things from distant splits, it seems like artist needs to do this.. The reverse however, removing things from close up splits is easy..

I'm 70% sure that the safe optimization isn't present, as in my test setup, characters appear in all 4 splits even if only 2 of the splits are within the distance, but I am getting a speed up so not sure what is going on... maybe something else is going on which is giving the speed up (LODs are off), and this could add an extra speed up if that is the case.

But yea, if someone does come up with an idea for how to remove objects from distant splits automatically safely, Please share your idea here.

The issue that I've faced with my ideas for that are the fact that you can have an object whose AABB is inside split 1 and only inside split 1 distance, that sends shadows all the way to the end affecting all 4 splits.. Example of such a scenario - Large Plane with a cube, the directional light only a few degrees above the plane, the camera positioned such that the cube is entirely within split 1 - resulting shadow will be in all 4 splits.

@mrjustaguy
Copy link
Author

Most people won't bother tweaking the cull layers manually, as it requires a fair bit of trial and error to get it right without losing too much quality.

As there doesn't seem to be a safe way to automatically determine what to cull, and what not to cull, both in close up splits and distant splits, and that this would be very demanding on the artist to do, it'd be very difficult to get right and the slight performance bump wouldn't be worth it and it's risks of graphically glitching shadows... So I'm closing this proposal.

I don't know, maybe it's possible to pass the geometry just once per Directional Light, instead of once per Directional Light Split, but I kind of doubt it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants