Skip to content

Commit b929b67

Browse files
committed
Use p_cam_projection.get_endpoints() to calculate the viewport location
Fixes #104193 In OpenXR the viewport location is not centered on the transform origin
1 parent 0028fd6 commit b929b67

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

modules/raycast/raycast_occlusion_cull.cpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -525,14 +525,14 @@ void RaycastOcclusionCull::buffer_set_size(RID p_buffer, const Vector2i &p_size)
525525
buffers[p_buffer].resize(p_size);
526526
}
527527

528-
Vector2 RaycastOcclusionCull::_jitter_half_extents(const Vector2 &p_half_extents, const Size2i &p_viewport_size) {
528+
Vector2 RaycastOcclusionCull::_get_jitter(const Vector2 &p_half_extents, const Size2i &p_viewport_size) {
529529
if (!_jitter_enabled) {
530-
return p_half_extents;
530+
return Vector2();
531531
}
532532

533533
// Prevent divide by zero when using NULL viewport.
534534
if ((p_viewport_size.x <= 0) || (p_viewport_size.y <= 0)) {
535-
return p_half_extents;
535+
return Vector2();
536536
}
537537

538538
int32_t frame = Engine::get_singleton()->get_frames_drawn();
@@ -578,7 +578,7 @@ Vector2 RaycastOcclusionCull::_jitter_half_extents(const Vector2 &p_half_extents
578578
// False shown can lower percentage that are occluded, and therefore performance.
579579
jitter *= 0.66f;
580580

581-
return p_half_extents + jitter;
581+
return jitter;
582582
}
583583

584584
void RaycastOcclusionCull::buffer_update(RID p_buffer, const Transform3D &p_cam_transform, const Projection &p_cam_projection, bool p_cam_orthogonal) {
@@ -596,8 +596,10 @@ void RaycastOcclusionCull::buffer_update(RID p_buffer, const Transform3D &p_cam_
596596
scenario.update();
597597

598598
Vector2 viewport_half = p_cam_projection.get_viewport_half_extents();
599-
Vector2 jitter_viewport_half = _jitter_half_extents(viewport_half, buffer.get_occlusion_buffer_size());
600-
Vector3 near_bottom_left = Vector3(-jitter_viewport_half.x, -jitter_viewport_half.y, -p_cam_projection.get_z_near());
599+
Vector2 jitter = _get_jitter(viewport_half, buffer.get_occlusion_buffer_size());
600+
Vector3 endpoints[8];
601+
p_cam_projection.get_endpoints(Transform3D(), endpoints);
602+
Vector3 near_bottom_left = Vector3(jitter.x, jitter.y, 0) + endpoints[5];
601603

602604
buffer.update_camera_rays(p_cam_transform, near_bottom_left, 2 * viewport_half, p_cam_projection.get_z_far(), p_cam_orthogonal);
603605

modules/raycast/raycast_occlusion_cull.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class RaycastOcclusionCull : public RendererSceneOcclusionCull {
161161
bool _jitter_enabled = false;
162162

163163
void _init_embree();
164-
Vector2 _jitter_half_extents(const Vector2 &p_half_extents, const Size2i &p_viewport_size);
164+
Vector2 _get_jitter(const Vector2 &p_half_extents, const Size2i &p_viewport_size);
165165

166166
public:
167167
virtual bool is_occluder(RID p_rid) override;

0 commit comments

Comments
 (0)