[Bf-blender-cvs] [a3afcae39ed] blender2.8: GP: Add Blur to Shadow FX

Antonioya noreply at git.blender.org
Mon Oct 1 16:31:12 CEST 2018


Commit: a3afcae39ed03e0d62087992dac0b64f1a2a3138
Author: Antonioya
Date:   Mon Oct 1 16:30:43 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBa3afcae39ed03e0d62087992dac0b64f1a2a3138

GP: Add Blur to Shadow FX

The shadow needed a blur to make soft transitions and get a better effect.

===================================================================

M	release/scripts/startup/bl_ui/properties_data_shaderfx.py
M	source/blender/draw/engines/gpencil/gpencil_shader_fx.c
M	source/blender/makesdna/DNA_shader_fx_types.h
M	source/blender/makesrna/intern/rna_shader_fx.c
M	source/blender/shader_fx/intern/FX_shader_shadow.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/properties_data_shaderfx.py b/release/scripts/startup/bl_ui/properties_data_shaderfx.py
index f1372f4b2c3..fdb962aab68 100644
--- a/release/scripts/startup/bl_ui/properties_data_shaderfx.py
+++ b/release/scripts/startup/bl_ui/properties_data_shaderfx.py
@@ -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:
diff --git a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
index 49629c72444..9e04365fe1d 100644
--- a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
+++ b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
@@ -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;
diff --git a/source/blender/makesdna/DNA_shader_fx_types.h b/source/blender/makesdna/DNA_shader_fx_types.h
index 62a1d705f3b..8c124b8837a 100644
--- a/source/blender/makesdna/DNA_shader_fx_types.h
+++ b/source/blender/makesdna/DNA_shader_fx_types.h
@@ -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;
 
diff --git a/source/blender/makesrna/intern/rna_shader_fx.c b/source/blender/makesrna/intern/rna_shader_fx.c
index 97acc47f2f4..22ebd3f7567 100644
--- a/source/blender/makesrna/intern/rna_shader_fx.c
+++ b/source/blender/makesrna/intern/rna_shader_fx.c
@@ -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");
diff --git a/source/blender/shader_fx/intern/FX_shader_shadow.c b/source/blender/shader_fx/intern/FX_shader_shadow.c
index d0a2ffd4590..8d4c34b5864 100644
--- a/source/blender/shader_fx/intern/FX_shader_shadow.c
+++ b/source/blender/shader_fx/intern/FX_shader_shadow.c
@@ -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)



More information about the Bf-blender-cvs mailing list