From 0f0e24016ceb11b2503447bb70bce723322dcb7c Mon Sep 17 00:00:00 2001 From: Rudolph Bester Date: Sat, 2 Nov 2024 12:09:10 +0200 Subject: [PATCH] Fix Occlusion Culling Buffer getting corrupted. --- modules/raycast/raycast_occlusion_cull.cpp | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/modules/raycast/raycast_occlusion_cull.cpp b/modules/raycast/raycast_occlusion_cull.cpp index 634c370b059..3609f5a554d 100644 --- a/modules/raycast/raycast_occlusion_cull.cpp +++ b/modules/raycast/raycast_occlusion_cull.cpp @@ -90,18 +90,11 @@ void RaycastOcclusionCull::RaycastHZBuffer::update_camera_rays(const Transform3D td.camera_dir = -p_cam_transform.basis.get_column(2); td.camera_orthogonal = p_cam_orthogonal; - Projection inv_camera_matrix = p_cam_projection.inverse(); - Vector3 camera_corner_proj = Vector3(-1.0f, -1.0f, -1.0f); - Vector3 camera_corner_view = inv_camera_matrix.xform(camera_corner_proj); - td.pixel_corner = p_cam_transform.xform(camera_corner_view); - - Vector3 top_corner_proj = Vector3(-1.0f, 1.0f, -1.0f); - Vector3 top_corner_view = inv_camera_matrix.xform(top_corner_proj); - Vector3 top_corner_world = p_cam_transform.xform(top_corner_view); - - Vector3 left_corner_proj = Vector3(1.0f, -1.0f, -1.0f); - Vector3 left_corner_view = inv_camera_matrix.xform(left_corner_proj); - Vector3 left_corner_world = p_cam_transform.xform(left_corner_view); + // Calculate the world coordinates of the viewport. + Vector2 viewport_half = p_cam_projection.get_viewport_half_extents(); + td.pixel_corner = p_cam_transform.xform(Vector3(-viewport_half.x, -viewport_half.y, -p_cam_projection.get_z_near())); + Vector3 top_corner_world = p_cam_transform.xform(Vector3(-viewport_half.x, viewport_half.y, -p_cam_projection.get_z_near())); + Vector3 left_corner_world = p_cam_transform.xform(Vector3(viewport_half.x, -viewport_half.y, -p_cam_projection.get_z_near())); td.pixel_u_interp = left_corner_world - td.pixel_corner; td.pixel_v_interp = top_corner_world - td.pixel_corner;