summaryrefslogtreecommitdiff
path: root/core
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 /core
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 'core')
-rw-r--r--core/math/camera_matrix.cpp10
-rw-r--r--core/math/camera_matrix.h2
2 files changed, 5 insertions, 7 deletions
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<Plane> 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;