From eaf8e5ce52331d05ee117c21e114ab0990dd3a9b Mon Sep 17 00:00:00 2001 From: lawnjelly Date: Tue, 21 Jan 2020 18:39:16 +0000 Subject: 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. --- core/math/camera_matrix.cpp | 10 ++++------ core/math/camera_matrix.h | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) (limited to 'core') diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp index 165bb9f823..380bae871a 100644 --- a/core/math/camera_matrix.cpp +++ b/core/math/camera_matrix.cpp @@ -247,7 +247,7 @@ real_t CameraMatrix::get_z_near() const { return new_plane.d; } -void CameraMatrix::get_viewport_size(real_t &r_width, real_t &r_height) const { +Vector2 CameraMatrix::get_viewport_half_extents() const { const real_t *matrix = (const real_t *)this->matrix; ///////--- Near Plane ---/////// @@ -273,8 +273,7 @@ void CameraMatrix::get_viewport_size(real_t &r_width, real_t &r_height) const { Vector3 res; near_plane.intersect_3(right_plane, top_plane, &res); - r_width = res.x; - r_height = res.y; + return Vector2(res.x, res.y); } bool CameraMatrix::get_endpoints(const Transform &p_transform, Vector3 *p_8points) const { @@ -563,9 +562,8 @@ CameraMatrix::operator String() const { real_t CameraMatrix::get_aspect() const { - real_t w, h; - get_viewport_size(w, h); - return w / h; + Vector2 vp_he = get_viewport_half_extents(); + return vp_he.x / vp_he.y; } int CameraMatrix::get_pixels_per_meter(int p_for_pixel_width) const { diff --git a/core/math/camera_matrix.h b/core/math/camera_matrix.h index 59e34c0855..2eed6d25d6 100644 --- a/core/math/camera_matrix.h +++ b/core/math/camera_matrix.h @@ -73,7 +73,7 @@ struct CameraMatrix { Vector get_projection_planes(const Transform &p_transform) const; bool get_endpoints(const Transform &p_transform, Vector3 *p_8points) const; - void get_viewport_size(real_t &r_width, real_t &r_height) const; + Vector2 get_viewport_half_extents() const; void invert(); CameraMatrix inverse() const; -- cgit v1.2.3