Commit: 26d0530d03a5a3d593293376eebb738933b04159
Author: Antonio Vazquez
Date:   Sun Jul 1 17:21:46 2018 +0200
Branches: temp-greasepencil-vfx
https://developer.blender.org/rB26d0530d03a5a3d593293376eebb738933b04159

New Colorize Shader effect

This effects is used to convert to GrayScale, Sepia, BW and other color changes.

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

M       release/scripts/startup/bl_ui/properties_data_shaderfx.py
M       source/blender/draw/CMakeLists.txt
M       source/blender/draw/engines/gpencil/gpencil_engine.h
M       source/blender/draw/engines/gpencil/gpencil_shader_fx.c
A       
source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_colorize_frag.glsl
M       source/blender/makesdna/DNA_shader_fx_types.h
M       source/blender/makesrna/RNA_access.h
M       source/blender/makesrna/intern/rna_shader_fx.c
M       source/blender/shader_fx/CMakeLists.txt
M       source/blender/shader_fx/FX_shader_types.h
A       source/blender/shader_fx/intern/FX_shader_colorize.c
M       source/blender/shader_fx/intern/FX_shader_util.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_shaderfx.py 
b/release/scripts/startup/bl_ui/properties_data_shaderfx.py
index 6f2cab5239d..1cb940d39cc 100644
--- a/release/scripts/startup/bl_ui/properties_data_shaderfx.py
+++ b/release/scripts/startup/bl_ui/properties_data_shaderfx.py
@@ -65,6 +65,20 @@ class DATA_PT_shader_fx(ShaderFxButtonsPanel, Panel):
         if fx.use_dof_mode:
             layout.prop(fx, "coc")
 
+    def FX_COLORIZE(self, layout, fx):
+        layout.prop(fx, "mode", text="Mode")
+
+        if fx.mode == 'BITONE':
+            layout.prop(fx, "low_color", text="Low Color")
+        if fx.mode == 'CUSTOM':
+            layout.prop(fx, "low_color", text="Color")
+
+        if fx.mode == 'BITONE':
+            layout.prop(fx, "high_color", text="High Color")
+
+        if fx.mode in {'BITONE', 'CUSTOM'}:
+            layout.prop(fx, "factor")
+
     def FX_WAVE(self, layout,fx):
         layout.prop(fx, "orientation", expand=True)
 
diff --git a/source/blender/draw/CMakeLists.txt 
b/source/blender/draw/CMakeLists.txt
index b4c147a3bdd..6343a8825f3 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -320,6 +320,7 @@ 
data_to_c_simple(engines/gpencil/shaders/gpencil_edit_point_geom.glsl SRC)
 data_to_c_simple(engines/gpencil/shaders/gpencil_edit_point_frag.glsl SRC)
 
 data_to_c_simple(engines/gpencil/shaders/fx/gpencil_fx_blur_frag.glsl SRC)
+data_to_c_simple(engines/gpencil/shaders/fx/gpencil_fx_colorize_frag.glsl SRC)
 data_to_c_simple(engines/gpencil/shaders/fx/gpencil_fx_flip_frag.glsl SRC)
 data_to_c_simple(engines/gpencil/shaders/fx/gpencil_fx_light_frag.glsl SRC)
 data_to_c_simple(engines/gpencil/shaders/fx/gpencil_fx_pixel_frag.glsl SRC)
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h 
b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 2967cd1f8de..766a555b255 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -77,6 +77,13 @@ typedef struct GPencilFXBlur {
        int samples;
 } GPencilFXBlur;
 
+typedef struct GPencilFXColorize {
+       float low_color[4];
+       float high_color[4];
+       int mode;
+       float factor;
+} GPencilFXColorize;
+
 typedef struct GPencilFXFlip {
        float flipmode[2]; /* use float to pass to shader, but only will be 0 
or 1 */
 } GPencilFXFlip;
