Commit: 4ca4e64d25f69eb4cbb96084fb688b69484e1507
Author: Clément Foucault
Date:   Sun May 27 11:25:29 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB4ca4e64d25f69eb4cbb96084fb688b69484e1507

Grid: Do not go over objects in front/side ortho views.

Fixes T55190 Grid displayed on top of objects in orthographic view

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

M       source/blender/draw/modes/object_mode.c
M       source/blender/draw/modes/shaders/object_grid_frag.glsl

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

diff --git a/source/blender/draw/modes/object_mode.c 
b/source/blender/draw/modes/object_mode.c
index fcc0e0f20a5..52749a5429f 100644
--- a/source/blender/draw/modes/object_mode.c
+++ b/source/blender/draw/modes/object_mode.c
@@ -289,6 +289,7 @@ enum {
        PLANE_YZ     = (1 << 6),
        CLIP_ZPOS    = (1 << 7),
        CLIP_ZNEG    = (1 << 8),
+       GRID_BACK    = (1 << 9),
 };
 
 /* *********** FUNCTIONS *********** */
@@ -447,18 +448,21 @@ static void OBJECT_engine_init(void *vedata)
                                e_data.grid_flag |= SHOW_AXIS_Y;
                                e_data.grid_flag |= SHOW_AXIS_Z;
                                e_data.grid_flag |= SHOW_GRID;
+                               e_data.grid_flag |= GRID_BACK;
                        }
                        else if (ELEM(rv3d->view, RV3D_VIEW_TOP, 
RV3D_VIEW_BOTTOM)) {
                                e_data.grid_flag = PLANE_XY;
                                e_data.grid_flag |= SHOW_AXIS_X;
                                e_data.grid_flag |= SHOW_AXIS_Y;
                                e_data.grid_flag |= SHOW_GRID;
+                               e_data.grid_flag |= GRID_BACK;
                        }
                        else if (ELEM(rv3d->view, RV3D_VIEW_FRONT, 
RV3D_VIEW_BACK)) {
                                e_data.grid_flag = PLANE_XZ;
                                e_data.grid_flag |= SHOW_AXIS_X;
                                e_data.grid_flag |= SHOW_AXIS_Z;
                                e_data.grid_flag |= SHOW_GRID;
+                               e_data.grid_flag |= GRID_BACK;
                        }
                        else { /* RV3D_VIEW_USER */
                                e_data.grid_flag = PLANE_XY;
diff --git a/source/blender/draw/modes/shaders/object_grid_frag.glsl 
b/source/blender/draw/modes/shaders/object_grid_frag.glsl
index 2d0d637fc45..2b04bb0d855 100644
--- a/source/blender/draw/modes/shaders/object_grid_frag.glsl
+++ b/source/blender/draw/modes/shaders/object_grid_frag.glsl
@@ -29,6 +29,7 @@ uniform int gridFlag;
 #define PLANE_XY  (1 << 4)
 #define PLANE_XZ  (1 << 5)
 #define PLANE_YZ  (1 << 6)
+#define GRID_BACK (1 << 9) /* grid is behind objects */
 
 #define GRID_LINE_SMOOTH 1.15
 
@@ -137,18 +138,6 @@ void main()
                }
        }
 
-       /* Manual, non hard, depth test:
-        * Progressively fade the grid below occluders
-        * (avoids poping visuals due to depth buffer precision) */
-       float scene_depth = texture(depthBuffer, sPos).r;
-       /* Add a small bias so the grid will always
-        * be on top of a mesh with the same depth. */
-       float grid_depth = gl_FragCoord.z - 1e-8;
-       /* Harder settings tend to flicker more,
-        * but have less "see through" appearance. */
-       const float test_hardness = 1e4;
-       fade *= 1.0 - clamp((grid_depth - scene_depth) * test_hardness, 0.0, 
1.0);
-
        if ((gridFlag & GRID) > 0) {
                float grid_res = log(dist * gridResolution) * 
gridOneOverLogSubdiv;
 
@@ -217,5 +206,22 @@ void main()
                }
        }
 
+       float scene_depth = texture(depthBuffer, sPos).r;
+       if ((gridFlag & GRID_BACK) > 0) {
+               fade *= (scene_depth == 1.0) ? 1.0 : 0.0;
+       }
+       else {
+               /* Manual, non hard, depth test:
+                * Progressively fade the grid below occluders
+                * (avoids poping visuals due to depth buffer precision) */
+               /* Add a small bias so the grid will always
+                * be on top of a mesh with the same depth. */
+               float grid_depth = gl_FragCoord.z - 1e-8;
+               /* Harder settings tend to flicker more,
+                * but have less "see through" appearance. */
+               const float test_hardness = 1e4;
+               fade *= 1.0 - clamp((grid_depth - scene_depth) * test_hardness, 
0.0, 1.0);
+       }
+
        FragColor.a *= fade;
 }

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

Reply via email to