[Bf-blender-cvs] [ad0a8fb1882] temp-greasepencil-vfx: Redo Rim FX Blur

Antonio Vazquez noreply at git.blender.org
Thu Jul 5 19:38:52 CEST 2018


Commit: ad0a8fb1882b1e9fdec5e280aceb8145c540e3aa
Author: Antonio Vazquez
Date:   Thu Jul 5 19:38:29 2018 +0200
Branches: temp-greasepencil-vfx
https://developer.blender.org/rBad0a8fb1882b1e9fdec5e280aceb8145c540e3aa

Redo Rim FX Blur

The previous implementation was doing the blur in the wrong step and the result was very bad.

Now, the Rim mask is blured before blending with the final image.

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

M	release/scripts/startup/bl_ui/properties_data_shaderfx.py
M	source/blender/draw/engines/gpencil/gpencil_engine.c
M	source/blender/draw/engines/gpencil/gpencil_engine.h
M	source/blender/draw/engines/gpencil/gpencil_shader_fx.c
M	source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_rim_prepare_frag.glsl
M	source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_rim_resolve_frag.glsl
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_rim.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_shaderfx.py b/release/scripts/startup/bl_ui/properties_data_shaderfx.py
index 7b1d28c767d..5010f56d234 100644
--- a/release/scripts/startup/bl_ui/properties_data_shaderfx.py
+++ b/release/scripts/startup/bl_ui/properties_data_shaderfx.py
@@ -104,7 +104,6 @@ class DATA_PT_shader_fx(ShaderFxButtonsPanel, Panel):
         layout.prop(fx, "mode")
         layout.prop(fx, "blur")
         layout.prop(fx, "samples")
-        layout.prop(fx, "blurrines")
 
     def FX_SWIRL(self, layout, fx):
         layout.prop(fx, "object", text="Object")
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 5bf5d2455ae..1baaea96896 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -138,12 +138,9 @@ static void GPENCIL_create_framebuffers(void *vedata)
 			&draw_engine_gpencil_type);
 		e_data.temp_color_tx_rim = DRW_texture_pool_query_2D(size[0], size[1], fb_format,
 			&draw_engine_gpencil_type);
-		e_data.temp_mask_tx_rim = DRW_texture_pool_query_2D(size[0], size[1], GPU_RGBA8,
-			&draw_engine_gpencil_type);
 		GPU_framebuffer_ensure_config(&fbl->temp_fb_rim, {
 			GPU_ATTACHMENT_TEXTURE(e_data.temp_depth_tx_rim),
 			GPU_ATTACHMENT_TEXTURE(e_data.temp_color_tx_rim),
-			GPU_ATTACHMENT_TEXTURE(e_data.temp_mask_tx_rim)
 			});
 
 		/* background framebuffer to speed up drawing process (always 16 bits) */
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index c381a9478e8..7895fd1c8a8 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -251,7 +251,6 @@ typedef struct GPENCIL_e_data {
 
 	struct GPUTexture *temp_color_tx_rim;
 	struct GPUTexture *temp_depth_tx_rim;
-	struct GPUTexture *temp_mask_tx_rim;
 } GPENCIL_e_data; /* Engine data */
 
 /* Gwn_Batch Cache */
