GP: Add Blur to Shadow FX

The shadow needed a blur to make soft transitions and get a better effect.
This commit is contained in:
Antonio Vazquez 2018-10-01 16:30:43 +02:00
parent c234c3db1b
commit a3afcae39e
5 changed files with 86 additions and 2 deletions

View File

@ -106,6 +106,10 @@ class DATA_PT_shader_fx(ShaderFxButtonsPanel, Panel):
layout.prop(fx, "scale")
layout.prop(fx, "rotation")
layout.separator()
layout.prop(fx, "blur")
layout.prop(fx, "samples")
layout.separator()
layout.prop(fx, "use_object", text="Use object as pivot")
if fx.use_object:

View File

@ -484,6 +484,21 @@ static void DRW_gpencil_fx_shadow(
fxd->runtime.fx_sh = fx_shgrp;
/* blur pass */
fx_shgrp = DRW_shgroup_create(
e_data->gpencil_fx_blur_sh,
psl->fx_shader_pass_blend);
DRW_shgroup_call_add(fx_shgrp, fxquad, NULL);
DRW_shgroup_uniform_texture_ref(fx_shgrp, "strokeColor", &e_data->temp_color_tx_fx);
DRW_shgroup_uniform_texture_ref(fx_shgrp, "strokeDepth", &e_data->temp_depth_tx_fx);
DRW_shgroup_uniform_int(fx_shgrp, "blur", &fxd->blur[0], 2);
DRW_shgroup_uniform_vec3(fx_shgrp, "loc", &cache->loc[0], 1);
DRW_shgroup_uniform_float(fx_shgrp, "pixsize", stl->storage->pixsize, 1);
DRW_shgroup_uniform_float(fx_shgrp, "pixfactor", &cache->pixfactor, 1);
fxd->runtime.fx_sh_b = fx_shgrp;
/* resolve pass */
fx_shgrp = DRW_shgroup_create(
e_data->gpencil_fx_shadow_resolve_sh,
@ -494,7 +509,7 @@ static void DRW_gpencil_fx_shadow(
DRW_shgroup_uniform_texture_ref(fx_shgrp, "shadowColor", &e_data->temp_color_tx_fx);
DRW_shgroup_uniform_texture_ref(fx_shgrp, "shadowDepth", &e_data->temp_depth_tx_fx);
fxd->runtime.fx_sh_b = fx_shgrp;
fxd->runtime.fx_sh_c = fx_shgrp;
}
/* Swirl FX */
@ -832,6 +847,7 @@ static void draw_gpencil_rim_passes(
fxd->blur[1] = by;
}
}
/* resolve */
GPU_framebuffer_bind(fbl->temp_fb_b);
GPU_framebuffer_clear_color_depth(fbl->temp_fb_b, clearcol, 1.0f);
@ -848,6 +864,27 @@ static void draw_gpencil_rim_passes(
DRW_draw_pass(psl->mix_pass_noblend);
}
/* blur shadow */
static void draw_gpencil_shadow_blur(
struct GPENCIL_e_data *UNUSED(e_data),
struct GPENCIL_Data *vedata,
struct ShadowShaderFxData *fxd)
{
GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl;
GPENCIL_FramebufferList *fbl = ((GPENCIL_Data *)vedata)->fbl;
static float clearcol[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
GPU_framebuffer_bind(fbl->temp_fb_b);
GPU_framebuffer_clear_color_depth(fbl->temp_fb_b, clearcol, 1.0f);
DRW_draw_pass_subset(psl->fx_shader_pass_blend,
fxd->runtime.fx_sh_b, fxd->runtime.fx_sh_b);
/* copy pass from b for ping-pong frame buffers */
GPU_framebuffer_bind(fbl->temp_fb_fx);
GPU_framebuffer_clear_color_depth(fbl->temp_fb_fx, clearcol, 1.0f);
DRW_draw_pass(psl->mix_pass_noblend);
}
/* helper to draw SHADOW passes */
static void draw_gpencil_shadow_passes(
struct GPENCIL_e_data *e_data,
@ -862,6 +899,8 @@ static void draw_gpencil_shadow_passes(
GPENCIL_FramebufferList *fbl = ((GPENCIL_Data *)vedata)->fbl;
static float clearcol[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
int bx = fxd->blur[0];
int by = fxd->blur[1];
/* prepare shadow */
GPU_framebuffer_bind(fbl->temp_fb_fx);
@ -870,12 +909,34 @@ static void draw_gpencil_shadow_passes(
psl->fx_shader_pass_blend,
fxd->runtime.fx_sh, fxd->runtime.fx_sh);
/* blur shadow */
e_data->input_depth_tx = e_data->temp_depth_tx_b;
e_data->input_color_tx = e_data->temp_color_tx_b;
if ((fxd->samples > 0) && ((bx > 0) || (by > 0))) {
for (int x = 0; x < fxd->samples; x++) {
/* horizontal */
fxd->blur[0] = bx;
fxd->blur[1] = 0;
draw_gpencil_shadow_blur(e_data, vedata, fxd);
/* Vertical */
fxd->blur[0] = 0;
fxd->blur[1] = by;
draw_gpencil_shadow_blur(e_data, vedata, fxd);
fxd->blur[0] = bx;
fxd->blur[1] = by;
}
}
/* resolve */
GPU_framebuffer_bind(fbl->temp_fb_b);
GPU_framebuffer_clear_color_depth(fbl->temp_fb_b, clearcol, 1.0f);
DRW_draw_pass_subset(
psl->fx_shader_pass_blend,
fxd->runtime.fx_sh_b, fxd->runtime.fx_sh_b);
fxd->runtime.fx_sh_c, fxd->runtime.fx_sh_c);
/* copy pass from b to a for ping-pong frame buffers */
e_data->input_depth_tx = e_data->temp_depth_tx_b;

View File

@ -182,6 +182,9 @@ typedef struct ShadowShaderFxData {
int orientation;
float scale[2];
float rotation;
int blur[2];
int samples;
char pad[4];
ShaderFxData_runtime runtime;
} ShadowShaderFxData;

View File

@ -458,6 +458,20 @@ static void rna_def_shader_fx_shadow(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Rotation", "Rotation around center or object");
RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, "rna_ShaderFx_update");
prop = RNA_def_property(srna, "blur", PROP_INT, PROP_PIXEL);
RNA_def_property_int_sdna(prop, NULL, "blur");
RNA_def_property_range(prop, 0, INT_MAX);
RNA_def_property_ui_text(prop, "Blur", "Number of pixels for bluring shadow (set to 0 to disable)");
RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, "rna_ShaderFx_update");
prop = RNA_def_property(srna, "samples", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "samples");
RNA_def_property_range(prop, 0, 32);
RNA_def_property_ui_range(prop, 0, 32, 2, -1);
RNA_def_property_int_default(prop, 4);
RNA_def_property_ui_text(prop, "Samples", "Number of Blur Samples (zero, disable blur)");
RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, "rna_ShaderFx_update");
prop = RNA_def_property(srna, "use_object", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", FX_SHADOW_USE_OBJECT);
RNA_def_property_ui_text(prop, "Use Object", "Use object as center of rotation");

View File

@ -58,6 +58,8 @@ static void initData(ShaderFxData *md)
gpfx->period = 20.0f;
gpfx->phase = 0.0f;
gpfx->orientation = 1;
ARRAY_SET_ITEMS(gpfx->blur, 0, 0);
}
static void copyData(const ShaderFxData *md, ShaderFxData *target)