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
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2018-10-12 16:09:43 +0300
committerClément Foucault <foucault.clem@gmail.com>2018-10-12 17:43:40 +0300
commit03d0219d7ae5916500a45b157bd7a637310ef494 (patch)
treecf8da7335316267ab5141c466c6db27f06deaa06 /source/blender/draw/modes/shaders/edit_mesh_overlay_vert.glsl
parentfe4840ed4d7bc002586c5f11d04558edfdf996fe (diff)
Edit Mesh: Refactor edit mesh drawing
This decouple the vertex display from the face+edges. This is to reduce the number of triangles required to fix the edges artifacts (aliasing) and increase viewport reactivity when not actively navigating (ie. mouse scroll). Also it makes all vertices visible (not cut-off) even when navigating. However it makes the navigation drawing a bit slower because it has to render twice. Also add a depth bias to the wires to avoid depth fighting when previewing final mesh (modifiers applied).
Diffstat (limited to 'source/blender/draw/modes/shaders/edit_mesh_overlay_vert.glsl')
-rw-r--r--source/blender/draw/modes/shaders/edit_mesh_overlay_vert.glsl89
1 files changed, 77 insertions, 12 deletions
diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_vert.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_vert.glsl
index 7cab2a5035f..8715ab69181 100644
--- a/source/blender/draw/modes/shaders/edit_mesh_overlay_vert.glsl
+++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_vert.glsl
@@ -2,38 +2,103 @@
/* Solid Wirefram implementation
* Mike Erwin, Clément Foucault */
-/* This shader follows the principles of
- * http://developer.download.nvidia.com/SDK/10/direct3d/Source/SolidWireframe/Doc/SolidWireframe.pdf */
-
+uniform mat3 NormalMatrix;
+uniform mat4 ProjectionMatrix;
uniform mat4 ModelViewMatrix;
uniform mat4 ModelViewProjectionMatrix;
uniform ivec4 dataMask = ivec4(0xFF);
+uniform float ofs = 1e-5;
+
+uniform isamplerBuffer dataBuffer;
+
in vec3 pos;
+#ifdef VERTEX_FACING
+in vec3 vnor;
+#endif
+
+#ifdef EDGE_FIX
in ivec4 data;
out vec4 vPos;
out vec4 pPos;
out ivec4 vData;
-
-#ifdef VERTEX_FACING
-uniform mat4 ProjectionMatrix;
-uniform mat3 NormalMatrix;
-
-in vec3 vnor;
+# ifdef VERTEX_FACING
out float vFacing;
-#endif
+# endif
void main()
{
vPos = ModelViewMatrix * vec4(pos, 1.0);
pPos = ModelViewProjectionMatrix * vec4(pos, 1.0);
+ pPos.z -= ofs;
vData = data & dataMask;
-#ifdef VERTEX_FACING
+# ifdef VERTEX_FACING
vec3 view_normal = normalize(NormalMatrix * vnor);
vec3 view_vec = (ProjectionMatrix[3][3] == 0.0)
? normalize(vPos.xyz)
: vec3(0.0, 0.0, 1.0);
vFacing = dot(view_vec, view_normal);
-#endif
+# endif
}
+
+#else /* EDGE_FIX */
+
+flat out vec3 edgesCrease;
+flat out vec3 edgesBweight;
+flat out vec4 faceColor;
+flat out ivec3 flag;
+# ifdef VERTEX_SELECTION
+out vec3 vertexColor;
+# endif
+# ifdef VERTEX_FACING
+out float facing;
+# endif
+
+out vec3 barycentric;
+
+void main()
+{
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+ gl_Position.z -= ofs;
+
+ int v_0 = (gl_VertexID / 3) * 3;
+ int vidx = gl_VertexID % 3;
+ barycentric = vec3(0.0);
+ barycentric[vidx] = 1.0;
+
+ /* Edge */
+ ivec4 vData[3], data = ivec4(0);
+ ivec3 eflag;
+ for (int v = 0; v < 3; ++v) {
+ data = texelFetch(dataBuffer, v_0 + v);
+ vData[v] = data & dataMask;
+ flag[v] = eflag[v] = vData[v].y | (vData[v].x << 8);
+ edgesCrease[v] = vData[v].z / 255.0;
+ edgesBweight[v] = vData[v].w / 255.0;
+ }
+
+ /* Face */
+ if ((vData[0].x & FACE_ACTIVE) != 0)
+ faceColor = colorFaceSelect;
+ else if ((vData[0].x & FACE_SELECTED) != 0)
+ faceColor = colorFaceSelect;
+ else if ((vData[0].x & FACE_FREESTYLE) != 0)
+ faceColor = colorFaceFreestyle;
+ else
+ faceColor = colorFace;
+
+# ifdef VERTEX_SELECTION
+ vertexColor = EDIT_MESH_vertex_color(vData[vidx].x).rgb;
+# endif
+# ifdef VERTEX_FACING
+ vec4 vPos = ModelViewMatrix * vec4(pos, 1.0);
+ vec3 view_normal = normalize(NormalMatrix * vnor);
+ vec3 view_vec = (ProjectionMatrix[3][3] == 0.0)
+ ? normalize(vPos.xyz)
+ : vec3(0.0, 0.0, 1.0);
+ facing = dot(view_vec, view_normal);
+# endif
+}
+
+#endif \ No newline at end of file