1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-10 13:00:37 +00:00

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.
This commit is contained in:
lawnjelly
2020-01-21 18:39:16 +00:00
parent 11260fb87f
commit eaf8e5ce52
8 changed files with 37 additions and 40 deletions

View File

@@ -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 {