Commit: ffca77814e642f5962481be96deb336ea5f86ff6
Author: Clément Foucault
Date:   Thu May 3 15:43:42 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBffca77814e642f5962481be96deb336ea5f86ff6

DRW: Add plane culling test.

Usefull to see if the view frustum is totally behind a plane.

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

M       source/blender/draw/intern/DRW_render.h
M       source/blender/draw/intern/draw_manager.h
M       source/blender/draw/intern/draw_manager_exec.c

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

diff --git a/source/blender/draw/intern/DRW_render.h 
b/source/blender/draw/intern/DRW_render.h
index c0f5a0df3bf..51fba1500f7 100644
--- a/source/blender/draw/intern/DRW_render.h
+++ b/source/blender/draw/intern/DRW_render.h
@@ -462,6 +462,7 @@ void DRW_state_clip_planes_reset(void);
 /* Culling, return true if object is inside view frustum. */
 bool DRW_culling_sphere_test(BoundSphere *bsphere);
 bool DRW_culling_box_test(BoundBox *bbox);
+bool DRW_culling_plane_test(float plane[4]);
 
 /* Selection */
 void DRW_select_load_id(unsigned int id);
diff --git a/source/blender/draw/intern/draw_manager.h 
b/source/blender/draw/intern/draw_manager.h
index c6c2d5928d8..00d7c7233a5 100644
--- a/source/blender/draw/intern/draw_manager.h
+++ b/source/blender/draw/intern/draw_manager.h
@@ -320,6 +320,7 @@ typedef struct DRWManager {
 
        struct {
                float frustum_planes[6][4];
+               BoundBox frustum_corners;
                BoundSphere frustum_bsphere;
                bool updated;
        } clipping;
diff --git a/source/blender/draw/intern/draw_manager_exec.c 
b/source/blender/draw/intern/draw_manager_exec.c
index a70d80257e6..232ae36438e 100644
--- a/source/blender/draw/intern/draw_manager_exec.c
+++ b/source/blender/draw/intern/draw_manager_exec.c
@@ -461,6 +461,8 @@ static void draw_clipping_setup_from_view(void)
                mul_m4_v3(viewinv, bbox.vec[i]);
        }
 
+       memcpy(&DST.clipping.frustum_corners, &bbox, sizeof(BoundBox));
+
        /* Compute clip planes using the world space frustum corners. */
        for (int p = 0; p < 6; p++) {
                int q, r;
@@ -640,6 +642,22 @@ bool DRW_culling_box_test(BoundBox *bbox)
        return true;
 }
 
+/* Return True if the current view frustum is inside or intersect the given 
plane */
+bool DRW_culling_plane_test(float plane[4])
+{
+       draw_clipping_setup_from_view();
+
+       /* Test against the 8 frustum corners. */
+       for (int c = 0; c < 8; c++) {
+               float dist = plane_point_side_v3(plane, 
DST.clipping.frustum_corners.vec[c]);
+               if (dist < 0.0f) {
+                       return true;
+               }
+       }
+
+       return false;
+}
+
 /** \} */
 
 /* -------------------------------------------------------------------- */

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to