Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix culling with infinite projection matrix #95944

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions core/math/projection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,14 @@ Plane Projection::get_projection_plane(Planes p_plane) const {
matrix[11] - matrix[10],
matrix[15] - matrix[14]);

new_plane.normal = -new_plane.normal;
new_plane.normalize();
if (new_plane.normal[0] == 0 && new_plane.normal[1] == 0 && new_plane.normal[2] == 0) {
new_plane.normal = Vector3(0, 0, -1);
new_plane.d = INFINITY;
} else {
new_plane.normal = -new_plane.normal;
new_plane.normalize();
}

return new_plane;
}
case PLANE_LEFT: {
Expand Down Expand Up @@ -408,6 +414,10 @@ real_t Projection::get_z_far() const {
matrix[11] - matrix[10],
matrix[15] - matrix[14]);

if (new_plane.normal[0] == 0 && new_plane.normal[1] == 0 && new_plane.normal[2] == 0) {
return INFINITY;
}

new_plane.normalize();

return new_plane.d;
Expand Down Expand Up @@ -459,7 +469,13 @@ Vector2 Projection::get_far_plane_half_extents() const {
matrix[7] - matrix[6],
matrix[11] - matrix[10],
-matrix[15] + matrix[14]);
far_plane.normalize();

if (far_plane.normal[0] == 0 && far_plane.normal[1] == 0 && far_plane.normal[2] == 0) {
far_plane.normal = Vector3(0, 0, 1);
far_plane.d = -INFINITY;
} else {
far_plane.normalize();
}

///////--- Right Plane ---///////
Plane right_plane = Plane(matrix[3] - matrix[0],
Expand Down Expand Up @@ -537,8 +553,13 @@ Vector<Plane> Projection::get_projection_planes(const Transform3D &p_transform)
matrix[11] - matrix[10],
matrix[15] - matrix[14]);

new_plane.normal = -new_plane.normal;
new_plane.normalize();
if (new_plane.normal[0] == 0 && new_plane.normal[1] == 0 && new_plane.normal[2] == 0) {
new_plane.normal = Vector3(0, 0, -1);
new_plane.d = INFINITY;
} else {
new_plane.normal = -new_plane.normal;
new_plane.normalize();
}

planes.write[1] = p_transform.xform(new_plane);

Expand Down
Loading