Wireframe: Optimization: Output degenerate triangles if no edges
authorClément Foucault <foucault.clem@gmail.com>
Tue, 4 Dec 2018 00:16:13 +0000 (01:16 +0100)
committerClément Foucault <foucault.clem@gmail.com>
Tue, 4 Dec 2018 16:52:32 +0000 (17:52 +0100)
source/blender/draw/modes/shaders/overlay_face_wireframe_geom.glsl
source/blender/draw/modes/shaders/overlay_face_wireframe_vert.glsl

index 8abb6ecc737d4a0a9bde9bb656c56482ec3f4ca5..e0ec9563ef4b43ea8896194db8855d30a30aa220 100644 (file)
@@ -80,6 +80,12 @@ void main(void)
        edgeSharpness.x = (forceEdge[0] == 1.0) ? 1.0 : edgeSharpness.x;
        edgeSharpness.y = (forceEdge[1] == 1.0) ? 1.0 : edgeSharpness.y;
        edgeSharpness.z = (forceEdge[2] == 1.0) ? 1.0 : edgeSharpness.z;
+
+       do_edge = greaterThan(edgeSharpness, vec3(0.005));
+       if (!any(do_edge)) {
+               /* Don't generate any fragment. */
+               return;
+       }
 #endif
 
 #ifdef SELECT_EDGES
index 828bc551cad356d9cb97d1e186d7f56d81dcdf96..ca077f29abda29b269d77a29947b822401844359 100644 (file)
@@ -145,8 +145,6 @@ void main()
 #  ifndef LIGHT_EDGES
        vec3 nor = get_vertex_nor(v_id[v_n]);
 #  else
-       p_pos[v_n1] = ModelViewProjectionMatrix * vec4(pos[v_n1], 1.0);
-       p_pos[v_n2] = ModelViewProjectionMatrix * vec4(pos[v_n2], 1.0);
 
        pos[v_n1] = get_vertex_pos(v_id[v_n1]);
        pos[v_n2] = get_vertex_pos(v_id[v_n2]);
@@ -168,6 +166,12 @@ void main()
        edgeSharpness.y = force_edge.y ? 1.0 : edgeSharpness.y;
        edgeSharpness.z = force_edge.z ? 1.0 : edgeSharpness.z;
 
+       do_edge = greaterThan(edgeSharpness, vec3(0.01));
+       if (!any(do_edge)) {
+               /* Don't generate any fragment. */
+               gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
+       }
+
        vec3 nor = nors[v_n];
 #  endif