[Bf-blender-cvs] [ff1040c6fef] blender-v2.83-release: GPencil: Reduce aliasing for subpixel lines

Clément Foucault noreply at git.blender.org
Thu May 28 13:48:54 CEST 2020


Commit: ff1040c6fefc4c54fef243635a915edf3f40355a
Author: Clément Foucault
Date:   Thu May 28 13:36:24 2020 +0200
Branches: blender-v2.83-release
https://developer.blender.org/rBff1040c6fefc4c54fef243635a915edf3f40355a

GPencil: Reduce aliasing for subpixel lines

===================================================================

M	source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl

===================================================================

diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl
index fb5073b3dc7..1e75f6dd5bb 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_common_lib.glsl
@@ -317,7 +317,7 @@ vec2 safe_normalize_len(vec2 v, out float len)
   }
 }
 
-float stroke_thickness_modulate(float thickness)
+float stroke_thickness_modulate(float thickness, out float opacity)
 {
   /* Modify stroke thickness by object and layer factors.-*/
   thickness *= thicknessScale;
@@ -333,6 +333,11 @@ float stroke_thickness_modulate(float thickness)
     /* World space point size. */
     thickness *= thicknessWorldScale * ProjectionMatrix[1][1] * sizeViewport.y;
   }
+  /* To avoid aliasing artifact, we clamp the line thickness and reduce its opacity. */
+  float min_thickness = gl_Position.w * 1.3;
+  opacity = smoothstep(0.0, gl_Position.w * 1.0, thickness);
+  thickness = max(min_thickness, thickness);
+
   return thickness;
 }
 
@@ -414,8 +419,9 @@ void stroke_vertex()
   vec2 line = safe_normalize_len(ss2 - ss1, line_len);
   vec2 line_adj = safe_normalize((use_curr) ? (ss1 - ss_adj) : (ss_adj - ss2));
 
+  float small_line_opacity;
   float thickness = abs((use_curr) ? thickness1 : thickness2);
-  thickness = stroke_thickness_modulate(thickness);
+  thickness = stroke_thickness_modulate(thickness, small_line_opacity);
 
   finalUvs = vec2(x, y) * 0.5 + 0.5;
   strokeHardeness = decode_hardness(use_curr ? hardness1 : hardness2);
@@ -505,7 +511,7 @@ void stroke_vertex()
   vec4 stroke_col = MATERIAL(m).stroke_color;
   float mix_tex = MATERIAL(m).stroke_texture_mix;
 
-  color_output(stroke_col, vert_col, vert_strength, mix_tex);
+  color_output(stroke_col, vert_col, vert_strength * small_line_opacity, mix_tex);
 
   matFlag = MATERIAL(m).flag & ~GP_FILL_FLAGS;
 #  endif



More information about the Bf-blender-cvs mailing list