Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Kim <pk15950@gmail.com>2021-10-26 07:33:21 +0300
committerPeter Kim <pk15950@gmail.com>2021-10-26 07:35:12 +0300
commit7ae2810848338033d9e71834a2cea294025cb214 (patch)
tree5c8776296e11952274d70e9392a40b53f36906ad /source/blender/draw
parent3434a991ec5befef19c5484bfc70a3a333e42c34 (diff)
XR: View adjustments for variable viewer scale
This adjusts some calculations and visibility flags for XR viewports in order to account for a possible scale factor in the XR view matrix. This scale factor can be introduced via the XR session settings base scale, which allows a viewer to begin their session at a specific reference scale, or the XR session state navigation scale, which allows a viewer to adjust their scale relative to the reference scale during the session. Reviewed by Severin as part of D11501, but requested to be committed separately.
Diffstat (limited to 'source/blender/draw')
-rw-r--r--source/blender/draw/engines/overlay/overlay_grid.c9
-rw-r--r--source/blender/draw/intern/draw_manager_data.c8
2 files changed, 14 insertions, 3 deletions
diff --git a/source/blender/draw/engines/overlay/overlay_grid.c b/source/blender/draw/engines/overlay/overlay_grid.c
index 31c8ed9d664..4a551c4dec5 100644
--- a/source/blender/draw/engines/overlay/overlay_grid.c
+++ b/source/blender/draw/engines/overlay/overlay_grid.c
@@ -200,6 +200,15 @@ void OVERLAY_grid_init(OVERLAY_Data *vedata)
shd->grid_distance = dist / 2.0f;
ED_view3d_grid_steps(scene, v3d, rv3d, shd->grid_steps);
+
+ if ((v3d->flag & (V3D_XR_SESSION_SURFACE | V3D_XR_SESSION_MIRROR)) != 0) {
+ /* The calculations for the grid parameters assume that the view matrix has no scale component,
+ * which may not be correct if the user is "shrunk" or "enlarged" by zooming in or out.
+ * Therefore, we need to compensate the values here. */
+ float viewinvscale = len_v3(
+ viewinv[0]); /* Assumption is uniform scaling (all column vectors are of same length). */
+ shd->grid_distance *= viewinvscale;
+ }
}
void OVERLAY_grid_cache_init(OVERLAY_Data *vedata)
diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c
index f96bd474aec..5d3e3db866f 100644
--- a/source/blender/draw/intern/draw_manager_data.c
+++ b/source/blender/draw/intern/draw_manager_data.c
@@ -1684,10 +1684,12 @@ static void draw_frustum_bound_sphere_calc(const BoundBox *bbox,
bsphere->center[0] = farcenter[0] * z / e;
bsphere->center[1] = farcenter[1] * z / e;
bsphere->center[2] = z;
- bsphere->radius = len_v3v3(bsphere->center, farpoint);
- /* Transform to world space. */
- mul_m4_v3(viewinv, bsphere->center);
+ /* For XR, the view matrix may contain a scale factor. Then, transforming only the center
+ * into world space after calculating the radius will result in incorrect behavior. */
+ mul_m4_v3(viewinv, bsphere->center); /* Transform to world space. */
+ mul_m4_v3(viewinv, farpoint);
+ bsphere->radius = len_v3v3(bsphere->center, farpoint);
}
}