godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.15k stars 21.19k forks source link

Vulkan: DirectionalLight3D Angular Distance breaks shadows with long distance or complex shadow casters #63610

Open atirut-w opened 2 years ago

atirut-w commented 2 years ago

Godot version

v4.0.alpha12.official [2c11e6d9e]

System information

Fedora Linux 36 (Workstation Edition), Vulkan Clustered, GTX 1660

Issue description

When soft shadows are being cast by objects that are thin and have lots of distance, they seem to break.

Tested with House and Rungholt mesh from McGuire CG Archive.

https://user-images.githubusercontent.com/25323231/181693286-1eadffa1-d775-455c-a86a-885315d7a620.mp4

Also with a simple stretched cube

https://user-images.githubusercontent.com/25323231/181693586-45b2e42e-d69d-42f1-ba2e-0e8057400122.mp4

Steps to reproduce

  1. Shadow caster must have sufficiently thin shadows and far away from where the shadow lands
  2. DirectionalLight angular distance > 0

Minimal reproduction project

No response

BraqueDown commented 2 years ago

Related/Duplicate: #60391

atirut-w commented 2 years ago

This seems related indeed, but might not be a duplicate. The models I used from the archive are heavily tessellated.

Screenshot from 2022-07-29 14-34-57 Screenshot from 2022-07-29 14-33-41

BraqueDown commented 2 years ago

I just downloaded the scene myself, and yes that boat is very well tessellated. Definitely related though.

Either way this issue can be reigned in by increasing Pancake Size: image image

BraqueDown commented 2 years ago

Playing with the Pancake Size slider has interesting results. Increasing it causes the penumbra to apparently turn itself inside out:

https://user-images.githubusercontent.com/43602802/181711707-d4c66693-af6a-4668-bf16-147c9d166a07.mp4

Jamsers commented 1 year ago

Here's another repro project that you can use to see this in action: Bistro-Demo-Tweaked/PCSS-test

I've found lower camera FOVs exacerbate the issue.

Screenshot (16)

Turning up Pancake Size by even just a little bit helps the issue immensely, so the "fix" may be as simple as setting the pancake size higher by default, and adding some documentation recommending to increase pancake size the lower the FOV of your game camera is. I've found Pancake Size 30 matches well with FOV 75, for example. 🤔

atirut-w commented 1 year ago

Not sure if this is the right place to put my thoughts in, but I think this should be higher priority considering how this bug will affect scenes with huge shadow casters. This could become a problem in open world games.

viksl commented 1 year ago

I tested the Bistro scene above and this issue is not related to only large objects, small objects have the same issue.

Also for some reason 0 valu to the angular distance has a significant influence on shadow bias (although for some reason at this point pretty much any shadow setting has a significant negative impact on the shadow bias, was this intended or are some steps applied in some strange order perhaps?).

Here are two images with default settings:

1/ Angular distance = 0 angular_distance_0

2/ Angular distance = 0.01 (the lowest value possible in the editor) angular_distance_001

I'm not sure if this is related to this issue or not so I'm mentioning it as extra.

briansemrau commented 1 year ago

Angular distance > 0 also causes increasingly blurred shadows as the camera moves further from the origin where abs(dot(light_direction, camera_pos)) > 0. I see shadows steadily transition from crisp to incredibly blurry over a distance of several thousand units.

atirut-w commented 9 months ago

Could detecting if the penumbra is "inside out" help fix this issue? I feel like that's the right direction since the issue seems to stem from the shadow being so far away from the caster that it intersects with itself from the other side:

image