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

Code before:
		for (uint32_t n = 0; n < data.directional_cull_planes.size(); n++) {
			print_line("LightCuller directional light " + itos(n) + " rejected " + itos(data.directional_cull_planes[n].rejected_count) + " instances.");
		}
	}
#endif
#ifdef LIGHT_CULLER_DEBUG_REGULAR_LIGHT
	if (data.regular_rejected_count) {
		print_line("LightCuller regular lights rejected " + itos(data.regular_rejected_count) + " instances.");
	}
	data.regular_rejected_count = 0;
#endif

	data.directional_cull_planes.resize(0);

#ifdef LIGHT_CULLER_DEBUG_LOGGING
	if (is_logging()) {
		for (int p = 0; p < 6; p++) {
			print_line("plane " + itos(p) + " : " + String(data.frustum_planes[p]));
		}
	}
#endif

	return create_frustum_points(&data.frustum_planes[0], data.frustum_points);
}

bool RenderingLightCuller::create_frustum_points(const Plane *frustum_planes, Vector3 *result) const {
	// We want to calculate the frustum corners in a specific order.
	const Projection::Planes intersections[8][3] = {
		{ Projection::PLANE_FAR, Projection::PLANE_LEFT, Projection::PLANE_TOP },
		{ Projection::PLANE_FAR, Projection::PLANE_LEFT, Projection::PLANE_BOTTOM },
		{ Projection::PLANE_FAR, Projection::PLANE_RIGHT, Projection::PLANE_TOP },
		{ Projection::PLANE_FAR, Projection::PLANE_RIGHT, Projection::PLANE_BOTTOM },
		{ Projection::PLANE_NEAR, Projection::PLANE_LEFT, Projection::PLANE_TOP },
		{ Projection::PLANE_NEAR, Projection::PLANE_LEFT, Projection::PLANE_BOTTOM },
		{ Projection::PLANE_NEAR, Projection::PLANE_RIGHT, Projection::PLANE_TOP },
		{ Projection::PLANE_NEAR, Projection::PLANE_RIGHT, Projection::PLANE_BOTTOM },
	};

	for (int i = 0; i < 8; i++) {
		// 3 plane intersection, gives us a point.
		bool res = frustum_planes[intersections[i][0]].intersect_3(frustum_planes[intersections[i][1]], frustum_planes[intersections[i][2]], &result[i]);

		// What happens with a zero frustum? NYI - deal with this.
		ERR_FAIL_COND_V(!res, false);

#ifdef LIGHT_CULLER_DEBUG_LOGGING
		if (is_logging()) {
			print_line("point " + itos(i) + " -> " + String(result[i]));
		}
#endif
	}

Review comment (suggestion):
```suggestion
bool RenderingLightCuller::create_frustum_points(const Plane *p_frustum_planes, Vector3 *r_result) const {
```

Code after:
	data.regular_cull_planes.num_cull_planes = 0;

#ifdef LIGHT_CULLER_DEBUG_DIRECTIONAL_LIGHT
	if (is_logging()) {
		for (uint32_t n = 0; n < data.directional_cull_planes.size(); n++) {
			print_line("LightCuller directional light " + itos(n) + " rejected " + itos(data.directional_cull_planes[n].rejected_count) + " instances.");
		}
	}
#endif
#ifdef LIGHT_CULLER_DEBUG_REGULAR_LIGHT
	if (data.regular_rejected_count) {
		print_line("LightCuller regular lights rejected " + itos(data.regular_rejected_count) + " instances.");
	}
	data.regular_rejected_count = 0;
#endif

	data.directional_cull_planes.resize(0);

#ifdef LIGHT_CULLER_DEBUG_LOGGING
	if (is_logging()) {
		for (int p = 0; p < 6; p++) {
			print_line("plane " + itos(p) + " : " + String(data.frustum_planes[p]));
		}
	}
#endif

	return create_frustum_points(&data.frustum_planes[0], data.frustum_points);
}

bool RenderingLightCuller::create_frustum_points(const Plane *p_frustum_planes, Vector3 *r_result) const {
	// We want to calculate the frustum corners in a specific order.
	const Projection::Planes intersections[8][3] = {
		{ Projection::PLANE_FAR, Projection::PLANE_LEFT, Projection::PLANE_TOP },
		{ Projection::PLANE_FAR, Projection::PLANE_LEFT, Projection::PLANE_BOTTOM },
		{ Projection::PLANE_FAR, Projection::PLANE_RIGHT, Projection::PLANE_TOP },
		{ Projection::PLANE_FAR, Projection::PLANE_RIGHT, Projection::PLANE_BOTTOM },
		{ Projection::PLANE_NEAR, Projection::PLANE_LEFT, Projection::PLANE_TOP },
		{ Projection::PLANE_NEAR, Projection::PLANE_LEFT, Projection::PLANE_BOTTOM },
		{ Projection::PLANE_NEAR, Projection::PLANE_RIGHT, Projection::PLANE_TOP },
		{ Projection::PLANE_NEAR, Projection::PLANE_RIGHT, Projection::PLANE_BOTTOM },
	};

	for (int i = 0; i < 8; i++) {
		// 3 plane intersection, gives us a point.
		bool res = p_frustum_planes[intersections[i][0]].intersect_3(p_frustum_planes[intersections[i][1]], p_frustum_planes[intersections[i][2]], &r_result[i]);

		// What happens with a zero frustum? NYI - deal with this.
		ERR_FAIL_COND_V(!res, false);

#ifdef LIGHT_CULLER_DEBUG_LOGGING
		if (is_logging()) {