Skip to content

Commit 78a4e63

Browse files
authored
Merge pull request godotengine#98257 from Rudolph-B/94210-B
Fix to occlusion culling where all math is based on Euclidean distance.
2 parents e952651 + ed3f990 commit 78a4e63

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

modules/raycast/raycast_occlusion_cull.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -181,17 +181,7 @@ void RaycastOcclusionCull::RaycastHZBuffer::sort_rays(const Vector3 &p_camera_di
181181
}
182182
int k = tile_i * TILE_SIZE + tile_j;
183183
int tile_index = i * tile_grid_size.x + j;
184-
float d = camera_rays[tile_index].ray.tfar[k];
185-
186-
if (!p_orthogonal) {
187-
const float &dir_x = camera_rays[tile_index].ray.dir_x[k];
188-
const float &dir_y = camera_rays[tile_index].ray.dir_y[k];
189-
const float &dir_z = camera_rays[tile_index].ray.dir_z[k];
190-
float cos_theta = p_camera_dir.x * dir_x + p_camera_dir.y * dir_y + p_camera_dir.z * dir_z;
191-
d *= cos_theta;
192-
}
193-
194-
mips[0][y * buffer_size.x + x] = d;
184+
mips[0][y * buffer_size.x + x] = camera_rays[tile_index].ray.tfar[k];
195185
}
196186
}
197187
}

servers/rendering/renderer_scene_occlusion_cull.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class RendererSceneOcclusionCull {
7272
return false;
7373
}
7474

75-
float min_depth = -closest_point_view.z * 0.95f;
75+
float min_depth = (closest_point - p_cam_position).length();
7676

7777
Vector2 rect_min = Vector2(FLT_MAX, FLT_MAX);
7878
Vector2 rect_max = Vector2(FLT_MIN, FLT_MIN);
@@ -83,6 +83,10 @@ class RendererSceneOcclusionCull {
8383
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);
8484
Vector3 view = p_cam_inv_transform.xform(corner);
8585

86+
if (p_cam_projection.is_orthogonal()) {
87+
min_depth = MIN(min_depth, view.z);
88+
}
89+
8690
Plane vp = Plane(view, 1.0);
8791
Plane projected = p_cam_projection.xform4(vp);
8892

0 commit comments

Comments
 (0)