[Bf-blender-cvs] [f1afa6f6a71] blender2.8: GP: implement Shadow FX (wip)

Antonioya noreply at git.blender.org
Sun Sep 30 11:49:15 CEST 2018


Commit: f1afa6f6a71220fefcd3d967f261edd6ad93a43a
Author: Antonioya
Date:   Sun Sep 30 11:19:04 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBf1afa6f6a71220fefcd3d967f261edd6ad93a43a

GP: implement Shadow FX (wip)

Initial implementation of effect to create a drop shadow of the strokes

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

M	release/scripts/startup/bl_ui/properties_data_shaderfx.py
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
A	source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_shadow_prepare_frag.glsl
A	source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_shadow_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
A	source/blender/shader_fx/intern/FX_shader_shadow.c
M	source/blender/shader_fx/intern/FX_shader_util.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_shaderfx.py b/release/scripts/startup/bl_ui/properties_data_shaderfx.py
index 6725d354b2b..d56e5cc4782 100644
--- a/release/scripts/startup/bl_ui/properties_data_shaderfx.py
+++ b/release/scripts/startup/bl_ui/properties_data_shaderfx.py
@@ -100,6 +100,28 @@ class DATA_PT_shader_fx(ShaderFxButtonsPanel, Panel):
         layout.prop(fx, "blur")
         layout.prop(fx, "samples")
 
+    def FX_SHADOW(self, layout, fx):
+        layout.prop(fx, "offset", text="Offset")
+
+        layout.prop(fx, "shadow_color")
+        layout.prop(fx, "scale")
+        layout.prop(fx, "rotation")
+
+        layout.separator()
+        layout.prop(fx, "use_object", text="Use object as pivot")
+        if fx.use_object:
+            row = layout.row()
+            row.prop(fx, "object", text="Object")
+
+        layout.separator()
+        layout.prop(fx, "use_wave", text="Use Wave effect")
+        if fx.use_wave is True:
+            row = layout.row(align=True)
+            row.prop(fx, "orientation", expand=True)
+            layout.prop(fx, "amplitude")
+            layout.prop(fx, "period")
+            layout.prop(fx, "phase")
+
     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 06752e41092..a2ab6383828 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -340,6 +340,8 @@ 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)
 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_shadow_prepare_frag.glsl SRC)
