[Bf-blender-cvs] [c2519d85216] blender2.8: GP: New Glow Shader FX (wip)

Antonioya noreply at git.blender.org
Wed Oct 10 23:06:48 CEST 2018


Commit: c2519d8521687a802ce6cb6e9ca2e973693cf9a4
Author: Antonioya
Date:   Wed Oct 10 22:52:55 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBc2519d8521687a802ce6cb6e9ca2e973693cf9a4

GP: New Glow Shader FX (wip)

New shader to simulate a glow of the color.

The glow can be generated by luminance threshold or using a selection color.

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

M	release/scripts/startup/bl_ui/properties_data_shaderfx.py
M	source/blender/draw/CMakeLists.txt
M	source/blender/draw/engines/gpencil/gpencil_engine.h
M	source/blender/draw/engines/gpencil/gpencil_shader_fx.c
A	source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_glow_prepare_frag.glsl
A	source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_glow_resolve_frag.glsl
M	source/blender/makesdna/DNA_shader_fx_types.h
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/intern/rna_shader_fx.c
M	source/blender/shader_fx/CMakeLists.txt
M	source/blender/shader_fx/FX_shader_types.h
M	source/blender/shader_fx/intern/FX_shader_util.c
A	source/blender/shader_fx/intern/fx_shader_glow.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_shaderfx.py b/release/scripts/startup/bl_ui/properties_data_shaderfx.py
index fdb962aab68..8b4bd03bc6d 100644
--- a/release/scripts/startup/bl_ui/properties_data_shaderfx.py
+++ b/release/scripts/startup/bl_ui/properties_data_shaderfx.py
@@ -125,6 +125,19 @@ class DATA_PT_shader_fx(ShaderFxButtonsPanel, Panel):
             layout.prop(fx, "period")
             layout.prop(fx, "phase")
 
+    def FX_GLOW(self, layout, fx):
+        layout.prop(fx, "mode")
+        layout.prop(fx, "glow_color")
+        if fx.mode == 'LUMINANCE':
+            layout.prop(fx, "threshold")
+        else:
+            layout.prop(fx, "select_color")
+
+        layout.separator()
+        layout.prop(fx, "radius")
+        layout.prop(fx, "samples")
+        layout.prop(fx, "use_alpha_mode", text="Use alpha mode")
+
     def FX_SWIRL(self, layout, fx):
         layout.prop(fx, "object", text="Object")
 
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index 4f9a90ba4f0..738efffcd91 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -337,6 +337,8 @@ data_to_c_simple(engines/gpencil/shaders/gpencil_edit_point_frag.glsl SRC)
 data_to_c_simple(engines/gpencil/shaders/fx/gpencil_fx_blur_frag.glsl SRC)
 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_glow_prepare_frag.glsl SRC)
