[Bf-blender-cvs] [5ed07515f59] greasepencil-object: Refactor VFX code

Antonioya noreply at git.blender.org
Tue Apr 3 19:31:50 CEST 2018


Commit: 5ed07515f5933aa55eefe7c288a62854b0edbab2
Author: Antonioya
Date:   Tue Apr 3 18:27:15 2018 +0200
Branches: greasepencil-object
https://developer.blender.org/rB5ed07515f5933aa55eefe7c288a62854b0edbab2

Refactor VFX code

Make code more consistent and clear to understand.

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

M	source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
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_vfx.c

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

diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
index 773450dbc9a..0f27811e191 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_cache_impl.c
@@ -87,6 +87,7 @@ void gpencil_object_cache_add(tGPencilObjectCache *cache_array, Object *ob, bool
 	/* save object */
 	cache->ob = ob;
 	cache->temp_ob = is_temp;
+	cache->idx = *gp_cache_used;
 
 	cache->init_grp = 0;
 	cache->end_grp = -1;
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index f9daea039b7..ac1fdb8c779 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -418,8 +418,17 @@ static void GPENCIL_cache_init(void *vedata)
 		DRW_shgroup_uniform_texture_ref(mix_shgrp_noblend, "strokeDepth", &e_data.input_depth_tx);
 		DRW_shgroup_uniform_int(mix_shgrp_noblend, "tonemapping", &stl->storage->tonemapping, 1);
 
-		/* vfx copy pass from txtb to txta */
+		/* vfx setup pass to prepare txta */
 		struct Gwn_Batch *vfxquad = DRW_cache_fullscreen_quad_get();
+		psl->vfx_setup_pass = DRW_pass_create("GPencil VFX setup Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS);
+		DRWShadingGroup *vfx_setup_shgrp = DRW_shgroup_create(e_data.gpencil_simple_fullscreen_sh, psl->vfx_setup_pass);
+		stl->g_data->tot_sh++;
+		DRW_shgroup_call_add(vfx_setup_shgrp, vfxquad, NULL);
+		DRW_shgroup_uniform_texture_ref(vfx_setup_shgrp, "strokeColor", &e_data.temp_color_tx);
+		DRW_shgroup_uniform_texture_ref(vfx_setup_shgrp, "strokeDepth", &e_data.temp_depth_tx);
+		
+		/* vfx copy pass from txtb to txta */
+		vfxquad = DRW_cache_fullscreen_quad_get();
 		psl->vfx_copy_pass = DRW_pass_create("GPencil VFX Copy b to a Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS);
 		DRWShadingGroup *vfx_copy_shgrp = DRW_shgroup_create(e_data.gpencil_simple_fullscreen_sh, psl->vfx_copy_pass);
 		stl->g_data->tot_sh++;
@@ -613,27 +622,30 @@ static void gpencil_draw_vfx_pass(DRWPass *vfxpass, DRWPass *copypass,
  * vfx modifier. This use one pass more but allows to create a stack of vfx
  * modifiers and add more modifiers in the future using the same structure.
 */
-static void gpencil_vfx_passes(int ob_idx, void *vedata, tGPencilObjectCache *cache)
+static void gpencil_vfx_passes(void *vedata, tGPencilObjectCache *cache)
 {
 	float clearcol[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
 
 	GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
 	GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl;
 	GPENCIL_FramebufferList *fbl = ((GPENCIL_Data *)vedata)->fbl;
+	int ob_idx = cache->idx;
 
 	GPU_framebuffer_bind(fbl->vfx_fb_a);
 	GPU_framebuffer_clear_color_depth(fbl->vfx_fb_a, clearcol, 1.0f);
 
-	/* create a wave pass or if this modifier is not used, copy the original texture
-	* to tx_a to be used by all following vfx modifiers.
-	* At the end of this pass, we can be sure the vfx_fbcolor_color_tx_a texture has 
+	/* Copy the original texture to tx_a to be used by all following vfx modifiers.
+	* At the end of this passes, we can be sure the vfx_fbcolor_color_tx_a texture has 
 	* the final image.
-	*
-	* Wave pass is always evaluated first.
 	*/
-	DRW_draw_pass_subset(psl->vfx_wave_pass,
-		cache->vfx_wave_sh,
-		cache->vfx_wave_sh);
+	DRW_draw_pass(psl->vfx_setup_pass);
+	/* --------------
+	* Wave pass 
+	* --------------*/
+	if (cache->vfx_wave_sh) {
+		gpencil_draw_vfx_pass(psl->vfx_wave_pass, psl->vfx_copy_pass,
+			fbl, cache->vfx_wave_sh);
+	}
 	/* --------------
 	 * Blur passes (use several passes to get better quality)
 	 * --------------*/
@@ -644,38 +656,20 @@ static void gpencil_vfx_passes(int ob_idx, void *vedata, tGPencilObjectCache *ca
 			samples++;
 		}
 
-		/* save radius to avoid shift when apply several times the same effect */
 		float bx = stl->vfx[ob_idx].vfx_blur.radius[0];
 		float by = stl->vfx[ob_idx].vfx_blur.radius[1];
 
 		for (int b = 0; b < samples; b++) {
-			/* make a pin-pong change of framebuffer to acumulate 
-			 * first horizontal blur and next a vertical blur.
-			 * if we try to make both at the same time, the image is shifted to top
-			 */
-			if (b % 2 == 0) {
-				GPU_framebuffer_bind(fbl->vfx_fb_b);
-				/* clean only firt time */
-				if (b == 0) {
-					GPU_framebuffer_clear_color_depth(fbl->vfx_fb_b, clearcol, 1.0f);
-				}
-				e_data.input_depth_tx = e_data.vfx_depth_tx_a;
-				e_data.input_color_tx = e_data.vfx_color_tx_a;
-				/* horizontal */
-				stl->vfx[ob_idx].vfx_blur.radius[0] = bx;
-				stl->vfx[ob_idx].vfx_blur.radius[1] = 0;
-			}
-			else {
-				e_data.input_depth_tx = e_data.vfx_depth_tx_b;
-				e_data.input_color_tx = e_data.vfx_color_tx_b;
-				GPU_framebuffer_bind(fbl->vfx_fb_a);
-				/* vertical */
-				stl->vfx[ob_idx].vfx_blur.radius[0] = 0;
-				stl->vfx[ob_idx].vfx_blur.radius[1] = by;
-			}
-			DRW_draw_pass_subset(psl->vfx_blur_pass,
-				cache->vfx_blur_sh,
-				cache->vfx_blur_sh);
+			/* horizontal */
+			stl->vfx[ob_idx].vfx_blur.radius[0] = bx;
+			stl->vfx[ob_idx].vfx_blur.radius[1] = 0;
+			gpencil_draw_vfx_pass(psl->vfx_blur_pass, psl->vfx_copy_pass,
+				fbl, cache->vfx_blur_sh);
+			/* vertical */
+			stl->vfx[ob_idx].vfx_blur.radius[0] = 0;
+			stl->vfx[ob_idx].vfx_blur.radius[1] = by;
+			gpencil_draw_vfx_pass(psl->vfx_blur_pass, psl->vfx_copy_pass,
+				fbl, cache->vfx_blur_sh);
 		}
 	}
 	/* --------------
@@ -841,12 +835,10 @@ static void GPENCIL_draw_scene(void *vedata)
 					DRW_draw_pass(psl->drawing_pass);
 				}
 
-				/* vfx modifiers passes
-				 * if any vfx modifier exist, the init_vfx_wave_sh will be not NULL.
-				 */
-				if ((cache->vfx_wave_sh) && (!stl->storage->simplify_vfx)) {
+				/* vfx modifiers passes */
+				if ((gpencil_object_use_vfx(ob)) && (!stl->storage->simplify_vfx)) {
 					/* add vfx passes */
-					gpencil_vfx_passes(i, vedata, cache);
+					gpencil_vfx_passes(vedata, cache);
 
 					e_data.input_depth_tx = e_data.vfx_depth_tx_a;
 					e_data.input_color_tx = e_data.vfx_color_tx_a;
@@ -856,6 +848,7 @@ static void GPENCIL_draw_scene(void *vedata)
 					e_data.input_color_tx = e_data.temp_color_tx;
 				}
 
+#if 0 /* the reult is very low quality, disable while find a solution */
 				/* depth of field effect
 				 * send always to tx_b because other textures can be in use. Remap input
 				 * textures too.
@@ -866,7 +859,7 @@ static void GPENCIL_draw_scene(void *vedata)
 					e_data.input_depth_tx = e_data.vfx_depth_tx_b;
 					e_data.input_color_tx = e_data.vfx_color_tx_b;
 				}
-
+#endif
 				/* Combine with scene buffer */
 				if ((!is_render) || (fbl->main == NULL)) {
 					GPU_framebuffer_bind(dfbl->default_fb);
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 5ba4753f1d8..dea47745822 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -113,6 +113,7 @@ typedef struct GPencilVFXLight {
 typedef struct tGPencilObjectCache {
 	struct Object *ob;
 	int init_grp, end_grp;
+	int idx;  /*original index, can change after sort */
 	DRWShadingGroup *vfx_wave_sh;
 
 	DRWShadingGroup *vfx_blur_sh;
@@ -206,6 +207,7 @@ typedef struct GPENCIL_PassList {
 	struct DRWPass *drawing_pass;
 	struct DRWPass *mix_pass;
 	struct DRWPass *mix_pass_noblend;
+	struct DRWPass *vfx_setup_pass;
 	struct DRWPass *vfx_copy_pass;
 	struct DRWPass *vfx_wave_pass;
 	struct DRWPass *vfx_blur_pass;
@@ -381,6 +383,7 @@ void gpencil_object_cache_add(struct tGPencilObjectCache *cache, struct Object *
 void gpencil_array_modifiers(struct GPENCIL_StorageList *stl, struct Object *ob);
 
 void DRW_gpencil_vfx_modifiers(int ob_idx, struct GPENCIL_e_data *e_data, struct GPENCIL_Data *vedata, struct Object *ob, struct tGPencilObjectCache *cache);
+bool gpencil_object_use_vfx(struct Object *ob);
 
 /* depth of field */
 int GPENCIL_depth_of_field_init(struct DrawEngineType *draw_engine_gpencil_type, struct GPENCIL_e_data *e_data, struct GPENCIL_Data *vedata, struct Object *camera);
diff --git a/source/blender/draw/engines/gpencil/gpencil_vfx.c b/source/blender/draw/engines/gpencil/gpencil_vfx.c
index 3c9a8116764..8bb93a7c82a 100644
--- a/source/blender/draw/engines/gpencil/gpencil_vfx.c
+++ b/source/blender/draw/engines/gpencil/gpencil_vfx.c
@@ -38,6 +38,19 @@
 
 #include "gpencil_engine.h"
 
+/* verify if the object use vfx modifiers */
+bool gpencil_object_use_vfx(Object *ob)
+{
+	for (ModifierData *md = ob->modifiers.first; md; md = md->next) {
+		if (ELEM(md->type, eModifierType_GpencilWave, eModifierType_GpencilBlur, 
+						   eModifierType_GpencilPixel, eModifierType_GpencilSwirl,
+						   eModifierType_GpencilFlip, eModifierType_GpencilLight)) {
+			return true;
+		}
+	}
+	return false;
+}
+
 /* verify if this modifier is  available in the context, return NULL if not available */
 static ModifierData *modifier_available(Object *ob, ModifierType type, bool is_render)
 {
@@ -90,24 +103,6 @@ static bool modifier_is_active(Object *ob, ModifierData *md, bool is_render)
 	return false;
 }
 
-/* Copy image as is to fill vfx texture */
-static void DRW_gpencil_vfx_copy(
-        int UNUSED(ob_idx), GPENCIL_e_data *e_data, GPENCIL_Data *vedata,
-        Object *UNUSED(ob), tGPencilObjectCache *cache)
-{
-	GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl;
-	GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
-
-	struct Gwn_Batch *vfxquad = DRW_cache_fullscreen_quad_get();
-	DRWShadingGroup *vfx_shgrp = DRW_shgroup_create(e_data->gpencil_simple_fullscreen_sh, psl->vfx_wave_pass);
-	++stl->g_data->tot_sh;
-	DRW_shgroup_call_add(vfx_shgrp, vfxquad, NULL);
-	DRW_shgroup_uniform_texture_ref(vfx_shgrp, "strokeColor", &e_data->temp_color_tx);
-	DRW_shgroup_uniform_texture_ref(vfx_shgrp, "strokeDepth", &e_data->temp_depth_tx);
-
-	cache->vfx_wave_sh = vfx_shgrp;
-}
-
 /* Wave Distorsion VFX */
 static void DRW_gpencil_vfx_wave(
         ModifierData *md, int ob_idx, GPENCIL_e_data *e_data, GPENCIL_Data *vedata,
@@ -131,9 +126,8 @@ static void DR

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list