summaryrefslogtreecommitdiff
path: root/scene/3d/arvr_nodes.cpp
diff options
context:
space:
mode:
authorlawnjelly <lawnjelly@gmail.com>2020-01-21 18:39:16 +0000
committerlawnjelly <lawnjelly@gmail.com>2020-01-22 18:22:00 +0000
commiteaf8e5ce52331d05ee117c21e114ab0990dd3a9b (patch)
tree3de2610cfe1cbb042a3b7273d571762142d10085 /scene/3d/arvr_nodes.cpp
parent11260fb87f393e56692e6ba063609b5993d8d5f6 (diff)
Change CameraMatrix::get_viewport_size to get_viewport_half_extents
Fixes #26637. Fixes #19900. The viewport_size returned by get_viewport_size was previously incorrect, being half the correct value. The function is renamed to get_viewport_half_extents, and now returns a Vector2. Code which called this function has also been modified accordingly. This PR also fixes shadow culling when using ortho cameras, because the correct input for CameraMatrix::set_orthogonal should be the full HEIGHT from get_viewport_half_extents, and not half the width. It also fixes state.ubo_data.viewport_size in rasterizer_scene_gles3.cpp to be the width and the height of the viewport in pixels as stated in the documentation, rather than the current value which is half the viewport extents in worldspace, presumed to be a bug.
Diffstat (limited to 'scene/3d/arvr_nodes.cpp')
-rw-r--r--scene/3d/arvr_nodes.cpp10
1 files changed, 4 insertions, 6 deletions
diff --git a/scene/3d/arvr_nodes.cpp b/scene/3d/arvr_nodes.cpp
index 82293268b9..0f74bf673c 100644
--- a/scene/3d/arvr_nodes.cpp
+++ b/scene/3d/arvr_nodes.cpp
@@ -85,9 +85,8 @@ Vector3 ARVRCamera::project_local_ray_normal(const Point2 &p_pos) const {
Vector3 ray;
CameraMatrix cm = arvr_interface->get_projection_for_eye(ARVRInterface::EYE_MONO, viewport_size.aspect(), get_znear(), get_zfar());
- float screen_w, screen_h;
- cm.get_viewport_size(screen_w, screen_h);
- ray = Vector3(((cpos.x / viewport_size.width) * 2.0 - 1.0) * screen_w, ((1.0 - (cpos.y / viewport_size.height)) * 2.0 - 1.0) * screen_h, -get_znear()).normalized();
+ Vector2 screen_he = cm.get_viewport_half_extents();
+ ray = Vector3(((cpos.x / viewport_size.width) * 2.0 - 1.0) * screen_he.x, ((1.0 - (cpos.y / viewport_size.height)) * 2.0 - 1.0) * screen_he.y, -get_znear()).normalized();
return ray;
};
@@ -138,13 +137,12 @@ Vector3 ARVRCamera::project_position(const Point2 &p_point, float p_z_depth) con
CameraMatrix cm = arvr_interface->get_projection_for_eye(ARVRInterface::EYE_MONO, viewport_size.aspect(), get_znear(), get_zfar());
- Size2 vp_size;
- cm.get_viewport_size(vp_size.x, vp_size.y);
+ Vector2 vp_he = cm.get_viewport_half_extents();
Vector2 point;
point.x = (p_point.x / viewport_size.x) * 2.0 - 1.0;
point.y = (1.0 - (p_point.y / viewport_size.y)) * 2.0 - 1.0;
- point *= vp_size;
+ point *= vp_he;
Vector3 p(point.x, point.y, -p_z_depth);