[Bf-blender-cvs] [e83ad4671fb] temp-greasepencil-vfx: Refactor RIM FX to use Blur

Antonio Vazquez noreply at git.blender.org
Tue Jul 3 19:42:56 CEST 2018


Commit: e83ad4671fb4822c3ec61ad36621ec5aa6e256a3
Author: Antonio Vazquez
Date:   Tue Jul 3 19:30:09 2018 +0200
Branches: temp-greasepencil-vfx
https://developer.blender.org/rBe83ad4671fb4822c3ec61ad36621ec5aa6e256a3

Refactor RIM FX to use Blur

The RIM now is done in two passes and the rim can be blured.

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

M	source/blender/draw/CMakeLists.txt
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
R068	source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_rim_frag.glsl	source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_rim_prepare_frag.glsl
A	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/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index 6343a8825f3..367278c00ff 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -324,7 +324,8 @@ data_to_c_simple(engines/gpencil/shaders/fx/gpencil_fx_colorize_frag.glsl SRC)
 data_to_c_simple(engines/gpencil/shaders/fx/gpencil_fx_flip_frag.glsl SRC)
 data_to_c_simple(engines/gpencil/shaders/fx/gpencil_fx_light_frag.glsl SRC)
 data_to_c_simple(engines/gpencil/shaders/fx/gpencil_fx_pixel_frag.glsl SRC)
-data_to_c_simple(engines/gpencil/shaders/fx/gpencil_fx_rim_frag.glsl SRC)
+data_to_c_simple(engines/gpencil/shaders/fx/gpencil_fx_rim_prepare_frag.glsl SRC)
+data_to_c_simple(engines/gpencil/shaders/fx/gpencil_fx_rim_resolve_frag.glsl SRC)
 data_to_c_simple(engines/gpencil/shaders/fx/gpencil_fx_swirl_frag.glsl SRC)
 data_to_c_simple(engines/gpencil/shaders/fx/gpencil_fx_wave_frag.glsl SRC)
 
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index d70704fe095..5bf5d2455ae 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -133,6 +133,19 @@ static void GPENCIL_create_framebuffers(void *vedata)
 			GPU_ATTACHMENT_TEXTURE(e_data.temp_color_tx_b)
 			});
 
+		/* used for rim FX effect */
+		e_data.temp_depth_tx_rim = DRW_texture_pool_query_2D(size[0], size[1], GPU_DEPTH24_STENCIL8,
+			&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) */
 		e_data.background_depth_tx = DRW_texture_pool_query_2D(size[0], size[1], GPU_DEPTH24_STENCIL8,
 			&draw_engine_gpencil_type);
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index ac2eb2ca390..c381a9478e8 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -145,6 +145,7 @@ typedef struct GPENCIL_PassList {
 
 	/* effects */
 	struct DRWPass *fx_shader_pass;
+	struct DRWPass *fx_shader_pass_blend;
 
 } GPENCIL_PassList;
 
