[Bf-blender-cvs] [7359bec21b2] greasepencil-refactor: GPencil: Refactor: Add Colorize FX

Clément Foucault noreply at git.blender.org
Thu Dec 19 01:30:57 CET 2019


Commit: 7359bec21b2be5d284ba8a5630bfa2642ba55cad
Author: Clément Foucault
Date:   Wed Dec 18 19:50:58 2019 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rB7359bec21b2be5d284ba8a5630bfa2642ba55cad

GPencil: Refactor: Add Colorize FX

The behavior has been changed quite a bit to work with separated
transparency layer.

- The custom mode now just blend between the original image and the
  same image with the color changed and luma kept as is.
- Grayscale & Sepia mode now blend with the original image using the factor.
- The duo tone do not do a sharp separation of colors. It just color the
  original in 2 different color using a hard separation threshold.

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

M	source/blender/draw/engines/gpencil/gpencil_engine.c
M	source/blender/draw/engines/gpencil/gpencil_engine.h
M	source/blender/draw/engines/gpencil/gpencil_shader.c
M	source/blender/draw/engines/gpencil/gpencil_shader_fx.c
M	source/blender/draw/engines/gpencil/shaders/gpencil_vfx_frag.glsl

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

diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 85b125d0783..39fab08dae8 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -360,6 +360,7 @@ static void GPENCIL_engine_free(void)
   DRW_SHADER_FREE_SAFE(e_data.depth_merge_sh);
 
   DRW_SHADER_FREE_SAFE(e_data.fx_blur_sh);
+  DRW_SHADER_FREE_SAFE(e_data.fx_colorize_sh);
   DRW_SHADER_FREE_SAFE(e_data.fx_composite_sh);
   DRW_SHADER_FREE_SAFE(e_data.fx_glow_sh);
   DRW_SHADER_FREE_SAFE(e_data.fx_pixel_sh);
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 8c5393a40d0..2df8688f0d1 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -471,6 +471,7 @@ typedef struct GPENCIL_e_data {
   struct GPUShader *depth_merge_sh;
   /* Effects. */
   struct GPUShader *fx_composite_sh;
+  struct GPUShader *fx_colorize_sh;
   struct GPUShader *fx_blur_sh;
   struct GPUShader *fx_glow_sh;
   struct GPUShader *fx_pixel_sh;
@@ -713,6 +714,7 @@ struct GPUShader *GPENCIL_shader_layer_blend_get(GPENCIL_e_data *e_data);
 struct GPUShader *GPENCIL_shader_layer_mask_get(GPENCIL_e_data *e_data);
 struct GPUShader *GPENCIL_shader_depth_merge_get(GPENCIL_e_data *e_data);
 struct GPUShader *GPENCIL_shader_fx_blur_get(GPENCIL_e_data *e_data);
+struct GPUShader *GPENCIL_shader_fx_colorize_get(GPENCIL_e_data *e_data);
 struct GPUShader *GPENCIL_shader_fx_composite_get(GPENCIL_e_data *e_data);
 struct GPUShader *GPENCIL_shader_fx_glow_get(GPENCIL_e_data *e_data);
 struct GPUShader *GPENCIL_shader_fx_pixelize_get(GPENCIL_e_data *e_data);
diff --git a/source/blender/draw/engines/gpencil/gpencil_shader.c b/source/blender/draw/engines/gpencil/gpencil_shader.c
index 0590ea2824f..7533ebff48f 100644
--- a/source/blender/draw/engines/gpencil/gpencil_shader.c
+++ b/source/blender/draw/engines/gpencil/gpencil_shader.c
@@ -121,6 +121,15 @@ struct GPUShader *GPENCIL_shader_fx_blur_get(GPENCIL_e_data *e_data)
   return e_data->fx_blur_sh;
 }
 
