[Bf-blender-cvs] [a4063358efe] greasepencil-object: GPencil: More changes to add Blend modes to Glow
Antonio Vazquez
noreply at git.blender.org
Sun Feb 16 20:08:32 CET 2020
Commit: a4063358efe0d1cf5b4b1dc9073833d659aea156
Author: Antonio Vazquez
Date: Sun Feb 16 20:07:13 2020 +0100
Branches: greasepencil-object
https://developer.blender.org/rBa4063358efe0d1cf5b4b1dc9073833d659aea156
GPencil: More changes to add Blend modes to Glow
Still not working.
===================================================================
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_shader.c b/source/blender/draw/engines/gpencil/gpencil_shader.c
index 523ede9428d..8c7ba42a70e 100644
--- a/source/blender/draw/engines/gpencil/gpencil_shader.c
+++ b/source/blender/draw/engines/gpencil/gpencil_shader.c
@@ -236,8 +236,24 @@ GPUShader *GPENCIL_shader_fx_composite_get(void)
GPUShader *GPENCIL_shader_fx_glow_get(void)
{
if (!g_shaders.fx_glow_sh) {
- g_shaders.fx_glow_sh = DRW_shader_create_fullscreen(datatoc_gpencil_vfx_frag_glsl,
- "#define GLOW\n");
+ g_shaders.fx_glow_sh = GPU_shader_create_from_arrays({
+ .vert =
+ (const char *[]){
+ datatoc_common_fullscreen_vert_glsl,
+ NULL,
+ },
+ .frag =
+ (const char *[]){
+ datatoc_gpencil_common_lib_glsl,
+ datatoc_gpencil_vfx_frag_glsl,
+ NULL,
+ },
+ .defs =
+ (const char *[]){
+ "#define GLOW\n",
+ NULL,
+ },
+ });
}
return g_shaders.fx_glow_sh;
}
diff --git a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
index ebf8aaefdc8..22838280ccf 100644
--- a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
+++ b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
@@ -437,18 +437,19 @@ static void gpencil_vfx_glow(GlowShaderFxData *fx, Object *UNUSED(ob), gpIterVfx
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_uniform_bool_copy(grp, "glowUnder", false);
+ DRW_shgroup_uniform_bool_copy(grp, "firstPass", true);
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[1] * s, fx->blur[1] * c});
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_uniform_bool_copy(grp, "glowUnder", (fx->flag & FX_GLOW_USE_ALPHA) != 0);
+ DRW_shgroup_uniform_bool_copy(grp, "firstPass", false);
+ DRW_shgroup_uniform_int_copy(grp, "blendMode", fx->blend_mode);
DRW_shgroup_call_procedural_triangles(grp, NULL, 1);
}
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 860dae08dde..8fb5edb3163 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_vfx_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_vfx_frag.glsl
@@ -146,7 +146,9 @@ uniform vec3 glowColor;
uniform vec2 offset;
uniform int sampCount;
uniform vec3 threshold;
-uniform bool useAlphaMode;
+uniform bool firstPass;
+uniform bool glowUnder;
+uniform int blendMode;
void main()
{
@@ -154,9 +156,7 @@ void main()
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);
+ fragRevealage = vec4(0.0);
float weight_accum = 0.0;
for (int i = -sampCount; i <= sampCount; i++) {
@@ -165,6 +165,7 @@ void main()
weight_accum += weight;
vec2 uv = uvcoordsvar.xy + ofs * x;
vec3 col = texture(colorBuf, uv).rgb;
+ vec3 rev = texture(revealBuf, uv).rgb;
if (threshold.x > -1.0) {
if (threshold.y > -1.0) {
if (all(lessThan(abs(col - threshold), vec3(0.05)))) {
@@ -178,18 +179,25 @@ void main()
}
}
fragColor.rgb += col * weight;
+ fragRevealage.rgb += (1.0 - rev) * weight;
}
fragColor *= glowColor.rgbb / weight_accum;
+ fragRevealage = 1.0 - fragRevealage / weight_accum;
- if (useAlphaMode) {
+ if (firstPass && glowUnder) {
+ /* In first pass we copy the reveal buffer. This let us do the alpha under if needed. */
+ fragRevealage = texture(revealBuf, uvcoordsvar.xy);
+ }
+
+ if (glowUnder && blendMode != MODE_REGULAR) {
/* 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);
+ if (!firstPass) {
+ fragColor.a = dot(fragRevealage.rgb, vec3(0.333334));
+ blend_mode_output(blendMode, fragColor, 1.0, fragColor, fragRevealage);
}
}
@@ -336,4 +344,4 @@ void main()
fragRevealage /= float(sampCount) * 2.0 + 1.0;
}
-#endif
\ No newline at end of file
+#endif
More information about the Bf-blender-cvs
mailing list