[Bf-blender-cvs] [54fb045295a] temp-greasepencil-vfx: WIP: First steps to put in place FX again

Antonio Vazquez noreply at git.blender.org
Tue Jun 26 19:39:13 CEST 2018


Commit: 54fb045295a016b5204b6efb2106a555dcfa2af0
Author: Antonio Vazquez
Date:   Tue Jun 26 17:24:19 2018 +0200
Branches: temp-greasepencil-vfx
https://developer.blender.org/rB54fb045295a016b5204b6efb2106a555dcfa2af0

WIP: First steps to put in place FX again

Still not working. This commit only restore the elements required.

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

M	source/blender/draw/CMakeLists.txt
M	source/blender/draw/engines/gpencil/gpencil_engine.c
M	source/blender/draw/engines/gpencil/gpencil_engine.h
A	source/blender/draw/engines/gpencil/gpencil_fx.c
M	source/blender/draw/engines/gpencil/gpencil_render.c
A	source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_blur_frag.glsl
A	source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_flip_frag.glsl
A	source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_light_frag.glsl
A	source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_pixel_frag.glsl
A	source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_swirl_frag.glsl
A	source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_wave_frag.glsl

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

diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index 828543637f3..e11d5514ff0 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -123,6 +123,7 @@ set(SRC
 	engines/gpencil/gpencil_cache_utils.c
 	engines/gpencil/gpencil_draw_utils.c
 	engines/gpencil/gpencil_draw_cache_impl.c
+	engines/gpencil/gpencil_fx.c
 
 	DRW_engine.h
 	intern/DRW_render.h
@@ -314,6 +315,14 @@ data_to_c_simple(engines/gpencil/shaders/gpencil_edit_point_vert.glsl SRC)
 data_to_c_simple(engines/gpencil/shaders/gpencil_edit_point_geom.glsl SRC)
 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_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_swirl_frag.glsl SRC)
+data_to_c_simple(engines/gpencil/shaders/fx/gpencil_fx_wave_frag.glsl SRC)
+
+
 list(APPEND INC
 )
 
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index b62f52bdced..9f39fcf5327 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -66,6 +66,13 @@ extern char datatoc_gpencil_edit_point_vert_glsl[];
 extern char datatoc_gpencil_edit_point_geom_glsl[];
 extern char datatoc_gpencil_edit_point_frag_glsl[];
 
+extern char datatoc_gpencil_fx_blur_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_swirl_frag_glsl[];
+extern char datatoc_gpencil_fx_wave_frag_glsl[];
+
 /* *********** STATIC *********** */
 static GPENCIL_e_data e_data = {NULL}; /* Engine data */
 
@@ -129,6 +136,15 @@ static void GPENCIL_create_framebuffers(void *vedata)
 			GPU_ATTACHMENT_TEXTURE(e_data.temp_color_tx_a)
 			});
 
