godotengine / godot

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

Shadows create artifacts in Godot 3.0 #12148

Closed kakoeimon closed 4 years ago

kakoeimon commented 6 years ago

Operating system or device, Godot version, GPU Model and driver (if graphics related): Manjaro 17.0.5 Godot 3.0 Master Build NVidia GT540M, driver 384.90

Issue description:

Small cubes from OmniLight shadow. screenshot_2017-10-16_15-04-11

Steps to reproduce: Just create an Omni Light above a "floor" and anable shadow.

Link to minimal example project:

shadows.zip

reduz commented 6 years ago

Did you adjust bias?

On Oct 16, 2017 9:07 AM, "kakoeimon" notifications@github.com wrote:

Operating system or device, Godot version, GPU Model and driver (if graphics related): Manjaro 17.0.5 Godot 3.0 Master Build NVidia GT540M, driver 384.90

Issue description:

Small cubes from OmniLight shadow. [image: screenshot_2017-10-16_15-04-11] https://user-images.githubusercontent.com/13662414/31611088-594a1564-b283-11e7-9bd6-c2d078bb2e68.png

Steps to reproduce: Just create an Omni Light above a "floor" and anable shadow.

Link to minimal example project:

shadows.zip https://github.com/godotengine/godot/files/1387324/shadows.zip

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/godotengine/godot/issues/12148, or mute the thread https://github.com/notifications/unsubscribe-auth/AF-Z2yhQ_Snj1y5jZqawYeZd5cyU7_Wjks5ss0bwgaJpZM4P6hKD .

kakoeimon commented 6 years ago

@reduz no.

volzhs commented 6 years ago

image

image

kakoeimon commented 6 years ago

@volzhs yes I know this, but in closed doors room you get the shadow to far from the wall.

volzhs commented 6 years ago

then you can use "Contact" for it. not sure...

kakoeimon commented 6 years ago

I post here the problem in a particular state where bias creates an obvious problem.

Bias 0.15 an acceptable small gap from object to shadows but artifacts in the flat area. screenshot_2017-10-17_10-14-05

Bias to 0.6 (requared in this case) no artifacts but big gap between the caster and the shadow gives to me the illusion that the caster is flying, I think @volzhs and @reduz will agree. screenshot_2017-10-17_10-15-20

And contact seems just unusable... Look at the shadows produced by it. screenshot_2017-10-17_10-16-41

@Noshyaar added the tag bug to this, but I think that this is not a bug. After some searching over the internet I believe that @reduz implemented this cube shadows rightly.

I have no idea how this can be adressed, but right now I can not find any acceptable shadows.

volzhs commented 6 years ago

contact value seems too small to cover bias. did you try 0.6 for contact?

edit : oh, there is some glitch on mouse pointer. i see.

kakoeimon commented 6 years ago

@volzhs Yes. This glitch is active even by putting the geometry to Cast Shadows off. This looks like a bug to the contact of Omni Light after all.

screenshot_2017-10-17_11-38-18

I turned the mesh geometry to Cast Shadows Off and Contact to 0.01 cause to show that the problem always exists.

mhilbrunner commented 6 years ago

First of all thank you for your report and sorry for the delay.

We released Godot 3.0 in January 2018 after 18 months of work, fixing many old issues either directly, or by obsoleting/replacing the features they were referring to.

We still have hundreds of issues whose relevance/reproducibility needs to be checked against the current stable version, and that's where you can help us. Could you check if the issue that you described initially is still relevant/reproducible in Godot 3.0 or any newer version, and comment about it here?

For bug reports, please also make sure that the issue contains detailed steps to reproduce the bug and, if possible, a zipped project that can be used to reproduce it right away. This greatly speeds up debugging and bugfixing tasks for our contributors.

Our Bugsquad will review this issue more in-depth in 15 days, and potentially close it if its relevance could not be confirmed.

Thanks in advance.

Note: This message is being copy-pasted to many "stale" issues (90+ days without activity). It might happen that it is not meaningful for this specific issue or appears oblivious of the issue's context, if so please comment to notify the Bugsquad about it.

mhilbrunner commented 6 years ago

Also, if it still happens, please see if the fixes mentioned in #16520 help.

DEF7 commented 6 years ago