@@ -111,6 +118,7 @@ typedef struct tGPencilObjectCache {
        /* effects */
        DRWShadingGroup *fx_wave_sh;
        DRWShadingGroup *fx_blur_sh;
+       DRWShadingGroup *fx_colorize_sh;
        DRWShadingGroup *fx_pixel_sh;
        DRWShadingGroup *fx_rim_sh;
        DRWShadingGroup *fx_swirl_sh;
@@ -124,6 +132,7 @@ typedef struct tGPencilObjectCache {
   /* *********** LISTS *********** */
 typedef struct GPENCIL_fx {
        GPencilFXBlur fx_blur;
+       GPencilFXColorize fx_colorize;
        GPencilFXWave fx_wave;
        GPencilFXPixel fx_pixel;
        GPencilFXRim fx_rim;
@@ -199,6 +208,7 @@ typedef struct GPENCIL_PassList {
 
        /* effects */
        struct DRWPass *fx_blur_pass;
+       struct DRWPass *fx_colorize_pass;
        struct DRWPass *fx_flip_pass;
        struct DRWPass *fx_light_pass;
        struct DRWPass *fx_pixel_pass;
@@ -281,6 +291,7 @@ typedef struct GPENCIL_e_data {
 
        /* effects */
        struct GPUShader *gpencil_fx_blur_sh;
+       struct GPUShader *gpencil_fx_colorize_sh;
        struct GPUShader *gpencil_fx_flip_sh;
        struct GPUShader *gpencil_fx_light_sh;
        struct GPUShader *gpencil_fx_pixel_sh;
diff --git a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c 
b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
index 735e4ddfe72..e1518deb69f 100644
--- a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
+++ b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
@@ -42,6 +42,7 @@
 #include "gpencil_engine.h"
 
 extern char datatoc_gpencil_fx_blur_frag_glsl[];
+extern char datatoc_gpencil_fx_colorize_frag_glsl[];
 extern char datatoc_gpencil_fx_flip_frag_glsl[];
 extern char datatoc_gpencil_fx_light_frag_glsl[];
 extern char datatoc_gpencil_fx_pixel_frag_glsl[];
@@ -215,6 +216,40 @@ static void DRW_gpencil_fx_blur(
        cache->fx_blur_sh = fx_shgrp;
 }
 
+/* Colorize FX */
+static void DRW_gpencil_fx_colorize(
+       ShaderFxData *fx, int ob_idx, GPENCIL_e_data *e_data, GPENCIL_Data 
*vedata,
+       tGPencilObjectCache *cache)
+{
+       if (fx == NULL) {
+               return;
+       }
+       Object *ob = cache->ob;
+       ColorizeShaderFxData *fxd = (ColorizeShaderFxData *)fx;
+
+       GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
+       GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl;
+       DRWShadingGroup *fx_shgrp;
+       bGPdata *gpd = (bGPdata *)ob->data;
+
+       copy_v4_v4(stl->fx[ob_idx].fx_colorize.low_color, fxd->low_color);
+       copy_v4_v4(stl->fx[ob_idx].fx_colorize.high_color, fxd->high_color);
+       stl->fx[ob_idx].fx_colorize.mode = fxd->mode;
+       stl->fx[ob_idx].fx_colorize.factor = fxd->factor;
+
+       struct Gwn_Batch *fxquad = DRW_cache_fullscreen_quad_get();
+       fx_shgrp = DRW_shgroup_create(e_data->gpencil_fx_colorize_sh, 
psl->fx_colorize_pass);
+       DRW_shgroup_call_add(fx_shgrp, fxquad, NULL);
+       DRW_shgroup_uniform_texture_ref(fx_shgrp, "strokeColor", 
&e_data->temp_color_tx_a);
+       DRW_shgroup_uniform_texture_ref(fx_shgrp, "strokeDepth", 
&e_data->temp_depth_tx_a);
+       DRW_shgroup_uniform_vec4(fx_shgrp, "low_color", 
&stl->fx[ob_idx].fx_colorize.low_color[0], 1);
+       DRW_shgroup_uniform_vec4(fx_shgrp, "high_color", 
&stl->fx[ob_idx].fx_colorize.high_color[0], 1);
+       DRW_shgroup_uniform_int(fx_shgrp, "mode", 
&stl->fx[ob_idx].fx_colorize.mode, 1);
+       DRW_shgroup_uniform_float(fx_shgrp, "factor", 
&stl->fx[ob_idx].fx_colorize.factor, 1);
+
+       cache->fx_colorize_sh = fx_shgrp;
+}
+
 /* Flip FX */
 static void DRW_gpencil_fx_flip(
        ShaderFxData *fx, int ob_idx, GPENCIL_e_data *e_data, GPENCIL_Data 
*vedata,
@@ -477,6 +512,9 @@ void GPENCIL_create_fx_shaders(GPENCIL_e_data *e_data)
        if (!e_data->gpencil_fx_blur_sh) {
                e_data->gpencil_fx_blur_sh = 
DRW_shader_create_fullscreen(datatoc_gpencil_fx_blur_frag_glsl, NULL);
        }
+       if (!e_data->gpencil_fx_colorize_sh) {
+               e_data->gpencil_fx_colorize_sh = 
DRW_shader_create_fullscreen(datatoc_gpencil_fx_colorize_frag_glsl, NULL);
+       }
        if (!e_data->gpencil_fx_flip_sh) {
                e_data->gpencil_fx_flip_sh = 
DRW_shader_create_fullscreen(datatoc_gpencil_fx_flip_frag_glsl, NULL);
        }
@@ -501,6 +539,7 @@ void GPENCIL_create_fx_shaders(GPENCIL_e_data *e_data)
 void GPENCIL_delete_fx_shaders(GPENCIL_e_data *e_data)
 {
        DRW_SHADER_FREE_SAFE(e_data->gpencil_fx_blur_sh);
+       DRW_SHADER_FREE_SAFE(e_data->gpencil_fx_colorize_sh);
        DRW_SHADER_FREE_SAFE(e_data->gpencil_fx_flip_sh);
        DRW_SHADER_FREE_SAFE(e_data->gpencil_fx_light_sh);
        DRW_SHADER_FREE_SAFE(e_data->gpencil_fx_pixel_sh);
@@ -517,6 +556,8 @@ void GPENCIL_create_fx_passes(GPENCIL_PassList *psl)
        /* FX passes */
        psl->fx_blur_pass = DRW_pass_create("GPencil FX Blur Pass", state);
 
+       psl->fx_colorize_pass = DRW_pass_create("GPencil FX Colorize Pass", 
state);
+
        psl->fx_flip_pass = DRW_pass_create("GPencil FX Flip Pass", state);
 
        psl->fx_light_pass = DRW_pass_create("GPencil FX Light Pass", state);
@@ -550,6 +591,9 @@ void DRW_gpencil_fx_prepare(
                                case eShaderFxType_Blur:
                                        DRW_gpencil_fx_blur(fx, ob_idx, e_data, 
vedata, cache);
                                        break;
+                               case eShaderFxType_Colorize:
+                                       DRW_gpencil_fx_colorize(fx, ob_idx, 
e_data, vedata, cache);
+                                       break;
                                case eShaderFxType_Flip:
                                        DRW_gpencil_fx_flip(fx, ob_idx, e_data, 
vedata, cache);
                                        break;
@@ -658,6 +702,13 @@ void DRW_gpencil_fx_draw(struct GPENCIL_e_data *e_data,
                                                gpencil_blur_passes(e_data, 
vedata, cache);
                                        }
                                        break;
+                               case eShaderFxType_Colorize:
+                                       if (cache->fx_colorize_sh) {
+                                               gpencil_draw_fx_pass(e_data, 
psl->fx_colorize_pass,
+                                                       psl->mix_pass_noblend,
+                                                       fbl, 
cache->fx_colorize_sh);
+                                       }
+                                       break;
                                case eShaderFxType_Flip:
                                        if (cache->fx_flip_sh) {
                                                gpencil_draw_fx_pass(e_data, 
psl->fx_flip_pass,
diff --git 
a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_colorize_frag.glsl 
b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_colorize_frag.glsl
new file mode 100644
index 00000000000..c5ac710de1e
--- /dev/null
+++ 
b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_colorize_frag.glsl
@@ -0,0 +1,80 @@
+uniform sampler2D strokeColor;
+uniform sampler2D strokeDepth;
+
+uniform vec4 low_color;
+uniform vec4 high_color;
+uniform int mode;
+uniform float factor;
+
+out vec4 FragColor;
+
+#define MODE_GRAYSCALE   0
+#define MODE_SEPIA       1
+#define MODE_BITONE      2
+#define MODE_CUSTOM      3
+
+float get_luminance(vec4 color)
+{
+       float lum = (color.r * 0.2126) + (color.g * 0.7152) + (color.b * 0.723);
+       return lum;
+}
+
+void main()
+{
+       ivec2 uv = ivec2(gl_FragCoord.xy);
+
+       float stroke_depth = texelFetch(strokeDepth, uv.xy, 0).r;
+       vec4 src_pixel= texelFetch(strokeColor, uv.xy, 0);
+       float luminance = get_luminance(src_pixel);
+       vec4 outcolor;
+       
+       /* is transparent */ 
+       if (src_pixel.a == 0.0f) {
+               discard;
+       }
+       
+       switch(mode) {
+               case MODE_GRAYSCALE:
+                       {
+                       outcolor = vec4(luminance, luminance, luminance, 
src_pixel.a);
+                       break;
+                       }
+               case MODE_SEPIA:
+                       {
+                       float Red = (src_pixel.r * 0.393) + (src_pixel.g * 
0.769) + (src_pixel.b * 0.189);
+                       float Green = (src_pixel.r * 0.349) + (src_pixel.g * 
0.686) + (src_pixel.b * 0.168);
+                       float Blue = (src_pixel.r * 0.272) + (src_pixel.g * 
0.534) + (src_pixel.b * 0.131);
+                       outcolor = vec4(Red, Green, Blue, src_pixel.a);
+                       break;
+                       }
+               case MODE_BITONE:
+                       {
+                       if (luminance <= factor) {
+                               outcolor = low_color;
+                       }
+                       else {
+                               outcolor = high_color;
+                       }
+                       break;
+                       }
+               case MODE_CUSTOM:
+                       {
+                       /* if below umbral, force custom color */
+                       if (luminance <= factor) {
+                               outcolor = low_color;
+                       }
+                       else {
+                               outcolor = vec4(luminance * low_color.r, 
luminance * low_color.b, luminance * low_color.b, src_pixel.a);
+                       }
+                       break;
+                       }
+               default:
+                       {
+                       outcolor = src_pixel;
+                       }
+       
+       }
+
+       gl_FragDepth = stroke_depth;
+       FragColor = outcolor;
+}
diff --git a/source/blender/makesdna/DNA_shader_fx_types.h 
b/source/blender/makesdna/DNA_shader_fx_types.h
index ef57569a8d7..483f0250542 100644
--- a/source/blender/makesdna/DNA_shader_fx_types.h
+++ b/source/blender/makesdna/DNA_shader_fx_types.h
@@ -

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to