[Bf-blender-cvs] [97923d9b989] master: GPencil: glow fx, add threshold value color mode

Falk David noreply at git.blender.org
Thu Apr 29 16:50:38 CEST 2021


Commit: 97923d9b9892b422cfd4c5a795258a34e44c09e8
Author: Falk David
Date:   Thu Apr 29 16:49:57 2021 +0200
Branches: master
https://developer.blender.org/rB97923d9b9892b422cfd4c5a795258a34e44c09e8

GPencil: glow fx, add threshold value color mode

This patch adds a threshold value to the glow effect in color mode.
Currently, the threshold is hardcoded to 5%.
You can select a color and specify a higher threshold to include
similar colors in the effect.

Note: depends on D10670

Reviewed By: #grease_pencil, pepeland

Differential Revision: https://developer.blender.org/D10672

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

M	source/blender/draw/engines/gpencil/gpencil_shader_fx.c
M	source/blender/draw/engines/gpencil/shaders/gpencil_vfx_frag.glsl
M	source/blender/shader_fx/intern/FX_shader_glow.c

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

diff --git a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
index 0b66141e51a..ab90831f4ac 100644
--- a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
+++ b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
@@ -424,22 +424,26 @@ static void gpencil_vfx_glow(GlowShaderFxData *fx, Object *UNUSED(ob), gpIterVfx
 
   GPUShader *sh = GPENCIL_shader_fx_glow_get();
 
-  float ref_col[3];
+  float ref_col[4];
 
   if (fx->mode == eShaderFxGlowMode_Luminance) {
+    /* Only pass in the first value for luminace. */
     ref_col[0] = fx->threshold;
     ref_col[1] = -1.0f;
     ref_col[2] = -1.0f;
+    ref_col[3] = -1.0f;
   }
   else {
+    /* First three values are the RGB for the selected color, last value the threshold. */
     copy_v3_v3(ref_col, fx->select_color);
+    ref_col[3] = fx->threshold;
   }
 
   DRWState state = DRW_STATE_WRITE_COLOR;
   grp = gpencil_vfx_pass_create("Fx Glow H", state, iter, sh);
   DRW_shgroup_uniform_vec2_copy(grp, "offset", (float[2]){fx->blur[0] * c, fx->blur[0] * s});
   DRW_shgroup_uniform_int_copy(grp, "sampCount", max_ii(1, min_ii(fx->samples, fx->blur[0])));
-  DRW_shgroup_uniform_vec3_copy(grp, "threshold", ref_col);
+  DRW_shgroup_uniform_vec4_copy(grp, "threshold", ref_col);
   DRW_shgroup_uniform_vec4_copy(grp, "glowColor", fx->glow_color);
   DRW_shgroup_uniform_bool_copy(grp, "glowUnder", use_glow_under);
   DRW_shgroup_uniform_bool_copy(grp, "firstPass", true);
@@ -473,7 +477,7 @@ static void gpencil_vfx_glow(GlowShaderFxData *fx, Object *UNUSED(ob), gpIterVfx
   grp = gpencil_vfx_pass_create("Fx Glow V", state, iter, sh);
   DRW_shgroup_uniform_vec2_copy(grp, "offset", (float[2]){-fx->blur[1] * s, fx->blur[1] * c});
   DRW_shgroup_uniform_int_copy(grp, "sampCount", max_ii(1, min_ii(fx->samples, fx->blur[0])));
-  DRW_shgroup_uniform_vec3_copy(grp, "threshold", (float[3]){-1.0f, -1.0f, -1.0f});
+  DRW_shgroup_uniform_vec4_copy(grp, "threshold", (float[4]){-1.0f, -1.0f, -1.0f, -1.0});
   DRW_shgroup_uniform_vec4_copy(grp, "glowColor", (float[4]){1.0f, 1.0f, 1.0f, fx->glow_color[3]});
   DRW_shgroup_uniform_bool_copy(grp, "firstPass", false);
   DRW_shgroup_uniform_int_copy(grp, "blendMode", fx->blend_mode);
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_vfx_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_vfx_frag.glsl
index bb905f8694b..269ed49c4d0 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_vfx_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_vfx_frag.glsl
@@ -145,7 +145,7 @@ void main()
 uniform vec4 glowColor;
 uniform vec2 offset;
 uniform int sampCount;
-uniform vec3 threshold;
+uniform vec4 threshold;
 uniform bool firstPass;
 uniform bool glowUnder;
 uniform int blendMode;
@@ -168,7 +168,7 @@ void main()
     vec3 rev = texture(revealBuf, uv).rgb;
     if (threshold.x > -1.0) {
       if (threshold.y > -1.0) {
-        if (any(greaterThan(abs(col - threshold), vec3(0.05)))) {
+        if (any(greaterThan(abs(col - vec3(threshold)), vec3(threshold.w)))) {
           weight = 0.0;
         }
       }
diff --git a/source/blender/shader_fx/intern/FX_shader_glow.c b/source/blender/shader_fx/intern/FX_shader_glow.c
index 30eaa35a049..fc75771cd62 100644
--- a/source/blender/shader_fx/intern/FX_shader_glow.c
+++ b/source/blender/shader_fx/intern/FX_shader_glow.c
@@ -71,12 +71,11 @@ static void panel_draw(const bContext *UNUSED(C), Panel *panel)
 
   uiItemR(layout, ptr, "mode", 0, NULL, ICON_NONE);
 
-  if (mode == eShaderFxGlowMode_Luminance) {
-    uiItemR(layout, ptr, "threshold", 0, NULL, ICON_NONE);
-  }
-  else {
+  uiItemR(layout, ptr, "threshold", 0, NULL, ICON_NONE);
+  if (mode == eShaderFxGlowMode_Color) {
     uiItemR(layout, ptr, "select_color", 0, NULL, ICON_NONE);
   }
+
   uiItemR(layout, ptr, "glow_color", 0, NULL, ICON_NONE);
 
   uiItemS(layout);



More information about the Bf-blender-cvs mailing list