Repository: godotengine/godot
File: servers/rendering/rendering_light_culler.h (C/C++)

Code before:
			// sides is close to the length of the longest side,
			// the points are colinear, and the triangle is near degenerate.
			float ld = ((la + lb) - lc) / lc;

			// ld will be close to zero for colinear tris.
			// Long frustums are made out of significantly stretched-out triangles,
			// so a very small threshold is needed to prevent getting very large amounts false-positives.
			// For example: 0.001 causes false-positives with camera FOV of 75 and ortho shadows at ~50m at certain view angles.
			// 0.0001 causes false-positives with camera FOV of 75 and ortho shadows at ~500m at certain view angles.
			// ...These apply less to cascades since they have large near planes in comparison to far planes, unlike ortho lights.
			// [image-unavailable] opinion:
			// Is there any point to this check???
			// It was there from before I came around and it seems to only cause bugs. Does it actually do anything useful?
			return ld < 0.00001f;
		}

		// Don't create planes from tiny triangles,
		// they won't be accurate.
		return true;
	}

	// Internal version uses LightSource.
	bool _add_light_camera_planes(LightCullPlanes &r_cull_planes, const LightSource &p_light_source, const CullParameters &params);

	// Directional light gives parallel culling planes (as opposed to point lights).
	bool add_light_camera_planes_directional(LightCullPlanes &r_cull_planes, const LightSource &p_light_source, const CullParameters &params);

	// Is the light culler active? maybe not in the editor...
	bool is_caster_culling_active() const { return data.caster_culling_active; }
	bool is_light_culling_active() const { return data.light_culling_active; }

	//Ensure result is at least a Plane[6] for the frustum input and Vector3[8] to store result before calling. If not, nasal demons :)
	bool create_frustum_points(const Plane *frustum_planes, Vector3 *result) const;

	// Do we want to log some debug output?
	bool is_logging() const { return data.debug_count == 0; }

	struct Data {
		// Camera frustum planes (world space) - order ePlane.
		Vector<Plane> frustum_planes;

		// Camera frustum corners (world space) - order ePoint.
		Vector3 frustum_points[NUM_CAM_POINTS];

		// Master can have multiple directional lights.
		// These need to store their own cull planes individually, as master
		// chops and changes between culling different lights
		// instead of doing one by one, and we don't want to prepare
		// lights multiple times per frame.
		LocalVector<DirectionalCullPlanes> directional_cull_planes;


Review comment (suggestion):
```suggestion
	bool add_light_camera_planes_directional(LightCullPlanes &r_cull_planes, const LightSource &p_light_source, const CullParameters &p_params);
```

Code after:

		// Get longest side into lc.
		if (lb < la) {
			SWAP(la, lb);
		}
		if (lc < lb) {
			SWAP(lb, lc);
		}

		// Prevent divide by zero.
		if (lc > 0.001f) {
			// If the summed length of the smaller two
			// sides is close to the length of the longest side,
			// the points are colinear, and the triangle is near degenerate.
			float ld = ((la + lb) - lc) / lc;

			// ld will be close to zero for colinear tris.

			// Long frustums are made out of significantly stretched-out triangles,
			// so large threshold will produce large amounts of cullable but unculled meshes.
			// For example: 0.001 fails to cull cullable meshes with camera FOV of 70 and ortho shadows at ~50m at certain view angles.
			// 0.0001 fails to cull cullable meshes with camera FOV of 70 and ortho shadows at ~500m at certain view angles.
			// ...These apply less to cascades since they have large near planes in comparison to far planes, unlike ortho lights.
			// If you're reading this and the value for directional lights is still 0.001f,
			// that is fine as is and it only means GH-115176 didn't make it.
			return ld < 0.001f;
		}

		// Don't create planes from tiny triangles,
		// they won't be accurate.
		return true;
	}

	// Internal version uses LightSource.
	bool _add_light_camera_planes(LightCullPlanes &r_cull_planes, const LightSource &p_light_source, const CullFrustumData &p_cull_frustum);

	// Directional light gives parallel culling planes (as opposed to point lights).
	bool add_light_camera_planes_directional(LightCullPlanes &r_cull_planes, const LightSource &p_light_source, const CullFrustumData &p_cull_frustum);

	// Is the light culler active? maybe not in the editor...
	bool is_caster_culling_active() const { return data.caster_culling_active; }
	bool is_light_culling_active() const { return data.light_culling_active; }

	// Ensure result is at least a Plane[6] for the frustum input and Vector3[8] to store result before calling. If not, undefined behavior.
	bool create_frustum_points(const Plane *p_frustum_planes, Vector3 *r_result) const;

	// Do we want to log some debug output?
	bool is_logging() const { return data.debug_count == 0; }

	struct Data {
		// Camera frustum planes (world space) - order ePlane.