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-04-22 23:49:36 +0300
committerClément Foucault <foucault.clem@gmail.com>2018-05-02 21:49:38 +0300
commite493a1a1aedcd6bc00f0f016aa6ef707742e3825 (patch)
treee479cb1f54c0029e92446dc6b0cfc263fe1bfb56 /source/blender/draw/modes/shaders/armature_shape_outline_vert.glsl
parent77b481fd5ae2e8b503aed714ae3335ba637c84b6 (diff)
DRW: Armature: New bone outline shader.
This fix the issue with the zfighting we were getting at bones edges. Moreover, this enables us to render arbitrarly large outline with varying thickness.
Diffstat (limited to 'source/blender/draw/modes/shaders/armature_shape_outline_vert.glsl')
-rw-r--r--source/blender/draw/modes/shaders/armature_shape_outline_vert.glsl53
1 files changed, 53 insertions, 0 deletions
diff --git a/source/blender/draw/modes/shaders/armature_shape_outline_vert.glsl b/source/blender/draw/modes/shaders/armature_shape_outline_vert.glsl
new file mode 100644
index 00000000000..2bfac594493
--- /dev/null
+++ b/source/blender/draw/modes/shaders/armature_shape_outline_vert.glsl
@@ -0,0 +1,53 @@
+
+uniform mat3 NormalMatrix;
+
+uniform mat4 ViewMatrix;
+uniform mat4 ProjectionMatrix;
+uniform vec2 viewportSize;
+
+/* ---- Instanciated Attribs ---- */
+in vec3 pos;
+in vec3 nor;
+in vec3 snor;
+
+/* ---- Per instance Attribs ---- */
+in mat4 InstanceModelMatrix;
+in vec4 color;
+
+out vec4 pPos;
+out float vZ;
+out float vFacing;
+out vec2 ssPos;
+out vec2 ssNor;
+out vec4 vCol;
+
+/* project to screen space */
+vec2 proj(vec4 pos)
+{
+ return (0.5 * (pos.xy / pos.w) + 0.5) * viewportSize;
+}
+
+void main()
+{
+ /* This is slow and run per vertex, but it's still faster than
+ * doing it per instance on CPU and sending it on via instance attrib */
+ mat3 NormalMatrix = transpose(inverse(mat3(ViewMatrix * InstanceModelMatrix)));
+
+ vec4 viewpos = ViewMatrix * (InstanceModelMatrix * vec4(pos, 1.0));
+ pPos = ProjectionMatrix * viewpos;
+ vZ = abs(viewpos.z);
+
+ /* if perspective */
+ vec3 V = (ProjectionMatrix[3][3] == 0.0) ? normalize(-viewpos.xyz) : vec3(0.0, 0.0, 1.0);
+
+ /* TODO FIX: there is still a problem with this vector
+ * when the bone is scaled or in persp mode. But it's
+ * barelly visible at the outline corners. */
+ ssNor = normalize((NormalMatrix * snor).xy);
+
+ vFacing = dot(V, normalize(NormalMatrix * nor));
+
+ ssPos = proj(pPos);
+
+ vCol = color;
+}