[Bf-blender-cvs] [3520b3379c2] greasepencil-refactor: GPencil: Refactor: FX: make the Blur not dependant on sampling parameter
Clément Foucault
noreply at git.blender.org
Wed Dec 18 03:14:27 CET 2019
Commit: 3520b3379c2958c03e7b247b58bf7cb447db4d6c
Author: Clément Foucault
Date: Tue Dec 17 15:33:42 2019 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rB3520b3379c2958c03e7b247b58bf7cb447db4d6c
GPencil: Refactor: FX: make the Blur not dependant on sampling parameter
The sampling parameter was in fact use as iteration step count in previous
implementation. New behavior is much more consistent and predicatble
===================================================================
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_fx.c b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
index a5264c24d09..a06868a1096 100644
--- a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
+++ b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
@@ -1111,10 +1111,12 @@ static void gpencil_vfx_blur(BlurShaderFxData *fx, Object *UNUSED(ob), gpIterVfx
DRWState state = DRW_STATE_WRITE_COLOR;
grp = gpencil_vfx_pass_create("Fx Blur H", state, iter, sh);
DRW_shgroup_uniform_vec2_copy(grp, "offset", (float[2]){fx->radius[0], 0.0f});
+ DRW_shgroup_uniform_int_copy(grp, "sampCount", max_ii(1, min_ii(fx->samples, fx->radius[0])));
DRW_shgroup_call_procedural_triangles(grp, NULL, 1);
grp = gpencil_vfx_pass_create("Fx Blur V", state, iter, sh);
DRW_shgroup_uniform_vec2_copy(grp, "offset", (float[2]){0.0f, fx->radius[1]});
+ DRW_shgroup_uniform_int_copy(grp, "sampCount", max_ii(1, min_ii(fx->samples, fx->radius[1])));
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 8c891bc9d72..74102f9e550 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_vfx_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_vfx_frag.glsl
@@ -31,6 +31,12 @@ void main()
#elif defined(BLUR)
uniform vec2 offset;
+uniform int sampCount;
+
+float gaussian_weight(float x)
+{
+ return exp(-x * x / (2.0 * 0.35 * 0.35));
+}
void main()
{
@@ -41,16 +47,17 @@ void main()
fragRevealage = vec4(0.0);
/* No blending. */
- fragColor.rgb += texture(colorBuf, uvcoordsvar.xy - ofs).rgb;
- fragColor.rgb += texture(colorBuf, uvcoordsvar.xy).rgb;
- fragColor.rgb += texture(colorBuf, uvcoordsvar.xy + ofs).rgb;
-
- fragRevealage.rgb += texture(revealBuf, uvcoordsvar.xy - ofs).rgb;
- fragRevealage.rgb += texture(revealBuf, uvcoordsvar.xy).rgb;
- fragRevealage.rgb += texture(revealBuf, uvcoordsvar.xy + ofs).rgb;
+ 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;
+ fragColor.rgb += texture(colorBuf, uvcoordsvar.xy - ofs * x).rgb * weight;
+ fragRevealage.rgb += texture(revealBuf, uvcoordsvar.xy - ofs * x).rgb * weight;
+ }
- fragColor *= (1.0 / 3.0);
- fragRevealage *= (1.0 / 3.0);
+ fragColor /= weight_accum;
+ fragRevealage /= weight_accum;
}
#endif
\ No newline at end of file
More information about the Bf-blender-cvs
mailing list