mirror of
https://github.com/Redot-Engine/redot-engine.git
synced 2025-12-06 23:31:53 -05:00
Tighter shadow culling - fix light colinear to frustum edge
In rare situations if a light is placed near colinear to a frustum edge, the extra culling plane derived can have an inaccurate normal due to floating point error. This PR detects colinear triangles, and prevents adding a culling plane in this situation.
This commit is contained in:
@@ -427,15 +427,19 @@ bool RenderingLightCuller::_add_light_camera_planes(LightCullPlanes &r_cull_plan
|
||||
uint8_t *entry = &data.LUT_entries[lookup][0];
|
||||
int n_edges = data.LUT_entry_sizes[lookup] - 1;
|
||||
|
||||
const Vector3 &pt2 = p_light_source.pos;
|
||||
|
||||
for (int e = 0; e < n_edges; e++) {
|
||||
int i0 = entry[e];
|
||||
int i1 = entry[e + 1];
|
||||
const Vector3 &pt0 = data.frustum_points[i0];
|
||||
const Vector3 &pt1 = data.frustum_points[i1];
|
||||
|
||||
// Create plane from 3 points.
|
||||
Plane p(pt0, pt1, p_light_source.pos);
|
||||
r_cull_planes.add_cull_plane(p);
|
||||
if (!_is_colinear_tri(pt0, pt1, pt2)) {
|
||||
// Create plane from 3 points.
|
||||
Plane p(pt0, pt1, pt2);
|
||||
r_cull_planes.add_cull_plane(p);
|
||||
}
|
||||
}
|
||||
|
||||
// Last to 0 edge.
|
||||
@@ -446,9 +450,11 @@ bool RenderingLightCuller::_add_light_camera_planes(LightCullPlanes &r_cull_plan
|
||||
const Vector3 &pt0 = data.frustum_points[i0];
|
||||
const Vector3 &pt1 = data.frustum_points[i1];
|
||||
|
||||
// Create plane from 3 points.
|
||||
Plane p(pt0, pt1, p_light_source.pos);
|
||||
r_cull_planes.add_cull_plane(p);
|
||||
if (!_is_colinear_tri(pt0, pt1, pt2)) {
|
||||
// Create plane from 3 points.
|
||||
Plane p(pt0, pt1, pt2);
|
||||
r_cull_planes.add_cull_plane(p);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef LIGHT_CULLER_DEBUG_LOGGING
|
||||
|
||||
Reference in New Issue
Block a user