Fix T70193 Overlay: Grid floor disappears for orthographic camera

The fix is to disable the fading for in the +Z direction in this case.
This commit is contained in:
Clément Foucault
2020-06-25 18:01:35 +02:00
parent 47ff54b008
commit 230b9eac69
2 changed files with 9 additions and 2 deletions

View File

@@ -41,6 +41,7 @@ enum {
CLIP_ZPOS = (1 << 7),
CLIP_ZNEG = (1 << 8),
GRID_BACK = (1 << 9),
GRID_CAMERA = (1 << 10),
};
void OVERLAY_grid_init(OVERLAY_Data *vedata)
@@ -145,6 +146,9 @@ void OVERLAY_grid_init(OVERLAY_Data *vedata)
if (rv3d->persp == RV3D_CAMOB && v3d->camera && v3d->camera->type == OB_CAMERA) {
Object *camera_object = DEG_get_evaluated_object(draw_ctx->depsgraph, v3d->camera);
dist = ((Camera *)(camera_object->data))->clip_end;
shd->grid_flag |= GRID_CAMERA;
shd->zneg_flag |= GRID_CAMERA;
shd->zpos_flag |= GRID_CAMERA;
}
else {
dist = v3d->clip_end;

View File

@@ -28,7 +28,8 @@ uniform float gridSteps[STEPS_LEN] = float[](0.001, 0.01, 0.1, 1.0, 10.0, 100.0,
#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_BACK (1 << 9) /* grid is behind objects */
#define GRID_CAMERA (1 << 10) /* In camera view */
#define M_1_SQRTPI 0.5641895835477563 /* 1/sqrt(pi) */
@@ -104,7 +105,9 @@ void main()
fade *= 1.0 - smoothstep(0.0, gridDistance, dist - gridDistance);
}
else {
dist = abs(gl_FragCoord.z * 2.0 - 1.0);
dist = gl_FragCoord.z * 2.0 - 1.0;
/* Avoid fading in +Z direction in camera view (see T70193). */
dist = ((gridFlag & GRID_CAMERA) != 0) ? clamp(dist, 0.0, 1.0) : abs(dist);
fade = 1.0 - smoothstep(0.0, 0.5, dist - 0.5);
dist = 1.0; /* avoid branch after */