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

Switch occlusion culling to be based on depth instead of Euclidean distance #103798

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion modules/raycast/raycast_occlusion_cull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ void RaycastOcclusionCull::RaycastHZBuffer::sort_rays(const Vector3 &p_camera_di
}
int k = tile_i * TILE_SIZE + tile_j;
int tile_index = i * tile_grid_size.x + j;
mips[0][y * buffer_size.x + x] = camera_rays[tile_index].ray.tfar[k];

Vector3 ray_dir(camera_rays[tile_index].ray.dir_x[k], camera_rays[tile_index].ray.dir_y[k], camera_rays[tile_index].ray.dir_z[k]);
mips[0][y * buffer_size.x + x] = camera_rays[tile_index].ray.tfar[k] * p_camera_dir.dot(ray_dir); // Store z-depth in view space.
}
}
}
Expand Down
7 changes: 2 additions & 5 deletions servers/rendering/renderer_scene_occlusion_cull.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class RendererSceneOcclusionCull {
return false;
}

float min_depth = (closest_point - p_cam_position).length();
float min_depth = -closest_point_view.z;

Vector2 rect_min = Vector2(FLT_MAX, FLT_MAX);
Vector2 rect_max = Vector2(FLT_MIN, FLT_MIN);
Expand All @@ -82,12 +82,9 @@ class RendererSceneOcclusionCull {
Vector3 corner = Vector3(p_bounds[0] * c.x + p_bounds[3] * nc.x, p_bounds[1] * c.y + p_bounds[4] * nc.y, p_bounds[2] * c.z + p_bounds[5] * nc.z);
Vector3 view = p_cam_inv_transform.xform(corner);

if (p_cam_projection.is_orthogonal()) {
min_depth = MIN(min_depth, -view.z);
}

Plane vp = Plane(view, 1.0);
Plane projected = p_cam_projection.xform4(vp);
min_depth = MIN(min_depth, -view.z);

float w = projected.d;
if (w < 1.0) {
Expand Down