Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2019-12-03 03:51:57 +0300
committerClément Foucault <foucault.clem@gmail.com>2019-12-03 03:53:27 +0300
commita81fdefddebc0eec3e324cf6a9d8c51050d3e749 (patch)
tree6020a3ec1c9e8afe0de3837b7c5a4c5e2e731c9e /source
parent37cd7b25dc87d53ee68dde3c9cf0809e200a26fd (diff)
Overlay: Wireframe: Improve Z-fighting / missing information stippling
To do this we do a half pixel offset in the normal direction. However, we use the shading vertex normal instead of the geometric normal (for speed) and this leads to imprecisions. So we try to mitigate the common case and leave the corner cases as is.
Diffstat (limited to 'source')
-rw-r--r--source/blender/draw/engines/overlay/shaders/wireframe_vert.glsl19
1 files changed, 17 insertions, 2 deletions
diff --git a/source/blender/draw/engines/overlay/shaders/wireframe_vert.glsl b/source/blender/draw/engines/overlay/shaders/wireframe_vert.glsl
index 16fdf2687fa..21f8bcf1791 100644
--- a/source/blender/draw/engines/overlay/shaders/wireframe_vert.glsl
+++ b/source/blender/draw/engines/overlay/shaders/wireframe_vert.glsl
@@ -102,8 +102,25 @@ void wire_object_color_get(out vec3 rim_col, out vec3 wire_col)
void main()
{
vec3 wpos = point_object_to_world(pos);
+ vec3 wnor = normalize(normal_object_to_world(nor));
+
+ bool is_persp = (ProjectionMatrix[3][3] == 0.0);
+ vec3 V = (is_persp) ? normalize(ViewMatrixInverse[3].xyz - wpos) : ViewMatrix[2].xyz;
+
+ float facing = dot(wnor, V);
+ float facing_ratio = clamp(1.0 - facing * facing, 0.0, 1.0);
+ float flip = sign(facing); /* Flip when not facing the normal (i.e.: backfacing). */
+ float curvature = (1.0 - wd * 0.75); /* Avoid making things worse for curvy areas. */
+ vec3 wofs = wnor * (facing_ratio * curvature * flip);
+ wofs = normal_world_to_view(wofs);
+
gl_Position = point_world_to_ndc(wpos);
+ /* Push vertex half a pixel (maximum) in normal direction. */
+ gl_Position.xy += wofs.xy * sizeViewportInv.xy * gl_Position.w;
+
+ /* Push the vertex towards the camera. Helps a bit. */
+ gl_Position.z -= facing_ratio * curvature * 1e-4;
/* Convert to screen position [0..sizeVp]. */
edgeStart = ((gl_Position.xy / gl_Position.w) * 0.5 + 0.5) * sizeViewport.xy;
@@ -119,8 +136,6 @@ void main()
wire_color_get(rim_col, wire_col);
}
- vec3 wnor = normalize(normal_object_to_world(nor));
- float facing = dot(wnor, ViewMatrixInverse[2].xyz);
facing = clamp(abs(facing), 0.0, 1.0);
vec3 final_front_col = mix(rim_col, wire_col, 0.4);