+data_to_c_simple(engines/gpencil/shaders/fx/gpencil_fx_glow_resolve_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_prepare_frag.glsl SRC)
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 7a9e93ec105..b8844d3c3e9 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -73,6 +73,7 @@ typedef struct tGPencilObjectCache {
 	DRWShadingGroup *fx_pixel_sh;
 	DRWShadingGroup *fx_rim_sh;
 	DRWShadingGroup *fx_shadow_sh;
+	DRWShadingGroup *fx_glow_sh;
 	DRWShadingGroup *fx_swirl_sh;
 	DRWShadingGroup *fx_flip_sh;
 	DRWShadingGroup *fx_light_sh;
@@ -231,6 +232,8 @@ typedef struct GPENCIL_e_data {
 	struct GPUShader *gpencil_fx_blur_sh;
 	struct GPUShader *gpencil_fx_colorize_sh;
 	struct GPUShader *gpencil_fx_flip_sh;
+	struct GPUShader *gpencil_fx_glow_prepare_sh;
+	struct GPUShader *gpencil_fx_glow_resolve_sh;
 	struct GPUShader *gpencil_fx_light_sh;
 	struct GPUShader *gpencil_fx_pixel_sh;
 	struct GPUShader *gpencil_fx_rim_prepare_sh;
diff --git a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
index 9e04365fe1d..9513f83191e 100644
--- a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
+++ b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
@@ -50,6 +50,8 @@ extern char datatoc_gpencil_fx_rim_prepare_frag_glsl[];
 extern char datatoc_gpencil_fx_rim_resolve_frag_glsl[];
 extern char datatoc_gpencil_fx_shadow_prepare_frag_glsl[];
 extern char datatoc_gpencil_fx_shadow_resolve_frag_glsl[];
+extern char datatoc_gpencil_fx_glow_prepare_frag_glsl[];
+extern char datatoc_gpencil_fx_glow_resolve_frag_glsl[];
 extern char datatoc_gpencil_fx_swirl_frag_glsl[];
 extern char datatoc_gpencil_fx_wave_frag_glsl[];
 
@@ -512,6 +514,67 @@ static void DRW_gpencil_fx_shadow(
 	fxd->runtime.fx_sh_c = fx_shgrp;
 }
 
+/* Glow FX */
+static void DRW_gpencil_fx_glow(
+	ShaderFxData *fx, GPENCIL_e_data *e_data, GPENCIL_Data *vedata,
+	tGPencilObjectCache *cache)
+{
+	if (fx == NULL) {
+		return;
+	}
+	GlowShaderFxData *fxd = (GlowShaderFxData *)fx;
+
+	GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
+	GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl;
+	DRWShadingGroup *fx_shgrp;
+
+	struct GPUBatch *fxquad = DRW_cache_fullscreen_quad_get();
+	/* prepare pass */
+	fx_shgrp = DRW_shgroup_create(
+		e_data->gpencil_fx_glow_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_vec3(fx_shgrp, "glow_color", &fxd->glow_color[0], 1);
+	DRW_shgroup_uniform_vec3(fx_shgrp, "select_color", &fxd->select_color[0], 1);
+	DRW_shgroup_uniform_int(fx_shgrp, "mode", &fxd->mode, 1);
+	DRW_shgroup_uniform_float(fx_shgrp, "threshold", &fxd->threshold, 1);
+
+	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_glow_resolve_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_texture_ref(fx_shgrp, "glowColor", &e_data->temp_color_tx_fx);
+	DRW_shgroup_uniform_texture_ref(fx_shgrp, "glowDepth", &e_data->temp_depth_tx_fx);
+
+	/* reuse field */
+	DRW_shgroup_uniform_int(fx_shgrp, "alpha_mode", &fxd->blur[1], 1);
+
+	fxd->runtime.fx_sh_c = fx_shgrp;
+}
+
 /* Swirl FX */
 static void DRW_gpencil_fx_swirl(
         ShaderFxData *fx, GPENCIL_e_data *e_data, GPENCIL_Data *vedata,
@@ -617,6 +680,13 @@ void GPENCIL_create_fx_shaders(GPENCIL_e_data *e_data)
 		e_data->gpencil_fx_shadow_resolve_sh = DRW_shader_create_fullscreen(
 			datatoc_gpencil_fx_shadow_resolve_frag_glsl, NULL);
 	}
+	if (!e_data->gpencil_fx_glow_prepare_sh) {
+		e_data->gpencil_fx_glow_prepare_sh = DRW_shader_create_fullscreen(
+			datatoc_gpencil_fx_glow_prepare_frag_glsl, NULL);
+
+		e_data->gpencil_fx_glow_resolve_sh = DRW_shader_create_fullscreen(
+			datatoc_gpencil_fx_glow_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);
@@ -639,6 +709,8 @@ void GPENCIL_delete_fx_shaders(GPENCIL_e_data *e_data)
 	DRW_SHADER_FREE_SAFE(e_data->gpencil_fx_rim_resolve_sh);
 	DRW_SHADER_FREE_SAFE(e_data->gpencil_fx_shadow_prepare_sh);
 	DRW_SHADER_FREE_SAFE(e_data->gpencil_fx_shadow_resolve_sh);
+	DRW_SHADER_FREE_SAFE(e_data->gpencil_fx_glow_prepare_sh);
+	DRW_SHADER_FREE_SAFE(e_data->gpencil_fx_glow_resolve_sh);
 	DRW_SHADER_FREE_SAFE(e_data->gpencil_fx_swirl_sh);
 	DRW_SHADER_FREE_SAFE(e_data->gpencil_fx_wave_sh);
 }
@@ -693,6 +765,9 @@ void DRW_gpencil_fx_prepare(
 				case eShaderFxType_Shadow:
 					DRW_gpencil_fx_shadow(fx, e_data, vedata, cache);
 					break;
+				case eShaderFxType_Glow:
+					DRW_gpencil_fx_glow(fx, e_data, vedata, cache);
+					break;
 				case eShaderFxType_Swirl:
 					DRW_gpencil_fx_swirl(fx, e_data, vedata, cache);
 					break;
@@ -947,6 +1022,92 @@ static void draw_gpencil_shadow_passes(
 	DRW_draw_pass(psl->mix_pass_noblend);
 }
 
+/* blur glow */
+static void draw_gpencil_glow_blur(
+	struct GPENCIL_e_data *UNUSED(e_data),
+	struct GPENCIL_Data *vedata,
+	struct GlowShaderFxData *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 GLOW passes */
+static void draw_gpencil_glow_passes(
+	struct GPENCIL_e_data *e_data,
+	struct GPENCIL_Data *vedata,
+	struct GlowShaderFxData *fxd)
+{
+	if (fxd->runtime.fx_sh_b == NULL) {
+		return;
+	}
+
+	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 };
+	int bx = fxd->blur[0];
+	int by = fxd->blur[0];
+
+	/* prepare glow */
+	GPU_framebuffer_bind(fbl->temp_fb_fx);
+	GPU_framebuffer_clear_color_depth(fbl->temp_fb_fx, clearcol, 1.0f);
+	DRW_draw_pass_subset(
+		psl->fx_shader_pass_blend,
+		fxd->runtime.fx_sh, fxd->runtime.fx_sh);
+
+	/* blur glow */
+	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_glow_blur(e_data, vedata, fxd);
+
+			/* Vertical */
+			fxd->blur[0] = 0;
+			fxd->blur[1] = by;
+			draw_gpencil_glow_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);
+
+	/* reuses blur field to keep alpha mode */
+	fxd->blur[1] = (fxd->flag & FX_GLOW_USE_ALPHA) ? 1 : 0;
+
+	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;

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list