+data_to_c_simple(engines/gpencil/shaders/fx/gpencil_fx_shadow_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 657c7665312..bc545a1db80 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -141,17 +141,17 @@ 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(
+		/* used for rim and shadow FX effects */
+		e_data.temp_depth_tx_fx = 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(
+		e_data.temp_color_tx_fx = DRW_texture_pool_query_2D(
 		        size[0], size[1], fb_format,
 		        &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),
+		        &fbl->temp_fb_fx, {
+		            GPU_ATTACHMENT_TEXTURE(e_data.temp_depth_tx_fx),
+		            GPU_ATTACHMENT_TEXTURE(e_data.temp_color_tx_fx),
 		        });
 
 		/* 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 be883360959..89a50170eb6 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -72,6 +72,7 @@ typedef struct tGPencilObjectCache {
 	DRWShadingGroup *fx_colorize_sh;
 	DRWShadingGroup *fx_pixel_sh;
 	DRWShadingGroup *fx_rim_sh;
+	DRWShadingGroup *fx_shadow_sh;
 	DRWShadingGroup *fx_swirl_sh;
 	DRWShadingGroup *fx_flip_sh;
 	DRWShadingGroup *fx_light_sh;
@@ -160,7 +161,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 *temp_fb_fx;
 	struct GPUFrameBuffer *background_fb;
 
 	struct GPUFrameBuffer *multisample_fb;
@@ -234,6 +235,8 @@ typedef struct GPENCIL_e_data {
 	struct GPUShader *gpencil_fx_pixel_sh;
 	struct GPUShader *gpencil_fx_rim_prepare_sh;
 	struct GPUShader *gpencil_fx_rim_resolve_sh;
+	struct GPUShader *gpencil_fx_shadow_prepare_sh;
+	struct GPUShader *gpencil_fx_shadow_resolve_sh;
 	struct GPUShader *gpencil_fx_swirl_sh;
 	struct GPUShader *gpencil_fx_wave_sh;
 
@@ -254,8 +257,8 @@ typedef struct GPENCIL_e_data {
 	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_color_tx_fx;
+	struct GPUTexture *temp_depth_tx_fx;
 
 	/* for buffer only one batch is nedeed because the drawing is only of one stroke */
 	GPUBatch *batch_buffer_stroke;
diff --git a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
index 7d6a8691b87..5a96d6d1275 100644
--- a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
+++ b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
@@ -48,6 +48,8 @@ extern char datatoc_gpencil_fx_light_frag_glsl[];
 extern char datatoc_gpencil_fx_pixel_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_shadow_prepare_frag_glsl[];
+extern char datatoc_gpencil_fx_shadow_resolve_frag_glsl[];
 extern char datatoc_gpencil_fx_swirl_frag_glsl[];
 extern char datatoc_gpencil_fx_wave_frag_glsl[];
 
@@ -407,8 +409,8 @@ static void DRW_gpencil_fx_rim(
 	        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_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);
@@ -425,13 +427,82 @@ static void DRW_gpencil_fx_rim(
 	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_texture_ref(fx_shgrp, "strokeRim", &e_data->temp_color_tx_fx);
 	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;
 }
 
+/* Shadow FX */
+static void DRW_gpencil_fx_shadow(
+	ShaderFxData *fx, GPENCIL_e_data *e_data, GPENCIL_Data *vedata,
+	tGPencilObjectCache *cache)
+{
+	if (fx == NULL) {
+		return;
+	}
+	ShadowShaderFxData *fxd = (ShadowShaderFxData *)fx;
+	if ((!fxd->object) && (fxd->flag & FX_SHADOW_USE_OBJECT)) {
+		return;
+	}
+
+	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_shadow_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_vec2(fx_shgrp, "Viewport", DRW_viewport_size_get(), 1);
+
+	DRW_shgroup_uniform_int(fx_shgrp, "offset", &fxd->offset[0], 2);
+	DRW_shgroup_uniform_float(fx_shgrp, "scale", &fxd->scale[0], 2);
+	DRW_shgroup_uniform_float(fx_shgrp, "rotation", &fxd->rotation, 1);
+	DRW_shgroup_uniform_vec4(fx_shgrp, "shadow_color", &fxd->shadow_rgba[0], 1);
+
+	if ((fxd->object) && (fxd->flag & FX_SHADOW_USE_OBJECT)) {
+		DRW_shgroup_uniform_vec3(fx_shgrp, "loc", &fxd->object->loc[0], 1);
+	}
+	else {
+		DRW_shgroup_uniform_vec3(fx_shgrp, "loc", &cache->loc[0], 1);
+	}
+
+	const int nowave = -1;
+	if (fxd->flag & FX_SHADOW_USE_WAVE) {
+		DRW_shgroup_uniform_int(fx_shgrp, "orientation", &fxd->orientation, 1);
+	}
+	else {
+		DRW_shgroup_uniform_int(fx_shgrp, "orientation", &nowave, 1);
+	}
+	DRW_shgroup_uniform_float(fx_shgrp, "amplitude", &fxd->amplitude, 1);
+	DRW_shgroup_uniform_float(fx_shgrp, "period", &fxd->period, 1);
+	DRW_shgroup_uniform_float(fx_shgrp, "phase", &fxd->phase, 1);
+
+	DRW_shgroup_uniform_float(fx_shgrp, "pixsize", stl->storage->pixsize, 1);
+	DRW_shgroup_uniform_float(fx_shgrp, "pixelsize", &U.pixelsize, 1);
+	DRW_shgroup_uniform_float(fx_shgrp, "pixfactor", &cache->pixfactor, 1);
+
+	fxd->runtime.fx_sh = fx_shgrp;
+
+	/* resolve pass */
+	fx_shgrp = DRW_shgroup_create(
+		e_data->gpencil_fx_shadow_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, "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;
+}
+
 /* Swirl FX */
 static void DRW_gpencil_fx_swirl(
         ShaderFxData *fx, GPENCIL_e_data *e_data, GPENCIL_Data *vedata,
@@ -531,6 +602,13 @@ void GPENCIL_create_fx_shaders(GPENCIL_e_data *e_data)
 		e_data->gpencil_fx_rim_resolve_sh = DRW_shader_create_fullscreen(
 			datatoc_gpencil_fx_rim_resolve_frag_glsl, NULL);
 	}
+	if (!e_data->gpencil_fx_shad

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list