Browse Source

Merge pull request #91789 from lawnjelly/fix_tight_light_cull_directional_colinear

[3.x] Tighter light culling - fix directional lights colinear case
lawnjelly 1 year ago
parent
commit
30b025d3d0
1 changed files with 10 additions and 6 deletions
  1. 10 6
      servers/visual/visual_server_light_culler.cpp

+ 10 - 6
servers/visual/visual_server_light_culler.cpp

@@ -227,9 +227,11 @@ bool VisualServerLightCuller::add_light_camera_planes_directional(const LightSou
 		// Create a third point from the light direction.
 		// Create a third point from the light direction.
 		Vector3 pt2 = pt0 - p_light_source.dir;
 		Vector3 pt2 = pt0 - p_light_source.dir;
 
 
-		// Create plane from 3 points.
-		Plane p(pt0, pt1, pt2);
-		add_cull_plane(p);
+		if (!_is_colinear_tri(pt0, pt1, pt2)) {
+			// Create plane from 3 points.
+			Plane p(pt0, pt1, pt2);
+			add_cull_plane(p);
+		}
 	}
 	}
 
 
 	// Last to 0 edge.
 	// Last to 0 edge.
@@ -243,9 +245,11 @@ bool VisualServerLightCuller::add_light_camera_planes_directional(const LightSou
 		// Create a third point from the light direction.
 		// Create a third point from the light direction.
 		Vector3 pt2 = pt0 - p_light_source.dir;
 		Vector3 pt2 = pt0 - p_light_source.dir;
 
 
-		// Create plane from 3 points.
-		Plane p(pt0, pt1, pt2);
-		add_cull_plane(p);
+		if (!_is_colinear_tri(pt0, pt1, pt2)) {
+			// Create plane from 3 points.
+			Plane p(pt0, pt1, pt2);
+			add_cull_plane(p);
+		}
 	}
 	}
 
 
 #ifdef LIGHT_CULLER_DEBUG_LOGGING
 #ifdef LIGHT_CULLER_DEBUG_LOGGING