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

Implement distance fade properties in OmniLight3D and SpotLight3D #58512

Merged
merged 1 commit into from
Mar 4, 2022

Conversation

Calinou
Copy link
Member

@Calinou Calinou commented Feb 24, 2022

This can be used to fade lights and their shadows in the distance, similar to Decal nodes. This can bring significant performance improvements, especially for lights with shadows enabled and when using higher-than-default shadow quality settings.

While lights can be smoothly faded out over distance, shadows are currently "all or nothing" since per-light shadow color is no longer customizable in the Vulkan renderer. This may result in noticeable pop-in when leaving the shadow cutoff distance, but depending on the scene, it may not always be that noticeable.

The default values and property hints are identical to #58296. Note that distance fade is still disabled by default (like for Decal), which means the default light rendering behavior is unchanged.

I've tested this PR with VoxelGI, SDFGI and LightmapGI. All techniques still work with distance fade, regardless of the camera position when baking. Lights will still be present in GI rendering even if they are past the distance, but this also helps make light transitions less noticeable, so it's not too bad.


Edit (May 2022): I started working on a 3.x backport, but didn't manage to get it fully working so far:
https://github.com/Calinou/godot/tree/light-add-distance-fade-3.x


This closes godotengine/godot-proposals#2744.

Testing project: test_light_lod.zip
Press L to toggle distance fade for all lights.

Preview

The highest shadow quality settings are used here.

Without distance fade

Lights are never culled regardless of distance. This is the current behavior.

2022-02-24_22 53 34

With distance fade

Distant lights are culled, and partially faded lights have their shadows disabled (this is configurable).

2022-02-24_22 51 40

This can be used to fade lights and their shadows in the distance,
similar to Decal nodes. This can bring significant performance
improvements, especially for lights with shadows enabled and when
using higher-than-default shadow quality settings.

While lights can be smoothly faded out over distance, shadows are
currently "all or nothing" since per-light shadow color is no longer
customizable in the Vulkan renderer. This may result in noticeable
pop-in when leaving the shadow cutoff distance, but depending on the
scene, it may not always be that noticeable.
Copy link
Contributor

@JFonS JFonS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

We have discussed in the past about adding a unified distance fade system for all visual instance types, but I think if this ever happens, it will be a set of properties in VisualInstance that are handled accordingly on each visual type. That means these changes should be reusable mostly unchanged, and the feature is useful on its own.

@@ -3494,7 +3522,24 @@ void RendererSceneRenderRD::_setup_lights(const PagedArray<RID> &p_lights, const

light_data.attenuation = storage->light_get_param(base, RS::LIGHT_PARAM_ATTENUATION);

float energy = sign * storage->light_get_param(base, RS::LIGHT_PARAM_ENERGY) * Math_PI;
// Reuse fade begin, fade length and distance for shadow LOD determination later.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this some reference for a future implementation? I don't see anything related to shadow LOD in this PR.

Copy link
Member Author

@Calinou Calinou Mar 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Light shadow LOD refers to the shadow cutoff distance, which can be set separately from the light cutoff distance (which is begin + length). I can reword the comment if it's confusing.

@akien-mga akien-mga merged commit 3078b92 into godotengine:master Mar 4, 2022
@akien-mga
Copy link
Member

Thanks!

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

Successfully merging this pull request may close these issues.

Add a level of detail system for OmniLight3D and SpotLight3D
3 participants