@@ -152,6 +153,7 @@ typedef struct GPENCIL_FramebufferList {
 	struct GPUFrameBuffer *main;
 	struct GPUFrameBuffer *temp_fb_a;
 	struct GPUFrameBuffer *temp_fb_b;
+	struct GPUFrameBuffer *temp_fb_rim;
 	struct GPUFrameBuffer *background_fb;
 
 	struct GPUFrameBuffer *multisample_fb;
@@ -225,7 +227,8 @@ typedef struct GPENCIL_e_data {
 	struct GPUShader *gpencil_fx_flip_sh;
 	struct GPUShader *gpencil_fx_light_sh;
 	struct GPUShader *gpencil_fx_pixel_sh;
-	struct GPUShader *gpencil_fx_rim_sh;
+	struct GPUShader *gpencil_fx_rim_prepare_sh;
+	struct GPUShader *gpencil_fx_rim_resolve_sh;
 	struct GPUShader *gpencil_fx_swirl_sh;
 	struct GPUShader *gpencil_fx_wave_sh;
 
@@ -242,9 +245,13 @@ typedef struct GPENCIL_e_data {
 	/* working textures */
 	struct GPUTexture *temp_color_tx_a;
 	struct GPUTexture *temp_depth_tx_a;
+
 	struct GPUTexture *temp_color_tx_b;
 	struct GPUTexture *temp_depth_tx_b;
 
+	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 4f7f97abd1d..a385a044b13 100644
--- a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
+++ b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
@@ -46,7 +46,8 @@ extern char datatoc_gpencil_fx_colorize_frag_glsl[];
 extern char datatoc_gpencil_fx_flip_frag_glsl[];
 extern char datatoc_gpencil_fx_light_frag_glsl[];
 extern char datatoc_gpencil_fx_pixel_frag_glsl[];
-extern char datatoc_gpencil_fx_rim_frag_glsl[];
+extern char datatoc_gpencil_fx_rim_prepare_frag_glsl[];
+extern char datatoc_gpencil_fx_rim_resolve_frag_glsl[];
 extern char datatoc_gpencil_fx_swirl_frag_glsl[];
 extern char datatoc_gpencil_fx_wave_frag_glsl[];
 
@@ -206,7 +207,8 @@ static void DRW_gpencil_fx_blur(
 
 	struct Gwn_Batch *fxquad = DRW_cache_fullscreen_quad_get();
 
-	fx_shgrp = DRW_shgroup_create(e_data->gpencil_fx_blur_sh, psl->fx_shader_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_a);
 	DRW_shgroup_uniform_texture_ref(fx_shgrp, "strokeDepth", &e_data->temp_depth_tx_a);
@@ -372,19 +374,20 @@ static void DRW_gpencil_fx_rim(
 
 	GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
 	GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl;
-	DRWShadingGroup *fx_shgrp;
+	DRWShadingGroup *fx_shgrp, *fx_shgrp_b;
 	bGPdata *gpd = (bGPdata *)ob->data;
 
 	struct Gwn_Batch *fxquad = DRW_cache_fullscreen_quad_get();
-	fx_shgrp = DRW_shgroup_create(e_data->gpencil_fx_rim_sh, psl->fx_shader_pass);
+	/* prepare pass */
+	fx_shgrp = DRW_shgroup_create(e_data->gpencil_fx_rim_prepare_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_a);
 	DRW_shgroup_uniform_texture_ref(fx_shgrp, "strokeDepth", &e_data->temp_depth_tx_a);
 	DRW_shgroup_uniform_int(fx_shgrp, "offset", &fxd->offset[0], 2);
-	DRW_shgroup_uniform_vec4(fx_shgrp, "rim_color", &fxd->rim_rgba[0], 1);
-	DRW_shgroup_uniform_vec4(fx_shgrp, "mask_color", &fxd->mask_rgba[0], 1);
+	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);
@@ -392,6 +395,23 @@ static void DRW_gpencil_fx_rim(
 	DRW_shgroup_uniform_float(fx_shgrp, "pixfactor", &gpd->pixfactor, 1);
 
 	fxd->runtime.fx_sh = fx_shgrp;
+
+	/* resolve pass */
+	fx_shgrp_b = 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, "mode", &fxd->mode, 1);
+	DRW_shgroup_uniform_int(fx_shgrp_b, "blur", &fxd->blur[0], 2);
+
+	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;
 }
 
 /* Swirl FX */
@@ -469,28 +489,39 @@ void GPENCIL_create_fx_shaders(GPENCIL_e_data *e_data)
 {
 	/* fx shaders (all in screen space) */
 	if (!e_data->gpencil_fx_blur_sh) {
-		e_data->gpencil_fx_blur_sh = DRW_shader_create_fullscreen(datatoc_gpencil_fx_blur_frag_glsl, NULL);
+		e_data->gpencil_fx_blur_sh = DRW_shader_create_fullscreen(
+			datatoc_gpencil_fx_blur_frag_glsl, NULL);
 	}
 	if (!e_data->gpencil_fx_colorize_sh) {
-		e_data->gpencil_fx_colorize_sh = DRW_shader_create_fullscreen(datatoc_gpencil_fx_colorize_frag_glsl, NULL);
+		e_data->gpencil_fx_colorize_sh = DRW_shader_create_fullscreen(
+			datatoc_gpencil_fx_colorize_frag_glsl, NULL);
 	}
 	if (!e_data->gpencil_fx_flip_sh) {
-		e_data->gpencil_fx_flip_sh = DRW_shader_create_fullscreen(datatoc_gpencil_fx_flip_frag_glsl, NULL);
+		e_data->gpencil_fx_flip_sh = DRW_shader_create_fullscreen(
+			datatoc_gpencil_fx_flip_frag_glsl, NULL);
 	}
 	if (!e_data->gpencil_fx_light_sh) {
-		e_data->gpencil_fx_light_sh = DRW_shader_create_fullscreen(datatoc_gpencil_fx_light_frag_glsl, NULL);
+		e_data->gpencil_fx_light_sh = DRW_shader_create_fullscreen(
+			datatoc_gpencil_fx_light_frag_glsl, NULL);
 	}
 	if (!e_data->gpencil_fx_pixel_sh) {
-		e_data->gpencil_fx_pixel_sh = DRW_shader_create_fullscreen(datatoc_gpencil_fx_pixel_frag_glsl, NULL);
+		e_data->gpencil_fx_pixel_sh = DRW_shader_create_fullscreen(
+			datatoc_gpencil_fx_pixel_frag_glsl, NULL);
 	}
-	if (!e_data->gpencil_fx_rim_sh) {
-		e_data->gpencil_fx_rim_sh = DRW_shader_create_fullscreen(datatoc_gpencil_fx_rim_frag_glsl, NULL);
+	if (!e_data->gpencil_fx_rim_prepare_sh) {
+		e_data->gpencil_fx_rim_prepare_sh = DRW_shader_create_fullscreen(
+			datatoc_gpencil_fx_rim_prepare_frag_glsl, NULL);
+
+		e_data->gpencil_fx_rim_resolve_sh = DRW_shader_create_fullscreen(
+			datatoc_gpencil_fx_rim_resolve_frag_glsl, NULL);
 	}
 	if (!e_data->gpencil_fx_swirl_sh) {
-		e_data->gpencil_fx_swirl_sh = DRW_shader_create_fullscreen(datatoc_gpencil_fx_swirl_frag_glsl, NULL);
+		e_data->gpencil_fx_swirl_sh = DRW_shader_create_fullscreen(
+			datatoc_gpencil_fx_swirl_frag_glsl, NULL);
 	}
 	if (!e_data->gpencil_fx_wave_sh) {
-		e_data->gpencil_fx_wave_sh = DRW_shader_create_fullscreen(datatoc_gpencil_fx_wave_frag_glsl, NULL);
+		e_data->gpencil_fx_wave_sh = DRW_shader_create_fullscreen(
+			datatoc_gpencil_fx_wave_frag_glsl, NULL);
 	}
 }
 
@@ -502,7 +533,8 @@ void GPENCIL_delete_fx_shaders(GPENCIL_e_data *e_data)
 	DRW_SHADER_FREE_SAFE(e_data->gpencil_fx_flip_sh);
 	DRW_SHADER_FREE_SAFE(e_data->gpencil_fx_light_sh);
 	DRW_SHADER_FREE_SAFE(e_data->gpencil_fx_pixel_sh);
-	DRW_SHADER_FREE_SAFE(e_data->gpencil_fx_rim_sh);
+	DRW_SHADER_FREE_SAFE(e_data->gpencil_fx_rim_prepare_sh);
+	DRW_SHADER_FREE_SAFE(e_data->gpencil_fx_rim_resolve_sh);
 	DRW_SHAD

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list