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

Contact hardening soft shadows / Percentage-Closer Soft Shadows #3643

Closed
Leakbang opened this issue Dec 7, 2021 · 4 comments
Closed

Contact hardening soft shadows / Percentage-Closer Soft Shadows #3643

Leakbang opened this issue Dec 7, 2021 · 4 comments

Comments

@Leakbang
Copy link

Leakbang commented Dec 7, 2021

Describe the project you are working on

A 3D physics based, FPS

Describe the problem or limitation you are having in your project

Poor implementation of shadows both in Vulkan

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

Add Contact hardening soft shadows. It means that shadows get blurrier, the further they are from a light source. Below is an example of it:
image
Source (Nvidia Docs)
Another neat implementation of it in Babylon.js:
image
Source (Babylon.js Docs)

This would be an amazing addition to the Vulkan renderer in Godot 4. It makes the scenes especially interior ones look much more realistic, also it adds a special beauty to daylight nature scenes. With the tree trunk having sharper shadows and the leaves and branches being more blurred out.

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

Each light source will receive a boolean option to toggle Contact hardening soft shadows on or off. By default it would be disabled as it will cost some processing power.

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

No. This feature is not simple enough to be implemented with only a few lines of code.

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

This significantly improves the current state of shadows in Vulkan. As of v4.0.dev.calinou [c1ed695f3], the lighting and shadows don't work as intended, but from screenshots that I have seen, the Vulkan shadows could really get some upgrades. There is a lot of dithering and soft shadows are extremely grainy. Additionally, adding such feature via an add-on might be impossible and or severely impact performance.

@Calinou
Copy link
Member

Calinou commented Dec 7, 2021

PCSS is already implemented for all light types in the master branch. You can enable it by increasing the light's Size (OmniLight3D/SpotLight3D) or Angular Distance (DirectionalLight3D) property above 0.0 (this is separate from the Range property). After increasing Size, play around with the light's Shadow Blur property. This acts as a global multiplier for shadow blur and also works for lights that have PCSS-style shadows.

PCSS could technically be backported to the GLES3 renderer in 3.x, but it's not really worth the effort since PCSS is high-end-oriented.

but from screenshots that I have seen, the Vulkan shadows could really get some upgrades. There is a lot of dithering and soft shadows are extremely grainy.

This is a known issue, see godotengine/godot#53534. This dithering is present by design. In most scenes with significant texture detail, it improves overall shadow rendering quality at high resolutions (reducing the typical aliasing visible in filtered shadows), but it has a noticeable performance impact.

It's technically possible to add a setting to disable shadow dithering. This would improve performance slightly, but it will make shadows look worse at high resolutions in most situations: godotengine/godot#53961

@Leakbang
Copy link
Author

Leakbang commented Dec 7, 2021

Wow it's actually amazing that PCSS is already implemented. But I have to say, this feature is kind of buried. I had no idea that size is supposed to represent PCSS. Probably the naming could be improved a bit to indicate the presence of this feature.

This is a known issue, see godotengine/godot#53534. This dithering is present by design.

Thank you for mentioning that issue. I did notice that issue before opening this thread. However, by running some tests of my own I was quite disappointed by the shadow quality.
This is a small scene with a couple of CSG cubes and an omnilight casting a shadow with the minimum Blur. It is the default shadow atlas size (4096).
image
Increasing the shadow atlas size to 16k reduces the aliasing but still it is very visible.

It looks much better when blurred, however still some massive aliasing is visible. Specifically where the pole touches the ground (shown below).
image

Perhaps an idea would be to render the hard shadows with a method like stencil shadows, so they look crispy, and for soft shadows the current implementation is kept. In the shadow mode property a new Stencil shadows option could be added for rendering hard shadows.

@Calinou
Copy link
Member

Calinou commented Dec 7, 2021

Wow it's actually amazing that PCSS is already implemented. But I have to say, this feature is kind of buried. I had no idea that size is supposed to represent PCSS. Probably the naming could be improved a bit to indicate the presence of this feature.

This is because light size defines how strong the PCSS effect should be (it also modifies the attenuation a little). It's how light behaves in real life. In real life, if a point light was infinitely small (in terms of emitter size), then its shadows would always be perfectly sharp.

This light size property also allows enabling PCSS on a per-light basis, and with different intensities for each light. This is important to keep performance high, as PCSS cannot be used on every light with shadows or performance will likely plummet.

This is a small scene with a couple of CSG cubes and an omnilight casting a shadow with the minimum Blur. It is the default shadow atlas size (4096).

The aliasing is expected when the blur is set to a low value. Therefore, I recommend keeping the Blur value to 1.0 at least. The dithering helps hide the aliasing – without dithering, it'd look even worse 🙂

Perhaps an idea would be to render the hard shadows with a method like stencil shadows, so they look crispy, and for soft shadows the current implementation is kept. In the shadow mode property a new Stencil shadows option could be added for rendering hard shadows.

There are no plans to implement stencil shadows, as they are very expensive as soon as your geometry gets remotely complex. Support for stencil in shaders is planned in a future 4.x release (so you could create stencil shadows manually), but not in 4.0.

@Leakbang
Copy link
Author

Leakbang commented Dec 7, 2021

That's very good to know! Thanks for the detailed response :)

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