+struct GPUShader *GPENCIL_shader_fx_colorize_get(GPENCIL_e_data *e_data)
+{
+  if (!e_data->fx_colorize_sh) {
+    e_data->fx_colorize_sh = DRW_shader_create_fullscreen(datatoc_gpencil_vfx_frag_glsl,
+                                                          "#define COLORIZE\n");
+  }
+  return e_data->fx_colorize_sh;
+}
+
 struct GPUShader *GPENCIL_shader_fx_composite_get(GPENCIL_e_data *e_data)
 {
   if (!e_data->fx_composite_sh) {
diff --git a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
index 16917593242..fe33113bd6f 100644
--- a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
+++ b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
@@ -1120,6 +1120,21 @@ static void gpencil_vfx_blur(BlurShaderFxData *fx, Object *UNUSED(ob), gpIterVfx
   DRW_shgroup_call_procedural_triangles(grp, NULL, 1);
 }
 
+static void gpencil_vfx_colorize(ColorizeShaderFxData *fx, Object *UNUSED(ob), gpIterVfxData *iter)
+{
+  DRWShadingGroup *grp;
+
+  GPUShader *sh = GPENCIL_shader_fx_colorize_get(&en_data);
+
+  DRWState state = DRW_STATE_WRITE_COLOR;
+  grp = gpencil_vfx_pass_create("Fx Colorize", state, iter, sh);
+  DRW_shgroup_uniform_vec3_copy(grp, "low_color", fx->low_color);
+  DRW_shgroup_uniform_vec3_copy(grp, "high_color", fx->high_color);
+  DRW_shgroup_uniform_float_copy(grp, "factor", fx->factor);
+  DRW_shgroup_uniform_int_copy(grp, "mode", fx->mode);
+  DRW_shgroup_call_procedural_triangles(grp, NULL, 1);
+}
+
 static void gpencil_vfx_pixelize(PixelShaderFxData *fx, Object *ob, gpIterVfxData *iter)
 {
   DRWShadingGroup *grp;
@@ -1347,6 +1362,7 @@ void gpencil_vfx_cache_populate(GPENCIL_Data *vedata, Object *ob, GPENCIL_tObjec
           gpencil_vfx_blur((BlurShaderFxData *)fx, ob, &iter);
           break;
         case eShaderFxType_Colorize:
+          gpencil_vfx_colorize((ColorizeShaderFxData *)fx, ob, &iter);
           break;
         case eShaderFxType_Flip:
           break;
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 b0046d4e4c8..6e790acff9f 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_vfx_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_vfx_frag.glsl
@@ -33,6 +33,51 @@ void main()
   }
 }
 
+#elif defined(COLORIZE)
+
+uniform vec3 low_color;
+uniform vec3 high_color;
+uniform float factor;
+uniform int mode;
+
+const mat3 sepia_mat = mat3(
+    vec3(0.393, 0.349, 0.272), vec3(0.769, 0.686, 0.534), vec3(0.189, 0.168, 0.131));
+
+#  define MODE_GRAYSCALE 0
+#  define MODE_SEPIA 1
+#  define MODE_DUOTONE 2
+#  define MODE_CUSTOM 3
+#  define MODE_TRANSPARENT 4
+
+void main()
+{
+  fragColor = texture(colorBuf, uvcoordsvar.xy);
+  fragRevealage = texture(revealBuf, uvcoordsvar.xy);
+
+  float luma = dot(fragColor.rgb, vec3(0.2126, 0.7152, 0.723));
+
+  /* No blending. */
+  switch (mode) {
+    case MODE_GRAYSCALE:
+      fragColor.rgb = mix(fragColor.rgb, vec3(luma), factor);
+      break;
+    case MODE_SEPIA:
+      fragColor.rgb = mix(fragColor.rgb, sepia_mat * fragColor.rgb, factor);
+      break;
+    case MODE_DUOTONE:
+      fragColor.rgb = luma * ((luma <= factor) ? low_color : high_color);
+      break;
+    case MODE_CUSTOM:
+      fragColor.rgb = mix(fragColor.rgb, luma * low_color, factor);
+      break;
+    case MODE_TRANSPARENT:
+    default:
+      fragColor.rgb *= factor;
+      fragRevealage.rgb = mix(vec3(1.0), fragRevealage.rgb, factor);
+      break;
+  }
+}
+
 #elif defined(BLUR)
 
 uniform vec2 offset;



More information about the Bf-blender-cvs mailing list