[Bf-blender-cvs] [2e5d299823b] greasepencil-refactor: GPencil: Refactor: Add Glow effect
Clément Foucault
noreply at git.blender.org
Wed Dec 18 03:14:33 CET 2019
Commit: 2e5d299823b534865129466e053b9db0b021b8f1
Author: Clément Foucault
Date: Tue Dec 17 18:16:19 2019 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rB2e5d299823b534865129466e053b9db0b021b8f1
GPencil: Refactor: Add Glow effect
The glow effect is now additive. You cannot make black "glow" (whatever
that meant).
===================================================================
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 aea3d37ca16..75514d07351 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -359,8 +359,9 @@ static void GPENCIL_engine_free(void)
DRW_SHADER_FREE_SAFE(e_data.layer_mask_sh);
DRW_SHADER_FREE_SAFE(e_data.depth_merge_sh);
- DRW_SHADER_FREE_SAFE(e_data.fx_composite_sh);
DRW_SHADER_FREE_SAFE(e_data.fx_blur_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);
DRW_TEXTURE_FREE_SAFE(e_data.gpencil_blank_texture);
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 9c3fc0d041a..35d23652bc1 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -469,6 +469,7 @@ typedef struct GPENCIL_e_data {
/* Effects. */
struct GPUShader *fx_blur_sh;
struct GPUShader *fx_pixel_sh;
+ struct GPUShader *fx_glow_sh;
struct GPUShader *fx_composite_sh;
/* general drawing shaders */
@@ -707,8 +708,9 @@ struct GPUShader *GPENCIL_shader_composite_get(GPENCIL_e_data *e_data);
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_composite_get(GPENCIL_e_data *e_data);
struct GPUShader *GPENCIL_shader_fx_blur_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);
/* main functions */
diff --git a/source/blender/draw/engines/gpencil/gpencil_shader.c b/source/blender/draw/engines/gpencil/gpencil_shader.c
index 618c44143da..f61ee80c39f 100644
--- a/source/blender/draw/engines/gpencil/gpencil_shader.c
+++ b/source/blender/draw/engines/gpencil/gpencil_shader.c
@@ -112,6 +112,15 @@ struct GPUShader *GPENCIL_shader_depth_merge_get(GPENCIL_e_data *e_data)
/* ------- FX Shaders --------- */
+struct GPUShader *GPENCIL_shader_fx_blur_get(GPENCIL_e_data *e_data)
+{
+ if (!e_data->fx_blur_sh) {
+ e_data->fx_blur_sh = DRW_shader_create_fullscreen(datatoc_gpencil_vfx_frag_glsl,
+ "#define BLUR\n");
+ }
+ return e_data->fx_blur_sh;
+}
+
struct GPUShader *GPENCIL_shader_fx_composite_get(GPENCIL_e_data *e_data)
{
if (!e_data->fx_composite_sh) {
@@ -121,13 +130,13 @@ struct GPUShader *GPENCIL_shader_fx_composite_get(GPENCIL_e_data *e_data)
return e_data->fx_composite_sh;
}
-struct GPUShader *GPENCIL_shader_fx_blur_get(GPENCIL_e_data *e_data)
+struct GPUShader *GPENCIL_shader_fx_glow_get(GPENCIL_e_data *e_data)
{
- if (!e_data->fx_blur_sh) {
- e_data->fx_blur_sh = DRW_shader_create_fullscreen(datatoc_gpencil_vfx_frag_glsl,
- "#define BLUR\n");
+ if (!e_data->fx_glow_sh) {
+ e_data->fx_glow_sh = DRW_shader_create_fullscreen(datatoc_gpencil_vfx_frag_glsl,
+ "#define GLOW\n");
}
- return e_data->fx_blur_sh;
+ return e_data->fx_glow_sh;
}
struct GPUShader *GPENCIL_shader_fx_pixelize_get(GPENCIL_e_data *e_data)
diff --git a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
index 031e00bd4a7..34661da2b1c 100644
--- a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
+++ b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
@@ -1174,6 +1174,43 @@ static void gpencil_vfx_pixelize(PixelShaderFxData *fx, Object *ob, gpIterVfxDat
}
}
+static void gpencil_vfx_glow(GlowShaderFxData *fx, Object *UNUSED(ob), gpIterVfxData *iter)
+{
+ DRWShadingGroup *grp;
+
+ GPUShader *sh = GPENCIL_shader_fx_glow_get(&en_data);
+
+ float ref_col[3], threshold_min, threshold_max;
+
+ if (fx->mode == eShaderFxGlowMode_Luminance) {
+ ref_col[0] = fx->threshold;
+ ref_col[1] = -1.0f;
+ ref_col[2] = -1.0f;
+ }
+ else {
+ copy_v3_v3(ref_col, fx->select_color);
+ }
+
+ 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], 0.0f});
+ 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_vec3_copy(grp, "glowColor", fx->glow_color);
+ DRW_shgroup_uniform_bool_copy(grp, "useAlphaMode", false);
+ DRW_shgroup_call_procedural_triangles(grp, NULL, 1);
+
+ ref_col[0] = -1.0f;
+
+ state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ADD_FULL;
+ grp = gpencil_vfx_pass_create("Fx Glow V", state, iter, sh);
+ DRW_shgroup_uniform_vec2_copy(grp, "offset", (float[2]){0.0f, fx->blur[0]});
+ DRW_shgroup_uniform_vec3_copy(grp, "threshold", ref_col);
+ DRW_shgroup_uniform_vec3_copy(grp, "glowColor", (float[3]){1.0f, 1.0f, 1.0f});
+ DRW_shgroup_uniform_bool_copy(grp, "useAlphaMode", (fx->flag & FX_GLOW_USE_ALPHA) != 0);
+ DRW_shgroup_call_procedural_triangles(grp, NULL, 1);
+}
+
void gpencil_vfx_cache_populate(GPENCIL_Data *vedata, Object *ob, GPENCIL_tObject *tgp_ob)
{
bGPdata *gpd = (bGPdata *)ob->data;
@@ -1211,6 +1248,7 @@ void gpencil_vfx_cache_populate(GPENCIL_Data *vedata, Object *ob, GPENCIL_tObjec
case eShaderFxType_Shadow:
break;
case eShaderFxType_Glow:
+ gpencil_vfx_glow((GlowShaderFxData *)fx, ob, &iter);
break;
case eShaderFxType_Swirl:
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 6588e3339ab..e483812b292 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_vfx_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_vfx_frag.glsl
@@ -9,6 +9,11 @@ in vec4 uvcoordsvar;
layout(location = 0) out vec4 fragColor;
layout(location = 1) out vec4 fragRevealage;
+float gaussian_weight(float x)
+{
+ return exp(-x * x / (2.0 * 0.35 * 0.35));
+}
+
#if defined(COMPOSITE)
uniform bool isFirstPass;
@@ -33,11 +38,6 @@ void main()
uniform vec2 offset;
uniform int sampCount;
-float gaussian_weight(float x)
-{
- return exp(-x * x / (2.0 * 0.35 * 0.35));
-}
-
void main()
{
vec2 pixel_size = 1.0 / vec2(textureSize(revealBuf, 0).xy);
@@ -61,6 +61,59 @@ void main()
fragRevealage /= weight_accum;
}
+#elif defined(GLOW)
+
+uniform vec3 glowColor;
+uniform vec2 offset;
+uniform int sampCount;
+uniform vec3 threshold;
+uniform bool useAlphaMode;
+
+void main()
+{
+ vec2 pixel_size = 1.0 / vec2(textureSize(revealBuf, 0).xy);
+ vec2 ofs = offset * pixel_size;
+
+ fragColor = vec4(0.0);
+
+ /* In first pass we copy the reveal buffer. This let us do the alpha under if needed. */
+ fragRevealage = texture(revealBuf, uvcoordsvar.xy);
+
+ float weight_accum = 0.0;
+ for (int i = -sampCount; i <= sampCount; i++) {
+ float x = float(i) / float(sampCount);
+ float weight = gaussian_weight(x);
+ weight_accum += weight;
+ vec2 uv = uvcoordsvar.xy + ofs * x;
+ vec3 col = texture(colorBuf, uv).rgb;
+ if (threshold.x > -1.0) {
+ if (threshold.y > -1.0) {
+ if (all(lessThan(vec3(0.05), abs(col - threshold)))) {
+ weight = 0.0;
+ }
+ }
+ else {
+ if (dot(col, vec3(1.0 / 3.0)) < threshold.x) {
+ weight = 0.0;
+ }
+ }
+ }
+ fragColor.rgb += col * weight;
+ }
+
+ fragColor *= glowColor.rgbb / weight_accum;
+
+ if (useAlphaMode) {
+ /* Equivalent to alpha under. */
+ fragColor *= fragRevealage;
+ }
+
+ if (threshold.x == -1.0) {
+ /* Blend Mode is additive in 2nd pass. Don't modify revealage. */
+ fragRevealage = vec4(0.0);
+ }
+}
+
#elif defined(PIXELIZE)
uniform vec2 targetPixelSize;
More information about the Bf-blender-cvs
mailing list