Commit: 98fac0e144f473bbcdf6df567d4e6b15376a8074
Author: Antonioya
Date: Sun Jul 1 16:12:21 2018 +0200
Branches: temp-greasepencil-vfx
https://developer.blender.org/rB98fac0e144f473bbcdf6df567d4e6b15376a8074
New Rim FX shader effect
This effect allows to create a rim around the whole drawing.
A mask color can be defined in order to keep drawing lines below the rim.
===================================================================
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_rim_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_rim.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 9bf26a8baed..6f2cab5239d 100644
--- a/release/scripts/startup/bl_ui/properties_data_shaderfx.py
+++ b/release/scripts/startup/bl_ui/properties_data_shaderfx.py
@@ -82,6 +82,13 @@ class DATA_PT_shader_fx(ShaderFxButtonsPanel, Panel):
col.enabled = fx.use_lines
col.prop(fx, "color")
+ def FX_RIM(self, layout, fx):
+ layout.prop(fx, "offset", text="Offset")
+
+ layout.prop(fx, "rim_color")
+ layout.prop(fx, "mask_color")
+ layout.prop(fx, "mode")
+
def FX_SWIRL(self, layout, fx):
layout.prop(fx, "object", text="Object")
diff --git a/source/blender/draw/CMakeLists.txt
b/source/blender/draw/CMakeLists.txt
index c220eba2255..b4c147a3bdd 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -323,6 +323,7 @@
data_to_c_simple(engines/gpencil/shaders/fx/gpencil_fx_blur_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)
+data_to_c_simple(engines/gpencil/shaders/fx/gpencil_fx_rim_frag.glsl SRC)
data_to_c_simple(engines/gpencil/shaders/fx/gpencil_fx_swirl_frag.glsl SRC)
data_to_c_simple(engines/gpencil/shaders/fx/gpencil_fx_wave_frag.glsl SRC)
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h
b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 0acb86a5702..2967cd1f8de 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -64,6 +64,14 @@ typedef struct GPencilFXPixel {
int lines;
} GPencilFXPixel;
+typedef struct GPencilFXRim {
+ float loc[3];
+ float offset[2];
+ float rim_rgba[4];
+ float mask_rgba[4];
+ int mode;
+} GPencilFXRim;
+
typedef struct GPencilFXBlur {
float radius[2];
int samples;
@@ -104,6 +112,7 @@ typedef struct tGPencilObjectCache {
DRWShadingGroup *fx_wave_sh;
DRWShadingGroup *fx_blur_sh;
DRWShadingGroup *fx_pixel_sh;
+ DRWShadingGroup *fx_rim_sh;
DRWShadingGroup *fx_swirl_sh;
DRWShadingGroup *fx_flip_sh;
DRWShadingGroup *fx_light_sh;
@@ -117,6 +126,7 @@ typedef struct GPENCIL_fx {
GPencilFXBlur fx_blur;
GPencilFXWave fx_wave;
GPencilFXPixel fx_pixel;
+ GPencilFXRim fx_rim;
GPencilFXSwirl fx_swirl;
GPencilFXFlip fx_flip;
GPencilFXLight fx_light;
@@ -192,6 +202,7 @@ typedef struct GPENCIL_PassList {
struct DRWPass *fx_flip_pass;
struct DRWPass *fx_light_pass;
struct DRWPass *fx_pixel_pass;
+ struct DRWPass *fx_rim_pass;
struct DRWPass *fx_swirl_pass;
struct DRWPass *fx_wave_pass;
@@ -273,6 +284,7 @@ typedef struct GPENCIL_e_data {
struct GPUShader *gpencil_fx_flip_sh;
struct GPUShader *gpencil_fx_light_sh;
struct GPUShader *gpencil_fx_pixel_sh;
+ struct GPUShader *gpencil_fx_rim_sh;
struct GPUShader *gpencil_fx_swirl_sh;
struct GPUShader *gpencil_fx_wave_sh;
diff --git a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
index 6c38f4be357..735e4ddfe72 100644
--- a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
+++ b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
@@ -45,6 +45,7 @@ extern char datatoc_gpencil_fx_blur_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[];
+extern char datatoc_gpencil_fx_rim_frag_glsl[];
extern char datatoc_gpencil_fx_swirl_frag_glsl[];
extern char datatoc_gpencil_fx_wave_frag_glsl[];
@@ -348,6 +349,47 @@ static void DRW_gpencil_fx_pixel(
cache->fx_pixel_sh = fx_shgrp;
}
+/* Rim FX */
+static void DRW_gpencil_fx_rim(
+ ShaderFxData *fx, int ob_idx, GPENCIL_e_data *e_data, GPENCIL_Data
*vedata,
+ tGPencilObjectCache *cache)
+{
+ if (fx == NULL) {
+ return;
+ }
+ Object *ob = cache->ob;
+ RimShaderFxData *fxd = (RimShaderFxData *)fx;
+
+ GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
+ GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl;
+ DRWShadingGroup *fx_shgrp;
+ bGPdata *gpd = (bGPdata *)ob->data;
+
+ stl->fx[ob_idx].fx_rim.offset[0] = fxd->offset[0];
+ stl->fx[ob_idx].fx_rim.offset[1] = fxd->offset[1];
+ copy_v4_v4(stl->fx[ob_idx].fx_rim.rim_rgba, fxd->rim_rgba);
+ copy_v4_v4(stl->fx[ob_idx].fx_rim.mask_rgba, fxd->mask_rgba);
+ stl->fx[ob_idx].fx_rim.mode = fxd->mode;
+
+ struct Gwn_Batch *fxquad = DRW_cache_fullscreen_quad_get();
+ fx_shgrp = DRW_shgroup_create(e_data->gpencil_fx_rim_sh,
psl->fx_rim_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_vec2(fx_shgrp, "offset",
&stl->fx[ob_idx].fx_rim.offset[0], 1);
+ DRW_shgroup_uniform_vec4(fx_shgrp, "rim_color",
&stl->fx[ob_idx].fx_rim.rim_rgba[0], 1);
+ DRW_shgroup_uniform_vec4(fx_shgrp, "mask_color",
&stl->fx[ob_idx].fx_rim.mask_rgba[0], 1);
+ DRW_shgroup_uniform_int(fx_shgrp, "mode", &stl->fx[ob_idx].fx_rim.mode,
1);
+
+ copy_v3_v3(stl->fx[ob_idx].fx_pixel.loc, &ob->loc[0]);
+ DRW_shgroup_uniform_vec3(fx_shgrp, "loc", stl->fx[ob_idx].fx_pixel.loc,
1);
+ DRW_shgroup_uniform_float(fx_shgrp, "pixsize", stl->storage->pixsize,
1);
+ DRW_shgroup_uniform_float(fx_shgrp, "pixelsize", &U.pixelsize, 1);
+ DRW_shgroup_uniform_float(fx_shgrp, "pixfactor", &gpd->pixfactor, 1);
+
+ cache->fx_rim_sh = fx_shgrp;
+}
+
/* Swirl FX */
static void DRW_gpencil_fx_swirl(
ShaderFxData *fx, int ob_idx, GPENCIL_e_data *e_data, GPENCIL_Data
*vedata,
@@ -444,6 +486,9 @@ void GPENCIL_create_fx_shaders(GPENCIL_e_data *e_data)
if (!e_data->gpencil_fx_pixel_sh) {
e_data->gpencil_fx_pixel_sh =
DRW_shader_create_fullscreen(datatoc_gpencil_fx_pixel_frag_glsl, NULL);
}
+ if (!e_data->gpencil_fx_rim_sh) {
+ e_data->gpencil_fx_rim_sh =
DRW_shader_create_fullscreen(datatoc_gpencil_fx_rim_frag_glsl, NULL);
+ }
if (!e_data->gpencil_fx_swirl_sh) {
e_data->gpencil_fx_swirl_sh =
DRW_shader_create_fullscreen(datatoc_gpencil_fx_swirl_frag_glsl, NULL);
}
@@ -459,6 +504,7 @@ void GPENCIL_delete_fx_shaders(GPENCIL_e_data *e_data)
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);
+ DRW_SHADER_FREE_SAFE(e_data->gpencil_fx_rim_sh);
DRW_SHADER_FREE_SAFE(e_data->gpencil_fx_swirl_sh);
DRW_SHADER_FREE_SAFE(e_data->gpencil_fx_wave_sh);
}
@@ -477,6 +523,8 @@ void GPENCIL_create_fx_passes(GPENCIL_PassList *psl)
psl->fx_pixel_pass = DRW_pass_create("GPencil FX Pixel Pass", state);
+ psl->fx_rim_pass = DRW_pass_create("GPencil FX Rim Pass", state);
+
psl->fx_swirl_pass = DRW_pass_create("GPencil FX Swirl Pass", state);
psl->fx_wave_pass = DRW_pass_create("GPencil FX Wave Pass", state);
@@ -511,6 +559,9 @@ void DRW_gpencil_fx_prepare(
case eShaderFxType_Pixel:
DRW_gpencil_fx_pixel(fx, ob_idx,
e_data, vedata, cache);
break;
+ case eShaderFxType_Rim:
+ DRW_gpencil_fx_rim(fx, ob_idx, e_data,
vedata, cache);
+ break;
case eShaderFxType_Swirl:
DRW_gpencil_fx_swirl(fx, ob_idx,
e_data, vedata, cache);
break;
@@ -628,6 +679,13 @@ void DRW_gpencil_fx_draw(struct GPENCIL_e_data *e_data,
fbl, cache->fx_pixel_sh);
}
break;
+ case eShaderFxType_Rim:
+ if (cache->fx_rim_sh) {
+ gpencil_draw_fx_pass(e_data,
psl->fx_rim_pass,
+ psl->mix_pass_noblend,
+ fbl, cache->fx_rim_sh);
+ }
+ break;
case eShaderFxType_Swirl:
if (cache->fx_swirl_sh) {
gpencil_draw_fx_pass(e_data,
psl->fx_swirl_pass,
diff --git
a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_rim_frag.glsl
b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_rim_frag.glsl
new file mode 100644
index 00000000000..8edc6040f1a
--- /dev/null
+++ b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_rim_frag.glsl
@@ -0,0 +1,115 @@
+uniform mat4 ProjectionMatrix;
+uniform mat4 ViewMatrix;
+
+uniform sampler2D strokeColor;
+uniform sampler2D strokeDepth;
+
+uniform vec2 offset;
+uniform vec4 rim_color;
+uniform vec4 mask_color;
+uniform int mode;
+
+uniform vec3 loc;
+uniform float pixsize; /* rv3d->pixsize */
+uniform float pixelsize; /* U.pixelsize */
+uniform float pixfactor;
+
+out vec4 FragColor;
+
+#define MODE_NORMAL 0
+#define MODE_OVERLAY 1
+#define MODE_ADD 2
+#define MODE_SUB 3
+#define MODE_MULTIPLY 4
+#define MODE_DIVIDE 5
+
+float defaultpixsize = pixsize * pixelsize * (1000.0 / pixfactor);
+vec2 noffset = vec2(offset[0], offset[1]);
+
+float overlay_color(float a, float b)
+{
+ float rtn;
+ if (a < 0.5) {
+ rtn = 2.0 * a * b;
+ }
+ else {
+ rtn = 1.0 - 2.0 * (1.0 - a) * (1.0 - b);
+ }
+
+ return rtn;
+}
+
+vec4 get_blend_color(int mode, vec4 src_color, vec4 mix_color)
+{
+ vec4 outcolor;
+ if (mode == MODE_NORMAL) {
+ outcolor = mix_color;
+ }
+ else if (mode == MODE_OVERLAY) {
+ outcolor.r = overlay_color(src_color.r, mix_color.r);
+ outcolor.g = overlay_color(src_color.g, mix_color.g);
+ outcolor.b = overlay_color(src_color.b, mix_color.b);
+
+ outcolor.a = src_color.a;
+ }
+ else if (mode == MODE_ADD){
+ outcolor = src_color + mix_color;
+ outcolor.a = src_color.a;
+ }
+ else if (mode == MODE_SUB){
+ outcolor = src_color - mix_color;
+ outcolor.a = src_color.a;
+ }
+ else if (mode == MODE_MULTIPLY) {
+ outcolor = src_color * mix_color;
+ outcolor.a = src_color.a;
+ }
+ else if (mode == MODE_DIVIDE) {
+ outcolor = src_color / mix_color;
+ outcolor.a = src_color.a;
+ }
+ else {
+ outcolor = mix_color;
+ }
+ return outcolor;
+}
+
+void main()
+{
+ vec2 uv = vec2(gl_FragCoord.xy);
+ vec4 nloc = ProjectionMatrix * ViewMatrix * vec4(loc.xyz, 1.0);
+
+ float dx = (ProjectionMatrix[3][3] == 0.0) ? (noffset[0] / (nloc.z *
defaultpixsize)) : (noffset[0] / defaultpixsize);
+ float dy = (ProjectionMatrix[3][3] == 0.0) ? (noffset[1] / (nloc.z *
defaultpixsi
@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs