Commit: b31ebd8c5c5554561f43202c8a377e85d0aceca9
Author: Germano
Date:   Mon Apr 16 09:22:42 2018 -0300
Branches: blender2.8
https://developer.blender.org/rBb31ebd8c5c5554561f43202c8a377e85d0aceca9

Fix T54609: Erros in precise BBox extraction algorithm

===================================================================

M       source/blender/draw/intern/draw_manager_exec.c

===================================================================

diff --git a/source/blender/draw/intern/draw_manager_exec.c 
b/source/blender/draw/intern/draw_manager_exec.c
index 6021863c690..2a5a595c682 100644
--- a/source/blender/draw/intern/draw_manager_exec.c
+++ b/source/blender/draw/intern/draw_manager_exec.c
@@ -386,11 +386,10 @@ void DRW_state_clip_planes_reset(void)
 
 /* Extract the 8 corners (world space).
  * Although less accurate, this solution can be simplified as follows:
- *
  * BKE_boundbox_init_from_minmax(&bbox, (const float[3]){-1.0f, -1.0f, -1.0f}, 
(const float[3]){1.0f, 1.0f, 1.0f});
  * for (int i = 0; i < 8; i++) {mul_project_m4_v3(viewprojinv, bbox.vec[i]);}
  */
-static void UNUSED_FUNCTION(draw_frustum_boundbox_calc)(
+static void draw_frustum_boundbox_calc(
         const float (*projmat)[4], const float (*viewinv)[4], BoundBox *r_bbox)
 {
        float screenvecs[3][3], loc[3], near, far, w_half, h_half;
@@ -426,8 +425,8 @@ static void UNUSED_FUNCTION(draw_frustum_boundbox_calc)(
                madd_v3_v3fl(mid, ver, projmat[2][1]);
        }
        else {
-               madd_v3_v3fl(mid, hor, projmat[3][0]);
-               madd_v3_v3fl(mid, ver, projmat[3][1]);
+               madd_v3_v3fl(mid, hor, -projmat[3][0]);
+               madd_v3_v3fl(mid, ver, -projmat[3][1]);
        }
 
        r_bbox->vec[0][0] = mid[0] - ver[0] - hor[0];
@@ -460,8 +459,8 @@ static void UNUSED_FUNCTION(draw_frustum_boundbox_calc)(
                madd_v3_v3v3fl(mid, loc, screenvecs[2], -far);
 
                /* Non-symmetric frustum. */
-               madd_v3_v3fl(mid, hor, projmat[3][0]);
-               madd_v3_v3fl(mid, ver, projmat[3][1]);
+               madd_v3_v3fl(mid, hor, -projmat[3][0]);
+               madd_v3_v3fl(mid, ver, -projmat[3][1]);
        }
 
        r_bbox->vec[1][0] = mid[0] - ver[0] - hor[0];
@@ -493,13 +492,13 @@ static void draw_clipping_setup_from_view(void)
 
        /* Extract Clipping Planes */
        BoundBox bbox;
-#if 0 /* does not currently work for all casses. */
-       draw_frustum_boundbox_calc(projmat, viewinv, &bbox);
-#else
+#if 0 /* It has accuracy problems. */
        BKE_boundbox_init_from_minmax(&bbox, (const float[3]){-1.0f, -1.0f, 
-1.0f}, (const float[3]){1.0f, 1.0f, 1.0f});
        for (int i = 0; i < 8; i++) {
                mul_project_m4_v3(DST.view_data.matstate.mat[DRW_MAT_PERSINV], 
bbox.vec[i]);
        }
+#else
+       draw_frustum_boundbox_calc(projmat, viewinv, &bbox);
 #endif
 
        /* Compute clip planes using the world space frustum corners. */

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to