Grid: Do not go over objects in front/side ortho views.
Fixes T55190 Grid displayed on top of objects in orthographic view
This commit is contained in:
@@ -289,6 +289,7 @@ enum {
|
|||||||
PLANE_YZ = (1 << 6),
|
PLANE_YZ = (1 << 6),
|
||||||
CLIP_ZPOS = (1 << 7),
|
CLIP_ZPOS = (1 << 7),
|
||||||
CLIP_ZNEG = (1 << 8),
|
CLIP_ZNEG = (1 << 8),
|
||||||
|
GRID_BACK = (1 << 9),
|
||||||
};
|
};
|
||||||
|
|
||||||
/* *********** FUNCTIONS *********** */
|
/* *********** 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_Y;
|
||||||
e_data.grid_flag |= SHOW_AXIS_Z;
|
e_data.grid_flag |= SHOW_AXIS_Z;
|
||||||
e_data.grid_flag |= SHOW_GRID;
|
e_data.grid_flag |= SHOW_GRID;
|
||||||
|
e_data.grid_flag |= GRID_BACK;
|
||||||
}
|
}
|
||||||
else if (ELEM(rv3d->view, RV3D_VIEW_TOP, RV3D_VIEW_BOTTOM)) {
|
else if (ELEM(rv3d->view, RV3D_VIEW_TOP, RV3D_VIEW_BOTTOM)) {
|
||||||
e_data.grid_flag = PLANE_XY;
|
e_data.grid_flag = PLANE_XY;
|
||||||
e_data.grid_flag |= SHOW_AXIS_X;
|
e_data.grid_flag |= SHOW_AXIS_X;
|
||||||
e_data.grid_flag |= SHOW_AXIS_Y;
|
e_data.grid_flag |= SHOW_AXIS_Y;
|
||||||
e_data.grid_flag |= SHOW_GRID;
|
e_data.grid_flag |= SHOW_GRID;
|
||||||
|
e_data.grid_flag |= GRID_BACK;
|
||||||
}
|
}
|
||||||
else if (ELEM(rv3d->view, RV3D_VIEW_FRONT, RV3D_VIEW_BACK)) {
|
else if (ELEM(rv3d->view, RV3D_VIEW_FRONT, RV3D_VIEW_BACK)) {
|
||||||
e_data.grid_flag = PLANE_XZ;
|
e_data.grid_flag = PLANE_XZ;
|
||||||
e_data.grid_flag |= SHOW_AXIS_X;
|
e_data.grid_flag |= SHOW_AXIS_X;
|
||||||
e_data.grid_flag |= SHOW_AXIS_Z;
|
e_data.grid_flag |= SHOW_AXIS_Z;
|
||||||
e_data.grid_flag |= SHOW_GRID;
|
e_data.grid_flag |= SHOW_GRID;
|
||||||
|
e_data.grid_flag |= GRID_BACK;
|
||||||
}
|
}
|
||||||
else { /* RV3D_VIEW_USER */
|
else { /* RV3D_VIEW_USER */
|
||||||
e_data.grid_flag = PLANE_XY;
|
e_data.grid_flag = PLANE_XY;
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ uniform int gridFlag;
|
|||||||
#define PLANE_XY (1 << 4)
|
#define PLANE_XY (1 << 4)
|
||||||
#define PLANE_XZ (1 << 5)
|
#define PLANE_XZ (1 << 5)
|
||||||
#define PLANE_YZ (1 << 6)
|
#define PLANE_YZ (1 << 6)
|
||||||
|
#define GRID_BACK (1 << 9) /* grid is behind objects */
|
||||||
|
|
||||||
#define GRID_LINE_SMOOTH 1.15
|
#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) {
|
if ((gridFlag & GRID) > 0) {
|
||||||
float grid_res = log(dist * gridResolution) * gridOneOverLogSubdiv;
|
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;
|
FragColor.a *= fade;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user