diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2020-04-24 00:08:20 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2020-04-24 00:08:20 +0300 |
commit | 826f6dd9ee20332585f808a41c487c94a590265f (patch) | |
tree | 8ad92e3c3a58e58904c8f19186c54a6be09590ce /source/blender/draw | |
parent | ed4f33a7bd3ed185f9b863a92673b3319c1890fe (diff) | |
parent | d712f1f83af881be536ec0d183b7d3025c172684 (diff) |
Merge branch 'blender-v2.83-release'
Diffstat (limited to 'source/blender/draw')
-rw-r--r-- | source/blender/draw/engines/overlay/overlay_extra.c | 4 | ||||
-rw-r--r-- | source/blender/draw/engines/overlay/shaders/grid_frag.glsl | 9 |
2 files changed, 8 insertions, 5 deletions
diff --git a/source/blender/draw/engines/overlay/overlay_extra.c b/source/blender/draw/engines/overlay/overlay_extra.c index 566c8cad528..32085890f20 100644 --- a/source/blender/draw/engines/overlay/overlay_extra.c +++ b/source/blender/draw/engines/overlay/overlay_extra.c @@ -1160,6 +1160,10 @@ void OVERLAY_camera_cache_populate(OVERLAY_Data *vedata, Object *ob) } else { copy_v3_fl3(scale, len_v3(ob->obmat[0]), len_v3(ob->obmat[1]), len_v3(ob->obmat[2])); + /* Avoid division by 0. */ + if (ELEM(0.0f, scale[0], scale[1], scale[2])) { + return; + } invert_v3(scale); } diff --git a/source/blender/draw/engines/overlay/shaders/grid_frag.glsl b/source/blender/draw/engines/overlay/shaders/grid_frag.glsl index db845c7f1dd..9743f918ce3 100644 --- a/source/blender/draw/engines/overlay/shaders/grid_frag.glsl +++ b/source/blender/draw/engines/overlay/shaders/grid_frag.glsl @@ -227,21 +227,20 @@ void main() } } - /* 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 - 6e-8 - fwidth(gl_FragCoord.z); float scene_depth = texelFetch(depthBuffer, ivec2(gl_FragCoord.xy), 0).r; if ((gridFlag & GRID_BACK) != 0) { fade *= (scene_depth == 1.0) ? 1.0 : 0.0; } else { + /* Add a small bias so the grid will always be below of a mesh with the same depth. */ + float grid_depth = gl_FragCoord.z + 4.8e-7; /* Manual, non hard, depth test: * Progressively fade the grid below occluders * (avoids popping visuals due to depth buffer precision) */ /* Harder settings tend to flicker more, * but have less "see through" appearance. */ - const float test_hardness = 1e7; - fade *= 1.0 - clamp((grid_depth - scene_depth) * test_hardness, 0.0, 1.0); + float bias = max(fwidth(gl_FragCoord.z), 2.4e-7); + fade *= linearstep(grid_depth, grid_depth + bias, scene_depth); } FragColor.a *= fade; |