diff --git a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
index 4e471df015c..b71c7d42081 100644
--- a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
+++ b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
@@ -374,7 +374,7 @@ static void DRW_gpencil_fx_rim(
 
 	GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
 	GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl;
-	DRWShadingGroup *fx_shgrp, *fx_shgrp_b;
+	DRWShadingGroup *fx_shgrp;
 	bGPdata *gpd = (bGPdata *)ob->data;
 
 	struct Gwn_Batch *fxquad = DRW_cache_fullscreen_quad_get();
@@ -387,8 +387,6 @@ static void DRW_gpencil_fx_rim(
 	DRW_shgroup_uniform_int(fx_shgrp, "offset", &fxd->offset[0], 2);
 	DRW_shgroup_uniform_vec3(fx_shgrp, "rim_color", &fxd->rim_rgb[0], 1);
 	DRW_shgroup_uniform_vec3(fx_shgrp, "mask_color", &fxd->mask_rgb[0], 1);
-	DRW_shgroup_uniform_int(fx_shgrp, "mode", &fxd->mode, 1);
-	DRW_shgroup_uniform_int(fx_shgrp, "blur", &fxd->blur[0], 2);
 
 	DRW_shgroup_uniform_vec3(fx_shgrp, "loc", &ob->loc[0], 1);
 	DRW_shgroup_uniform_float(fx_shgrp, "pixsize", stl->storage->pixsize, 1);
@@ -397,21 +395,27 @@ static void DRW_gpencil_fx_rim(
 
 	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_rim);
+	DRW_shgroup_uniform_texture_ref(fx_shgrp, "strokeDepth", &e_data->temp_depth_tx_rim);
+	DRW_shgroup_uniform_int(fx_shgrp, "blur", &fxd->blur[0], 2);
+
+	fxd->runtime.fx_sh_b = fx_shgrp;
+
 	/* resolve pass */
-	fx_shgrp_b = DRW_shgroup_create(e_data->gpencil_fx_rim_resolve_sh,
+	fx_shgrp = DRW_shgroup_create(e_data->gpencil_fx_rim_resolve_sh,
 								psl->fx_shader_pass_blend);
-	DRW_shgroup_call_add(fx_shgrp_b, fxquad, NULL);
-	DRW_shgroup_uniform_texture_ref(fx_shgrp_b, "strokeColor", &e_data->input_color_tx);
-	DRW_shgroup_uniform_texture_ref(fx_shgrp_b, "strokeDepth", &e_data->input_depth_tx);
-	DRW_shgroup_uniform_texture_ref(fx_shgrp_b, "strokeMask", &e_data->temp_mask_tx_rim);
-	DRW_shgroup_uniform_int(fx_shgrp_b, "blurrines", &fxd->blur_pixels, 1);
-
-	DRW_shgroup_uniform_vec3(fx_shgrp_b, "loc", &ob->loc[0], 1);
-	DRW_shgroup_uniform_float(fx_shgrp_b, "pixsize", stl->storage->pixsize, 1);
-	DRW_shgroup_uniform_float(fx_shgrp_b, "pixelsize", &U.pixelsize, 1);
-	DRW_shgroup_uniform_float(fx_shgrp_b, "pixfactor", &gpd->pixfactor, 1);
-
-	fxd->runtime.fx_sh_b = fx_shgrp_b;
+	DRW_shgroup_call_add(fx_shgrp, fxquad, NULL);
+	DRW_shgroup_uniform_texture_ref(fx_shgrp, "strokeColor", &e_data->temp_color_tx_a);
+	DRW_shgroup_uniform_texture_ref(fx_shgrp, "strokeDepth", &e_data->temp_depth_tx_a);
+	DRW_shgroup_uniform_texture_ref(fx_shgrp, "strokeRim", &e_data->temp_color_tx_rim);
+	DRW_shgroup_uniform_vec3(fx_shgrp, "mask_color", &fxd->mask_rgb[0], 1);
+	DRW_shgroup_uniform_int(fx_shgrp, "mode", &fxd->mode, 1);
+
+	fxd->runtime.fx_sh_c = fx_shgrp;
 }
 
 /* Swirl FX */
@@ -672,6 +676,25 @@ static void draw_gpencil_blur_passes(struct GPENCIL_e_data *e_data,
 	}
 }
 
+static void draw_gpencil_rim_blur(struct GPENCIL_e_data *e_data,
+								struct GPENCIL_Data *vedata,
+								struct RimShaderFxData *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_rim);
+	GPU_framebuffer_clear_color_depth(fbl->temp_fb_rim, clearcol, 1.0f);
+	DRW_draw_pass(psl->mix_pass_noblend);
+}
+
 /* helper to draw RIM passes */
 static void draw_gpencil_rim_passes(struct GPENCIL_e_data *e_data,
 									struct GPENCIL_Data *vedata,
@@ -688,78 +711,46 @@ static void draw_gpencil_rim_passes(struct GPENCIL_e_data *e_data,
 	int bx = fxd->blur[0];
 	int by = fxd->blur[1];
 
-	/* prepare image and mask */
+	/* prepare mask */
 	GPU_framebuffer_bind(fbl->temp_fb_rim);
 	GPU_framebuffer_clear_color_depth(fbl->temp_fb_rim, clearcol, 1.0f);
 	DRW_draw_pass_subset(psl->fx_shader_pass_blend,
 						fxd->runtime.fx_sh, fxd->runtime.fx_sh);
 
-	/* resolve */
-	if ((fxd->samples == 0) || ((bx == 0) && (by == 0))) {
-		e_data->input_depth_tx = e_data->temp_depth_tx_rim;
-		e_data->input_color_tx = e_data->temp_color_tx_rim;
-
-		GPU_framebuffer_bind(fbl->temp_fb_a);
-		GPU_framebuffer_clear_color_depth(fbl->temp_fb_a, clearcol, 1.0f);
-		DRW_draw_pass(psl->mix_pass_noblend);
+	/* blur rim */
+	e_data->input_depth_tx = e_data->temp_depth_tx_b;
+	e_data->input_color_tx = e_data->temp_color_tx_b;
 
-	}
-	else {
+	if ((fxd->samples > 0) && ((bx > 0) || (by > 0))) {
 		for (int x = 0; x < fxd->samples; x++) {
-			GPU_framebuffer_bind(fbl->temp_fb_b);
-			GPU_framebuffer_clear_color_depth(fbl->temp_fb_b, clearcol, 1.0f);
 
-			/* horizontal (always) */
+			/* horizontal */
 			fxd->blur[0] = bx;
 			fxd->blur[1] = 0;
+			draw_gpencil_rim_blur(e_data, vedata, fxd);
 
-			/* only the first loop must use the original rim output textures */
-			if (x == 0) {
-				e_data->input_depth_tx = e_data->temp_depth_tx_rim;
-				e_data->input_color_tx = e_data->temp_color_tx_rim;
-			}
-			else {
-				e_data->input_depth_tx = e_data->temp_depth_tx_a;
-				e_data->input_color_tx = e_data->temp_color_tx_a;
-			}
-
-			DRW_draw_pass_subset(psl->fx_shader_pass_blend,
-				fxd->runtime.fx_sh_b, fxd->runtime.fx_sh_b);
-			/* 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;
-
-			GPU_framebuffer_bind(fbl->temp_fb_a);
-			GPU_framebuffer_clear_color_depth(fbl->temp_fb_a, clearcol, 1.0f);
-			DRW_draw_pass(psl->mix_pass_noblend);
-
-			/* vertical if blur */
-			if (by > 0) {
-				GPU_framebuffer_bind(fbl->temp_fb_b);
-				GPU_framebuffer_clear_color_depth(fbl->temp_fb_b, clearcol, 1.0f);
-
-				fxd->blur[0] = 0;
-				fxd->blur[1] = by;
-
-				e_data->input_depth_tx = e_data->temp_depth_tx_a;
-				e_data->input_color_tx = e_data->temp_color_tx_a;
-
-				DRW_draw_pass_subset(psl->fx_shader_pass_blend,
-					fxd->runtime.fx_sh_b, fxd->runtime.fx_sh_b);
-
-				fxd->blur[0] = bx;
-				fxd->blur[1] = by;
-
-				/* 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;
+			/* Vertical */
+			fxd->blur[0] = 0;
+			fxd->blur[1] = by;
+			draw_gpencil_rim_blur(e_data, vedata, fxd);
 
-				GPU_framebuffer_bind(fbl->temp_fb_a);
-				GPU_framebuffer_clear_color_depth(fbl->temp_fb_a, clearcol, 1.0f);
-				DRW_draw_pass(psl->mix_pass_noblend);
-			}
+			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_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;
+	e_data->input_color_tx = e_data->temp_color_tx_b;
+
+	GPU_framebuffer_bind(fbl->temp_fb_a);
+	GPU_framebuffer_clear_color_depth(fbl->temp_fb_a, clearcol, 1.0f);
+	DRW_draw_pass(psl->mix_pass_noblend);
 }
 
 /* apply all object fx effects */
@@ -808,7 +799,6 @@ void DRW_gpencil_fx_draw(struct GPENCIL_e_data *e_data,
 				case eShaderFxType_Rim:
 				{
 					RimShaderFxData *fxd = (RimShaderFxData *)fx;
-					gpencil_draw_fx_pass(e_data, psl, fbl, fxd->runtime.fx_sh, false);
 					draw_gpencil_rim_passes(e_data, vedata, fxd);
 					break;
 				}
diff --git a/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_rim_prepare_frag.glsl b/source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_rim_prepare_frag.glsl
index 97b41516d1a..6807a07d6c9 100644
--- a/source/blender/draw/engines/gpe

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list