-
-
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
Directional shadows broken for Distance Fade objects with Pixel Dither or Object Dither #39530
Comments
Not sure if there is a nice solution here. Pixel fadeout is based on a) screen space position of the pixel and b) the distance from the camera to the pixel. For computing the shadow buffer these values don't make sense. Shadows fade out based on the distance between the object and the light and shadow buffer pixels don't turn into singular screen space pixels. What I would do is turn shadows off on that cube and then have a proxy cube that is set to shadows only. |
The only thing I can think of off the top of my head is rendering the shadows as normal but have them all fade out (reading) according to distance in the camera view, at about the same distance as the distance fade for the objects. As clayjohn say, it is a difficult problem, and as with visibility determination, shadows need to be considered at the same time as building the system, as shadows can be equally as difficult / or even more difficult to deal with. |
What's weird, though, is this only happens if min and max distances are reversed. If max > min, then shadows work properly. But if min > max, these bugs happen. That's why I'm not sure if this is the intended way of getting them to fade out with far distance as opposed to near distance, since min > max doesn't intuitively make sense (might be a usability issue) |
Missed that bit. Yeah, it's fairly common that things won't work as expected when a min is larger than a maximum. Maybe there could be a warning, or preventing the values being set to this in the UI. 👍 Irrespective the point stands, fading shadow maps might not work as intended, both in terms of the distance from the light being different from the distance from camera, and the all or nothing nature of shadow maps, and the shadow map texels being potentially a lot larger than pixels on screen. |
I'v got the same issue with shader, that scales objects by distance. Has someone already found a solution to this problem? |
And I think the problem is here: If you use uniforms or TIME to scale or dither objects, then you will get normal shadow behavior. |
So, some more interesting information.
|
I'm not getting shadows when using a dithered fade with gles3. It seems to be related to this line: Removing Is there a better fix for this that doesn't require changing the code? Can I force a material for the depth pass? |
Cool. But the one question still: why when using matrices to get the position of the vertices and their scaling, the shadows also disappear? |
As a workaround, you can duplicate your mesh, use a separate opaque material for it and change its shadow rendering mode in the GeometryInstance section to Shadows Only. Then make your other dithered mesh not cast any shadows in the same GeometryInstance section. (You can reuse the same opaque material for all shadow-only meshes.) |
godotengine/godot-proposals#3276 and godotengine/godot-proposals#4443 should allow resolving this once either of these is implemented. |
I think I've found a satisfactory workaround for this issue after converting this effect to shader code. Establishing an upper boundary for This trick works for camera view distances up to a few hundred units, until
|
Another workaround is to use a shader global for the world camera position. Instead of using length(VERTEX) as the distance, use the distance between the world camera position global (not the built-in!) and the current vertex/pixel position in world space. This calculation can be done in the vertex shader to make it run faster. The world camera position global variable will have to be updated from some script every frame. (As far as I know shader globals were introduced in 4.0) |
Godot version:
3.2.1 stable
OS/device including version:
Windows 10 Build 1909, Nvidia RTX 2070 Super, Driver version 445.87, GLES3
Issue description:
An object with a material that has Distance Fade (with either Pixel Dither or Object Dither mode) with a far-clip fade out (e.g. Min 60, Max 20) casts odd shadows (or not at all).
For example....
Shadows disappear when a large object exists in a scene?
Banding/inconsistent opacity when moving camera
Shadow fading out before object does (Is it supposed to fade out at all?)
Point and spot shadows look fine. Near-clip distance fade directional shadows (e.g. Min 20, Max 60) work fine. It also seems to be dependent on camera angle... there's one angle at which none of the above bugs show up.
Steps to reproduce:
4.a Enable and disable the large floor. Notice shadows disappear when it's visible
4.b Pan or zoom camera and observe banding and fading issues
Minimal reproduction project:
distance-fade-shadows.zip
Am I doing something wrong by making the min and max reversed? Is fading out at a far distance not supported? Not sure if this was never supposed to work in the first place 🙂
The text was updated successfully, but these errors were encountered: