summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDario <dariosamo@gmail.com>2023-10-09 08:25:03 -0300
committerDario <dariosamo@gmail.com>2023-10-09 09:44:40 -0300
commit94c60ae556f66271ae1345e395c01d60e1d2ad97 (patch)
treea55b799127dc0c1644dc2afc93827ad6121c4517
parent6916349697a4339216469e9bf5899b983d78db07 (diff)
downloadredot-engine-94c60ae556f66271ae1345e395c01d60e1d2ad97.tar.gz
Fix trace_ray() function in the lightmapper missing hits with large triangles.
The DDA traversal had a conceptual error where it did an early termination of the search if it hit a triangle, but it didn't check if the hit position was inside the bounds of the cell being traversed. This can aid to fix light leaks such as the ones found in issue #75440.
-rw-r--r--modules/lightmapper_rd/lm_compute.glsl8
1 files changed, 8 insertions, 0 deletions
diff --git a/modules/lightmapper_rd/lm_compute.glsl b/modules/lightmapper_rd/lm_compute.glsl
index ce33f2ed1d..cccf7db96e 100644
--- a/modules/lightmapper_rd/lm_compute.glsl
+++ b/modules/lightmapper_rd/lm_compute.glsl
@@ -205,6 +205,14 @@ uint trace_ray(vec3 p_from, vec3 p_to
return RAY_ANY; //any hit good
#endif
+ vec3 position = p_from + dir * distance;
+ vec3 hit_cell = (position - params.to_cell_offset) * params.to_cell_size;
+ if (icell != ivec3(hit_cell)) {
+ // It's possible for the ray to hit a triangle in a position outside the bounds of the cell
+ // if it's large enough to cover multiple ones. The hit must be ignored if this is the case.
+ continue;
+ }
+
#if defined(MODE_UNOCCLUDE) || defined(MODE_BOUNCE_LIGHT) || defined(MODE_LIGHT_PROBES)
if (!backface) {
// the case of meshes having both a front and back face in the same plane is more common than