[Bf-blender-cvs] [dd793b21dac] greasepencil-object: GPencil: Fix Blend and Glow Under problems
Antonio Vazquez
noreply at git.blender.org
Mon Feb 17 18:59:01 CET 2020
Commit: dd793b21dacccaf6b1d24263ed7fb1b5648b590b
Author: Antonio Vazquez
Date: Mon Feb 17 18:58:55 2020 +0100
Branches: greasepencil-object
https://developer.blender.org/rBdd793b21dacccaf6b1d24263ed7fb1b5648b590b
GPencil: Fix Blend and Glow Under problems
===================================================================
M release/scripts/startup/bl_ui/properties_data_shaderfx.py
M source/blender/draw/engines/gpencil/gpencil_shader_fx.c
M source/blender/draw/engines/gpencil/shaders/gpencil_vfx_frag.glsl
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_data_shaderfx.py b/release/scripts/startup/bl_ui/properties_data_shaderfx.py
index 23b661cc61b..48a851e8bef 100644
--- a/release/scripts/startup/bl_ui/properties_data_shaderfx.py
+++ b/release/scripts/startup/bl_ui/properties_data_shaderfx.py
@@ -144,10 +144,7 @@ class DATA_PT_shader_fx(ShaderFxButtonsPanel, Panel):
layout.prop(fx, "rotation")
layout.prop(fx, "samples")
- if fx.blend_mode != 'REGULAR':
- layout.prop(fx, "use_glow_under", text="Glow Under")
- else:
- layout.label(text="Glow Under not supported in Regular blend", icon="ERROR")
+ layout.prop(fx, "use_glow_under", text="Glow Under")
def FX_SWIRL(self, layout, fx):
layout.prop(fx, "object", text="Object")
diff --git a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
index 4376e79585b..9467efcd18c 100644
--- a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
+++ b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
@@ -413,6 +413,7 @@ static void gpencil_vfx_shadow(ShadowShaderFxData *fx, Object *ob, gpIterVfxData
static void gpencil_vfx_glow(GlowShaderFxData *fx, Object *UNUSED(ob), gpIterVfxData *iter)
{
+ const bool use_glow_under = (fx->flag & FX_GLOW_USE_ALPHA) != 0;
DRWShadingGroup *grp;
const float s = sin(fx->rotation);
const float c = cos(fx->rotation);
@@ -436,7 +437,7 @@ 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_vec4_copy(grp, "glowColor", fx->glow_color);
- DRW_shgroup_uniform_bool_copy(grp, "glowUnder", false);
+ DRW_shgroup_uniform_bool_copy(grp, "glowUnder", use_glow_under);
DRW_shgroup_uniform_bool_copy(grp, "firstPass", true);
DRW_shgroup_call_procedural_triangles(grp, NULL, 1);
@@ -458,7 +459,9 @@ static void gpencil_vfx_glow(GlowShaderFxData *fx, Object *UNUSED(ob), gpIterVfx
break;
}
- if (fx->blend_mode == eGplBlendMode_Subtract) {
+ /* Small Hack: We ask for RGBA16F buffer if using use_glow_under to store original
+ * revealage in alpha channel. */
+ if (fx->blend_mode == eGplBlendMode_Subtract || use_glow_under) {
/* For this effect to propagate, we need a signed floating point buffer. */
iter->pd->use_signed_fb = true;
}
@@ -468,7 +471,6 @@ 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", (float[3]){-1.0f, -1.0f, -1.0f});
DRW_shgroup_uniform_vec4_copy(grp, "glowColor", (float[4]){1.0f, 1.0f, 1.0f, fx->glow_color[3]});
- 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 504fa6a8fb6..503248558ad 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_vfx_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_vfx_frag.glsl
@@ -188,19 +188,23 @@ void main()
}
fragRevealage = 1.0 - fragRevealage;
- 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 (glowUnder) {
+ if (firstPass) {
+ /* In first pass we copy the revealage buffer in the alpha channel.
+ * This let us do the alpha under in second pass. */
+ vec3 original_revealage = texture(revealBuf, uvcoordsvar.xy).rgb;
+ fragRevealage.a = clamp(dot(original_revealage.rgb, vec3(0.333334)), 0.0, 1.0);
+ }
+ else {
+ /* Recover original revealage. */
+ fragRevealage.a = texture(revealBuf, uvcoordsvar.xy).a;
+ }
}
if (!firstPass) {
fragColor.a = clamp(1.0 - dot(fragRevealage.rgb, vec3(0.333334)), 0.0, 1.0);
- blend_mode_output(blendMode, fragColor, glowColor.a, fragColor, fragRevealage);
+ fragRevealage.a *= glowColor.a;
+ blend_mode_output(blendMode, fragColor, fragRevealage.a, fragColor, fragRevealage);
}
}
More information about the Bf-blender-cvs
mailing list