+		e_data.temp_depth_tx_b = DRW_texture_pool_query_2D(size[0], size[1], GPU_DEPTH24_STENCIL8,
+			&draw_engine_object_type);
+		e_data.temp_color_tx_b = DRW_texture_pool_query_2D(size[0], size[1], fb_format,
+			&draw_engine_object_type);
+		GPU_framebuffer_ensure_config(&fbl->temp_fb_b, {
+			GPU_ATTACHMENT_TEXTURE(e_data.temp_depth_tx_b),
+			GPU_ATTACHMENT_TEXTURE(e_data.temp_color_tx_b)
+			});
+
 		/* 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_object_type);
@@ -202,6 +218,45 @@ static void GPENCIL_create_shaders(void)
 	}
 }
 
+static void GPENCIL_create_fx_shaders(void)
+{
+	/* 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);
+	}
+	if (!e_data.gpencil_fx_flip_sh) {
+		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);
+	}
+	if (!e_data.gpencil_fx_pixel_sh) {
+		e_data.gpencil_fx_pixel_sh = DRW_shader_create_fullscreen(datatoc_gpencil_fx_pixel_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);
+	}
+	if (!e_data.gpencil_fx_wave_sh) {
+		e_data.gpencil_fx_wave_sh = DRW_shader_create_fullscreen(datatoc_gpencil_fx_wave_frag_glsl, NULL);
+	}
+}
+
+static void GPENCIL_create_fx_passes(GPENCIL_PassList *psl)
+{
+	/* FX passes */
+	psl->fx_blur_pass = DRW_pass_create("GPencil FX Blur Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS);
+
+	psl->fx_flip_pass = DRW_pass_create("GPencil FX Flip Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS);
+
+	psl->fx_light_pass = DRW_pass_create("GPencil FX Light Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS);
+
+	psl->fx_pixel_pass = DRW_pass_create("GPencil FX Pixel Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS);
+
+	psl->fx_swirl_pass = DRW_pass_create("GPencil FX Swirl Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS);
+
+	psl->fx_wave_pass = DRW_pass_create("GPencil FX Wave Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS);
+}
+
 void GPENCIL_engine_init(void *vedata)
 {
 	GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
@@ -220,6 +275,7 @@ void GPENCIL_engine_init(void *vedata)
 
 	/* create shaders */
 	GPENCIL_create_shaders();
+	GPENCIL_create_fx_shaders();
 
 	/* blank texture used if no texture defined for fill shader */
 	if (!e_data.gpencil_blank_texture) {
@@ -241,6 +297,14 @@ static void GPENCIL_engine_free(void)
 	DRW_SHADER_FREE_SAFE(e_data.gpencil_paper_sh);
 
 	DRW_TEXTURE_FREE_SAFE(e_data.gpencil_blank_texture);
+
+	/* effects */
+	DRW_SHADER_FREE_SAFE(e_data.gpencil_fx_blur_sh);
+	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_swirl_sh);
+	DRW_SHADER_FREE_SAFE(e_data.gpencil_fx_wave_sh);
 }
 
 void GPENCIL_cache_init(void *vedata)
@@ -382,8 +446,8 @@ void GPENCIL_cache_init(void *vedata)
 		psl->mix_pass_noblend = DRW_pass_create("GPencil Mix Pass no blend", DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS);
 		DRWShadingGroup *mix_shgrp_noblend = DRW_shgroup_create(e_data.gpencil_fullscreen_sh, psl->mix_pass_noblend);
 		DRW_shgroup_call_add(mix_shgrp_noblend, quad, NULL);
-		DRW_shgroup_uniform_texture_ref(mix_shgrp_noblend, "strokeColor", &e_data.temp_color_tx_a);
-		DRW_shgroup_uniform_texture_ref(mix_shgrp_noblend, "strokeDepth", &e_data.temp_depth_tx_a);
+		DRW_shgroup_uniform_texture_ref(mix_shgrp, "strokeColor", &e_data.input_color_tx);
+		DRW_shgroup_uniform_texture_ref(mix_shgrp, "strokeDepth", &e_data.input_depth_tx);
 		DRW_shgroup_uniform_int(mix_shgrp_noblend, "tonemapping", &stl->storage->tonemapping, 1);
 
 		/* Painting session pass (used only to speedup while the user is drawing )
@@ -423,6 +487,9 @@ void GPENCIL_cache_init(void *vedata)
 			}
 			DRW_shgroup_uniform_int(paper_shgrp, "uselines", &stl->storage->uselines, 1);
 		}
+
+		/* effects passes */
+		GPENCIL_create_fx_passes(psl);
 	}
 }
 
@@ -600,6 +667,8 @@ void GPENCIL_draw_scene(void *ved)
 		/* attach temp textures */
 		GPU_framebuffer_texture_attach(fbl->temp_fb_a, e_data.temp_depth_tx_a, 0, 0);
 		GPU_framebuffer_texture_attach(fbl->temp_fb_a, e_data.temp_color_tx_a, 0, 0);
+		GPU_framebuffer_texture_attach(fbl->temp_fb_b, e_data.temp_depth_tx_b, 0, 0);
+		GPU_framebuffer_texture_attach(fbl->temp_fb_b, e_data.temp_color_tx_b, 0, 0);
 
 		GPU_framebuffer_texture_attach(fbl->background_fb, e_data.background_depth_tx, 0, 0);
 		GPU_framebuffer_texture_attach(fbl->background_fb, e_data.background_color_tx, 0, 0);
@@ -669,6 +738,11 @@ void GPENCIL_draw_scene(void *ved)
 
 	/* detach temp textures */
 	if (DRW_state_is_fbo()) {
+		GPU_framebuffer_texture_detach(fbl->temp_fb_a, e_data.temp_depth_tx_a);
+		GPU_framebuffer_texture_detach(fbl->temp_fb_a, e_data.temp_color_tx_a);
+		GPU_framebuffer_texture_detach(fbl->temp_fb_b, e_data.temp_depth_tx_b);
+		GPU_framebuffer_texture_detach(fbl->temp_fb_b, e_data.temp_color_tx_b);
+
 		GPU_framebuffer_texture_detach(fbl->background_fb, e_data.background_depth_tx);
 		GPU_framebuffer_texture_detach(fbl->background_fb, e_data.background_color_tx);
 
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 0bce4e663cd..3d30531fef2 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -57,6 +57,42 @@ struct RenderLayer;
 #define GP_IS_CAMERAVIEW ((rv3d != NULL) && (rv3d->persp == RV3D_CAMOB && v3d->camera))
 
  /* *********** OBJECTS CACHE *********** */
+typedef struct GPencilFXPixel {
+	float loc[3];
+	float size[2];
+	float rgba[4];
+	int lines;
+} GPencilFXPixel;
+
+typedef struct GPencilFXBlur {
+	float radius[2];
+	int samples;
+} GPencilFXBlur;
+
+typedef struct GPencilFXFlip {
+	float flipmode[2]; /* use float to pass to shader, but only will be 0 or 1 */
+} GPencilFXFlip;
+
+typedef struct GPencilFXLight {
+	float loc[4];
+	float energy;
+	float ambient;
+	float specular;
+} GPencilFXLight;
+
+typedef struct GPencilFXSwirl {
+	float loc[3];
+	float radius;
+	float angle;
+	int transparent;
+} GPencilFXSwirl;
+
+typedef struct GPencilFXWave {
+	int orientation;
+	float amplitude;
+	float period;
+	float phase;
+} GPencilFXWave;
 
 /* used to save gpencil objects */
 typedef struct tGPencilObjectCache {
@@ -64,11 +100,27 @@ typedef struct tGPencilObjectCache {
 	int init_grp, end_grp;
 	int idx;  /*original index, can change after sort */
 
+	/* effects */
+	DRWShadingGroup *fx_wave_sh;
+	DRWShadingGroup *fx_blur_sh;
+	DRWShadingGroup *fx_pixel_sh;
+	DRWShadingGroup *fx_swirl_sh;
+	DRWShadingGroup *fx_flip_sh;
+	DRWShadingGroup *fx_light_sh;
+
 	float zdepth;  /* z-depth value to sort gp object */
 	bool temp_ob;  /* flag to tag temporary objects that must be removed after drawing loop */
 } tGPencilObjectCache;
 
   /* *********** LISTS *********** */
+typedef struct GPENCIL_fx {
+	GPencilFXBlur fx_blur;
+	GPencilFXWave fx_wave;
+	GPencilFXPixel fx_pixel;
+	GPencilFXSwirl fx_swirl;
+	GPencilFXFlip fx_flip;
+	GPencilFXLight fx_light;
+} GPENCIL_fx;
 
 typedef struct GPENCIL_shgroup {
 	int s_clamp;
@@ -108,19 +160,22 @@ typedef struct GPENCIL_Storage {
 	/* simplify settings*/
 	bool simplify_fill;
 	bool simplify_modif;
-	bool simplify_vfx;
+	bool simplify_fx;
 
 	/* Render Matrices and data */
 	float persmat[4][4], persinv[4][4];
 	float viewmat[4][4], viewinv[4][4];
 	float winmat[4][4], wininv[4][4];
 	float view

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list