[Bf-blender-cvs] [e87804f2ba5] greasepencil-refactor: GPencil: Refactor: Implement Miter corner logic
Clément Foucault
noreply at git.blender.org
Mon Dec 9 02:30:41 CET 2019
Commit: e87804f2ba597ad7b600469be16f030056536676
Author: Clément Foucault
Date: Sun Dec 8 15:14:57 2019 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rBe87804f2ba597ad7b600469be16f030056536676
GPencil: Refactor: Implement Miter corner logic
Not 100% complete, needs to fix the "corner" cases.
===================================================================
M source/blender/draw/engines/gpencil/shaders/gpencil_vert.glsl
===================================================================
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_vert.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_vert.glsl
index cd7b520a2c2..e65bf8d8298 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_vert.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_vert.glsl
@@ -23,39 +23,70 @@ vec2 project_to_screenspace(vec4 v)
return ((v.xy / v.w) * 0.5 + 0.5) * sizeViewport;
}
-void main()
+vec2 rotate_90deg(vec2 v)
{
- /* Trick to detect if a drawcall is stroke or fill. */
- bool is_fill = (gl_InstanceID == 0);
+ /* Counter Clock-Wise. */
+ return vec2(-v.y, v.x);
+}
- if (!is_fill) {
- /* Enpoints, we discard the vertices. */
- if (ma1 == -1 || ma2 == -1) {
- discard_vert();
- return;
- }
+void stroke_vertex()
+{
+ /* Enpoints, we discard the vertices. */
+ if (ma1 == -1 || ma2 == -1) {
+ discard_vert();
+ return;
+ }
+
+ /* Avoid using a vertex attrib for quad positioning. */
+ float x = float((gl_VertexID & 1));
+ float y = float((gl_VertexID & 2) >> 1);
+
+ vec3 pos_adj = (x == 0.0) ? pos : pos3;
+ vec4 ndc_adj = point_world_to_ndc(pos_adj);
+ vec4 ndc1 = point_world_to_ndc(pos1);
+ vec4 ndc2 = point_world_to_ndc(pos2);
+
+ /* TODO case where ndc1 & ndc2 is behind camera */
+ vec2 ss_adj = project_to_screenspace(ndc_adj);
+ vec2 ss1 = project_to_screenspace(ndc1);
+ vec2 ss2 = project_to_screenspace(ndc2);
+ /* Screenspace Lines tangents. */
+ vec2 line = normalize(ss2 - ss1);
+ vec2 line_adj = normalize((x == 0.0) ? (ss1 - ss_adj) : (ss_adj - ss2));
+ /* Mitter tangent vector. */
+ vec2 miter_tan = normalize(line_adj + line);
+ float miter_dot = dot(miter_tan, line_adj);
+
+ vec2 miter = rotate_90deg(miter_tan / miter_dot);
+
+ gl_Position = (x == 0.0) ? ndc1 : ndc2;
+ gl_Position.xy += miter * (y - 0.5) * sizeViewportInv.xy * gl_Position.w * 10.0;
- /* Avoid using a vertex attrib for quad positioning. */
- float x = float((gl_VertexID & 1));
- float y = float((gl_VertexID & 2) >> 1);
+ finalColor = vec4(0.0, 0.0, 0.0, 1.0);
+}
+
+void dots_vertex()
+{
+ /* TODO */
+}
- vec4 ndc1 = point_world_to_ndc(pos1);
- vec4 ndc2 = point_world_to_ndc(pos2);
+void fill_vertex()
+{
+ gl_Position = point_world_to_ndc(pos1);
+ gl_Position.z += 1e-2;
- /* TODO case where ndc2 is behind camera */
- vec2 ss1 = project_to_screenspace(ndc1);
- vec2 ss2 = project_to_screenspace(ndc2);
- vec2 perp = normalize(ss2 - ss1);
- perp = vec2(-perp.y, perp.x);
+ finalColor = vec4(1.0);
+}
- gl_Position = (x == 0.0) ? ndc1 : ndc2;
- gl_Position.xy += perp * (y - 0.5) * sizeViewportInv.xy * gl_Position.w * 10.0;
+void main()
+{
+ /* Trick to detect if a drawcall is stroke or fill. */
+ bool is_fill = (gl_InstanceID == 0);
- finalColor = vec4(0.0, 0.0, 0.0, 1.0);
+ if (!is_fill) {
+ stroke_vertex();
}
else {
- gl_Position = point_world_to_ndc(pos1);
-
- finalColor = vec4(1.0);
+ fill_vertex();
}
}
More information about the Bf-blender-cvs
mailing list