I've managed to make shadows look great in both large and small/detailed scenes using directional and non-directional lights. As far as I can tell most people are having problems because they aren't experimenting to find what works. This is obviously the case when they show screenshots of ultra-simple scenes, because those are a piece of cake to get looking right. However, I will admit that there are better default settings that should be in place for those who are less inclined to make sense of the tool they're trying to use. The reality is that fine-tuning the shadows is a game of musical artifacts and balancing it to where you minimize all of them as much as possible. Results that are of nearly the same quality as UE4/Unity can be achieved using Godot because it pretty much just uses the same state-of-the-art algorithms and techniques that everybody uses in their engines - it just doesn't have them auto-tuned for you.

I do imagine though that UE4/Unity use some kind of hybrid combination of shadow mapping and baked lighting - where the baked lighting is calculated at a much higher resolution to mitigate all of the artifacting problems, and shadow mapping is only used for dynamic objects to contribute their shadows to the baked lightmaps. If your scene is just too complex and varied to be able to hide all of the artifacting sufficiently there's always baked lighting. If you want to see what the best results are that you can achieve with shadow mapping then here's a little guide on tuning the shadows:

Setup: Under Project Settings -> Rendering -> Quality use a Directional Shadow Size of 8192 (you can always drop it back down to 4096 if its affecting performance later on). You'll have to re-start Godot for any changes to this shadow size parameter to take effect. Shadow filter mode should be at least PCF5, but PCF13 will produce much smoother shadows if you have the extra texture taps to spare (don't have a lot of complex/expensive shaders in your scene that perform a lot of texture samples, including some of the built-in Godot environment effects).

Backside Shadow Casting Method: Under your directional light's "Directional Shadow" parameters set 'Mode' to 'PSSM 4 Splits'. The split values are typically best with 'Split 1' anywhere from 0.075-0.125, and then double for each successive split value (i.e. for a Split1 of 0.1 you would get Splits 2/3 of 0.2/0.4). Enable blend splits to eliminate the hard transition edge between the shadow splits. Set 'normal bias' and 'bias split scale' to zero. Depth range to 'Stable'. Setting Max Distance is crucial because it affects not only the max distance your shadows will be visible from but also how your split values will scale the successive resolution decreases. You want it to be as close as possible to maximize resolution while still being far enough that shadows don't fade out prematurely. If you have a large open terrain scene then you should take a hint from all the open-world AAA titles and accept that your shadow has to fade out at some point and choose a value that has shadows fading out at an acceptable distance. Make sure your bias/contact values are also zero, and Reverse Cull Face is enabled.

Conventional Shadow Casting Method: Keep everything the same as the backside method except disable Reverse Cull Face. This will surely cause shadow acne (the shadow banding artifacts on light-facing surfaces). Now get ready to start paying attention, because here's where you get to play jazz with the numbers. The goal here is to offset the beginning of the shadow-casting to be far enough behind the light-facing surfaces that the shadow acne is gone enough to not be noticeable anymore. The problem is that this can cause thin geometry to 'Peter-Pan', or appear as though it's not touching other surfaces that it's casting a shadow on due to the shadow starting after the thickness of the geometry. This is a trade-off between acne, Peter-Pan, and resolution, where resolution is dictated by both your shadow size and max distance values. Once you find a usable Normal Bias value that sufficiently mitigates the shadow acne in the first level of shadowmapping (shadowmaps generated for the immediate vicinity) you will still likely have shadow acne on more distant shadowmaps from the lower resolution splits. To resolve this you can have Godot's renderer automatically scale up the bias value for them by setting 'Bias Split Scale' to a low value. Start with 0.05 and work your way up in multiples of that until the shadow acne on more distal shadows is also gone. If this value is too high you will start having Peter-Pan effect on the further shadows, so be sure to tune it carefully.

I don't know if this guide is better posted somewheres else, I figure people keep coming here to complain about it so there may as well be something for them to find if they can be bothered to search the issue tracker - which they likely aren't if they won't put the effort into figuring out how to use shadowmapping! I only say as much because it seems like there's multiple issues opened about the shadowmaps being severely broken, doh!

vnen commented 6 years ago

@DEF7 wow, that's documentation material right there.

Zylann commented 6 years ago

What is the status on this? I have shadow acne in my 3D game, even with directional biases that I believe are really high, it still looks bad and it's driving me nuts.

The most obvious observation I can make is, when the window is square, I get no banding: image

But otherwise, I immediately get banding with 16:9 ratio: image

Calinou commented 6 years ago

That reminds me of https://github.com/godotengine/godot/issues/13575#issuecomment-348684215 (wider aspect ratios resulting in worse shadow quality).