[Bf-blender-cvs] [13c79692e33] temp-greasepencil-vfx: More changes to Blur effect
Antonio Vazquez
noreply at git.blender.org
Wed Jun 27 13:37:30 CEST 2018
Commit: 13c79692e337e606e02b1407100d2881b1d84228
Author: Antonio Vazquez
Date: Wed Jun 27 13:37:22 2018 +0200
Branches: temp-greasepencil-vfx
https://developer.blender.org/rB13c79692e337e606e02b1407100d2881b1d84228
More changes to Blur effect
Still there are problems
===================================================================
M source/blender/draw/engines/gpencil/gpencil_engine.c
M source/blender/draw/engines/gpencil/gpencil_shader_fx.c
M source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_blur_frag.glsl
===================================================================
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 5fbd5e1dbe9..f1d5a291a3c 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -93,7 +93,7 @@ void DRW_gpencil_multisample_ensure(GPENCIL_Data *vedata, int rect_w, int rect_h
fbl->multisample_fb = GPU_framebuffer_create();
if (fbl->multisample_fb) {
if (txl->multisample_color == NULL) {
- txl->multisample_color = GPU_texture_create_2D_multisample(rect_w, rect_h, GPU_RGBA8, NULL, samples, NULL);
+ txl->multisample_color = GPU_texture_create_2D_multisample(rect_w, rect_h, GPU_RGBA32F, NULL, samples, NULL);
}
if (txl->multisample_depth == NULL) {
txl->multisample_depth = GPU_texture_create_2D_multisample(rect_w, rect_h, GPU_DEPTH24_STENCIL8, NULL, samples, NULL);
diff --git a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
index e007acc3c09..11b21dd1f8e 100644
--- a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
+++ b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
@@ -475,11 +475,48 @@ static void gpencil_draw_fx_pass(GPENCIL_e_data *e_data,
/* copy pass from b to a for ping-pong frame buffers */
e_data->input_depth_tx = e_data->temp_depth_tx_b;
e_data->input_color_tx = e_data->temp_color_tx_b;
+
+ /* do not need clear output because makes a full copy
+ * and replace al pixels */
GPU_framebuffer_bind(fbl->temp_fb_a);
- GPU_framebuffer_clear_color_depth(fbl->temp_fb_a, clearcol, 1.0f);
DRW_draw_pass(copypass);
}
+/* helper to manage gaussian blur passes */
+static void gpencil_blur_passes(struct GPENCIL_e_data *e_data,
+ struct GPENCIL_Data *vedata,
+ struct tGPencilObjectCache *cache)
+{
+ GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
+ GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl;
+ GPENCIL_FramebufferList *fbl = ((GPENCIL_Data *)vedata)->fbl;
+ Object *ob = cache->ob;
+ int ob_idx = cache->idx;
+ int samples = stl->fx[ob_idx].fx_blur.samples;
+
+ float bx = stl->fx[ob_idx].fx_blur.radius[0];
+ float by = stl->fx[ob_idx].fx_blur.radius[1];
+
+ for (int b = 0; b < samples; b++) {
+ /* horizontal */
+ if (bx > 0) {
+ stl->fx[ob_idx].fx_blur.radius[0] = bx;
+ stl->fx[ob_idx].fx_blur.radius[1] = 0;
+ gpencil_draw_fx_pass(e_data, psl->fx_blur_pass,
+ psl->mix_pass_noblend,
+ fbl, cache->fx_blur_sh);
+ }
+ /* vertical */
+ if (by > 0) {
+ stl->fx[ob_idx].fx_blur.radius[0] = 0;
+ stl->fx[ob_idx].fx_blur.radius[1] = by;
+ gpencil_draw_fx_pass(e_data, psl->fx_blur_pass,
+ psl->mix_pass_noblend,
+ fbl, cache->fx_blur_sh);
+ }
+ }
+}
+
/* apply all object fx effects */
void DRW_gpencil_fx_draw(struct GPENCIL_e_data *e_data,
struct GPENCIL_Data *vedata, struct tGPencilObjectCache *cache)
@@ -496,29 +533,7 @@ void DRW_gpencil_fx_draw(struct GPENCIL_e_data *e_data,
switch (md->type) {
case eShaderFxType_Blur:
if (cache->fx_blur_sh) {
- int samples = stl->fx[ob_idx].fx_blur.samples;
- /* be sure is even */
- if (samples % 2 != 0) {
- samples++;
- }
-
- float bx = stl->fx[ob_idx].fx_blur.radius[0];
- float by = stl->fx[ob_idx].fx_blur.radius[1];
-
- for (int b = 0; b < samples; b++) {
- /* horizontal */
- stl->fx[ob_idx].fx_blur.radius[0] = bx;
- stl->fx[ob_idx].fx_blur.radius[1] = 0;
- gpencil_draw_fx_pass(e_data, psl->fx_blur_pass,
- psl->mix_pass_noblend,
- fbl, cache->fx_blur_sh);
- /* vertical */
- stl->fx[ob_idx].fx_blur.radius[0] = 0;
- stl->fx[ob_idx].fx_blur.radius[1] = by;
- gpencil_draw_fx_pass(e_data, psl->fx_blur_pass,
- psl->mix_pass_noblend,
- fbl, cache->fx_blur_sh);
- }
+ gpencil_blur_passes(e_data, vedata, cache);
}
break;
case eShaderFxType_Flip:
diff --git a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_blur_frag.glsl b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_blur_frag.glsl
index 7df4e6d90b3..130db38083b 100644
--- a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_blur_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_blur_frag.glsl
@@ -9,11 +9,25 @@ uniform vec2 blur;
void main()
{
ivec2 uv = ivec2(gl_FragCoord.xy);
- float stroke_depth = texelFetch(strokeDepth, uv, 0).r;
- gl_FragDepth = stroke_depth;
+ /* apply blurring, using a 9-tap filter with predefined gaussian weights */
+ /* depth */
+ float outdepth = 0;
+ outdepth += texelFetch(strokeDepth, ivec2(uv.x - 1.0 * blur[0], uv.y + 1.0 * blur[1]), 0).r * 0.0947416;
+ outdepth += texelFetch(strokeDepth, ivec2(uv.x - 0.0 * blur[0], uv.y + 1.0 * blur[1]), 0).r * 0.118318;
+ outdepth += texelFetch(strokeDepth, ivec2(uv.x + 1.0 * blur[0], uv.y + 1.0 * blur[1]), 0).r * 0.0947416;
+ outdepth += texelFetch(strokeDepth, ivec2(uv.x - 1.0 * blur[0], uv.y + 0.0 * blur[1]), 0).r * 0.118318;
+
+ outdepth += texelFetch(strokeDepth, ivec2(uv.x, uv.y), 0).r * 0.147761;
+
+ outdepth += texelFetch(strokeDepth, ivec2(uv.x + 1.0 * blur[0], uv.y + 0.0 * blur[1]), 0).r * 0.118318;
+ outdepth += texelFetch(strokeDepth, ivec2(uv.x - 1.0 * blur[0], uv.y - 1.0 * blur[1]), 0).r * 0.0947416;
+ outdepth += texelFetch(strokeDepth, ivec2(uv.x + 0.0 * blur[0], uv.y - 1.0 * blur[1]), 0).r * 0.118318;
+ outdepth += texelFetch(strokeDepth, ivec2(uv.x + 1.0 * blur[0], uv.y - 1.0 * blur[1]), 0).r * 0.0947416;
+ gl_FragDepth = outdepth;
+
+ /* color */
vec4 outcolor = vec4(0.0);
- /* apply blurring, using a 9-tap filter with predefined gaussian weights */
outcolor += texelFetch(strokeColor, ivec2(uv.x - 1.0 * blur[0], uv.y + 1.0 * blur[1]), 0) * 0.0947416;
outcolor += texelFetch(strokeColor, ivec2(uv.x - 0.0 * blur[0], uv.y + 1.0 * blur[1]), 0) * 0.118318;
outcolor += texelFetch(strokeColor, ivec2(uv.x + 1.0 * blur[0], uv.y + 1.0 * blur[1]), 0) * 0.0947416;
@@ -26,5 +40,5 @@ void main()
outcolor += texelFetch(strokeColor, ivec2(uv.x + 0.0 * blur[0], uv.y - 1.0 * blur[1]), 0) * 0.118318;
outcolor += texelFetch(strokeColor, ivec2(uv.x + 1.0 * blur[0], uv.y - 1.0 * blur[1]), 0) * 0.0947416;
- FragColor = outcolor;
+ FragColor = clamp(outcolor, 0, 1.0);
}
More information about the Bf-blender-cvs
mailing list