summaryrefslogtreecommitdiff
path: root/drivers
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 /drivers
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 'drivers')
-rw-r--r--drivers/gles2/rasterizer_scene_gles2.cpp8
-rw-r--r--drivers/gles3/rasterizer_scene_gles3.cpp18
2 files changed, 15 insertions, 11 deletions
diff --git a/drivers/gles2/rasterizer_scene_gles2.cpp b/drivers/gles2/rasterizer_scene_gles2.cpp
index 6b1574bbbd..4ffd24862d 100644
--- a/drivers/gles2/rasterizer_scene_gles2.cpp
+++ b/drivers/gles2/rasterizer_scene_gles2.cpp
@@ -2685,14 +2685,14 @@ void RasterizerSceneGLES2::_draw_sky(RasterizerStorageGLES2::Sky *p_sky, const C
};
if (!asymmetrical) {
- float vw, vh, zn;
- camera.get_viewport_size(vw, vh);
+ Vector2 vp_he = camera.get_viewport_half_extents();
+ float zn;
zn = p_projection.get_z_near();
for (int i = 0; i < 4; i++) {
Vector3 uv = vertices[i * 2 + 1];
- uv.x = (uv.x * 2.0 - 1.0) * vw;
- uv.y = -(uv.y * 2.0 - 1.0) * vh;
+ uv.x = (uv.x * 2.0 - 1.0) * vp_he.x;
+ uv.y = -(uv.y * 2.0 - 1.0) * vp_he.y;
uv.z = -zn;
vertices[i * 2 + 1] = p_transform.basis.xform(uv).normalized();
vertices[i * 2 + 1].z = -vertices[i * 2 + 1].z;
diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp
index 0ed2637a11..2a59772a60 100644
--- a/drivers/gles3/rasterizer_scene_gles3.cpp
+++ b/drivers/gles3/rasterizer_scene_gles3.cpp
@@ -2538,14 +2538,14 @@ void RasterizerSceneGLES3::_draw_sky(RasterizerStorageGLES3::Sky *p_sky, const C
};
if (!asymmetrical) {
- float vw, vh, zn;
- camera.get_viewport_size(vw, vh);
+ Vector2 vp_he = camera.get_viewport_half_extents();
+ float zn;
zn = p_projection.get_z_near();
for (int i = 0; i < 4; i++) {
Vector3 uv = vertices[i * 2 + 1];
- uv.x = (uv.x * 2.0 - 1.0) * vw;
- uv.y = -(uv.y * 2.0 - 1.0) * vh;
+ uv.x = (uv.x * 2.0 - 1.0) * vp_he.x;
+ uv.y = -(uv.y * 2.0 - 1.0) * vp_he.y;
uv.z = -zn;
vertices[i * 2 + 1] = p_transform.basis.xform(uv).normalized();
vertices[i * 2 + 1].z = -vertices[i * 2 + 1].z;
@@ -4181,11 +4181,15 @@ void RasterizerSceneGLES3::render_scene(const Transform &p_cam_transform, const
state.ubo_data.shadow_dual_paraboloid_render_zfar = 0;
state.ubo_data.opaque_prepass_threshold = 0.99;
- p_cam_projection.get_viewport_size(state.ubo_data.viewport_size[0], state.ubo_data.viewport_size[1]);
+ int viewport_width_pixels = storage->frame.current_rt->width;
+ int viewport_height_pixels = storage->frame.current_rt->height;
+
+ state.ubo_data.viewport_size[0] = viewport_width_pixels;
+ state.ubo_data.viewport_size[1] = viewport_height_pixels;
if (storage->frame.current_rt) {
- state.ubo_data.screen_pixel_size[0] = 1.0 / storage->frame.current_rt->width;
- state.ubo_data.screen_pixel_size[1] = 1.0 / storage->frame.current_rt->height;
+ state.ubo_data.screen_pixel_size[0] = 1.0 / viewport_width_pixels;
+ state.ubo_data.screen_pixel_size[1] = 1.0 / viewport_height_pixels;
}
_setup_environment(env, p_cam_projection, p_cam_transform, p_reflection_probe.is_valid());