Fix some SpotLight3D
issues (clustering artifacts, leaking light, AABB)
#71832
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes light leak to the outside of the cone, visible at certain cone angles (the leaked light changed periodically from being negative to positive, see green spot lights with slightly different spot angle in picture below)
Fixes Vulkan Clustered: SpotLight3D clustering artifacts with no fog or other effects #70698
Fixes Vulkan: SpotLight3D affects lighting outside of the cone #69936
Fixes Vulkan: SpotLight3D exhibits clustering artifacts at small angle relative to the surface #68969
Fixes Vulkan: SpotLight3D + WorldEnvironment fog causes jaggedness due to clustering issues #59262 (likely, could not test since no MRP was provided)
(These basically boil down to the same bug: no clustering issue, but since the light leaks in directions where the cluster builder doesn't expect it to be it looks blocky; its also visible in the mobile renderer)
Cause: Bisected to More fixes to mobile renderer #51843. Seems to be a precision issue, changing the precision of
cone_angle
frommediump
tohighp
in theLightData
struct (light_data_inc.glsl
) also fixes the issue, but I went with convertingcone_angle
to ahighp float
inside the shader so the struct size doesn't have to be increased.Fixes AABB generation
The wrong trigonometric function was used, so the AABB would grow towards infinity for angles close to 90 degrees. For angles above 90 degrees a box enclosing the whole sphere (radius = range) is generated.
Fixes clustering for angles close to and above 90 degrees
Fixes Vulkan: SpotLight3D angles above 90 degrees cause clustering artifacts (even with shadows disabled) #48054
Introduces a threshold constant: the angle above which the cluster builder uses a sphere instead of a cone (see comment in code).
Before
With this PR