[Bf-blender-cvs] [162711fee23] greasepencil-object: Cleanup: Move vfx code and solve VFX order

Antonio Vazquez noreply at git.blender.org
Wed Apr 4 16:37:37 CEST 2018


Commit: 162711fee231577349949a310059535e4d245ccd
Author: Antonio Vazquez
Date:   Wed Apr 4 16:37:28 2018 +0200
Branches: greasepencil-object
https://developer.blender.org/rB162711fee231577349949a310059535e4d245ccd

Cleanup: Move vfx code and solve VFX order

All the code moved to vfx module and now the VFX modifiers are evaluated in the same order defined in the interface. Before, the order was always the same and did not use the interface order.

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

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_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 68c2c621f20..ef981cb0ab5 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -620,24 +620,6 @@ static int gpencil_object_cache_compare_zdepth(const void *a1, const void *a2)
 	return 0;
 }
 
-/* helper to draw VFX pass */
-static void gpencil_draw_vfx_pass(DRWPass *vfxpass, DRWPass *copypass, 
-	GPENCIL_FramebufferList *fbl, DRWShadingGroup *shgrp)
-{
-	float clearcol[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
-
-	GPU_framebuffer_bind(fbl->vfx_fb_b);
-	GPU_framebuffer_clear_color_depth(fbl->vfx_fb_b, clearcol, 1.0f);
-	
-	/* draw effect pass */
-	DRW_draw_pass_subset(vfxpass, shgrp, shgrp);
-	
-	/* copy pass from b to a for ping-pong frame buffers */
-	GPU_framebuffer_bind(fbl->vfx_fb_a);
-	GPU_framebuffer_clear_color_depth(fbl->vfx_fb_a, clearcol, 1.0f);
-	DRW_draw_pass(copypass);
-}
-
 /* Draw all passes related to VFX modifiers 
  * the passes are created using two framebuffers and use a ping-pong selection
  * to alternate use. By default all vfx modifiers start with tx_a as input
@@ -647,82 +629,21 @@ static void gpencil_draw_vfx_pass(DRWPass *vfxpass, DRWPass *copypass,
 */
 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);
 
 	/* 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.
 	*/
+	float clearcol[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
+	GPU_framebuffer_bind(fbl->vfx_fb_a);
+	GPU_framebuffer_clear_color_depth(fbl->vfx_fb_a, clearcol, 1.0f);
 	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)
-	 * --------------*/
-	if (cache->vfx_blur_sh) {
-		int samples = stl->vfx[ob_idx].vfx_blur.samples;
-		/* be sure is even */
-		if (samples % 2 != 0) {
-			samples++;
-		}
 
-		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++) {
-			/* 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);
-		}
-	}
-	/* --------------
-	 * Pixelate pass 
-	 * --------------*/
-	if (cache->vfx_pixel_sh) {
-		gpencil_draw_vfx_pass(psl->vfx_pixel_pass, psl->vfx_copy_pass,
-			fbl, cache->vfx_pixel_sh);
-	}
-	/* --------------
-	 * Swirl pass 
-	 * --------------*/
-	if (cache->vfx_swirl_sh) {
-		gpencil_draw_vfx_pass(psl->vfx_swirl_pass, psl->vfx_copy_pass,
-			fbl, cache->vfx_swirl_sh);
-	}
-	/* --------------
-	* Flip pass
-	* --------------*/
-	if (cache->vfx_flip_sh) {
-		gpencil_draw_vfx_pass(psl->vfx_flip_pass, psl->vfx_copy_pass,
-			fbl, cache->vfx_flip_sh);
-	}
-	/* --------------
-	* Light pass
-	* --------------*/
-	if (cache->vfx_light_sh) {
-		gpencil_draw_vfx_pass(psl->vfx_light_pass, psl->vfx_copy_pass,
-			fbl, cache->vfx_light_sh);
-	}
+	/* draw all vfx passes */
+	DRW_gpencil_vfx_draw(vedata, cache);
 }
 
 /* prepare a texture with full viewport for fast drawing */
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 47acffc8c26..9258d087826 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -384,6 +384,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(struct GPENCIL_e_data *e_data, struct GPENCIL_Data *vedata, struct tGPencilObjectCache *cache);
+void DRW_gpencil_vfx_draw(struct GPENCIL_Data *vedata, struct tGPencilObjectCache *cache);
 bool gpencil_object_use_vfx(struct Object *ob);
 
 /* depth of field */
diff --git a/source/blender/draw/engines/gpencil/gpencil_vfx.c b/source/blender/draw/engines/gpencil/gpencil_vfx.c
index 53a1756e377..637582eb041 100644
--- a/source/blender/draw/engines/gpencil/gpencil_vfx.c
+++ b/source/blender/draw/engines/gpencil/gpencil_vfx.c
@@ -470,3 +470,96 @@ void DRW_gpencil_vfx_modifiers(
 	}
 
 }
+
+/* helper to draw VFX pass */
+static void gpencil_draw_vfx_pass(DRWPass *vfxpass, DRWPass *copypass,
+	GPENCIL_FramebufferList *fbl, DRWShadingGroup *shgrp)
+{
+	float clearcol[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
+
+	GPU_framebuffer_bind(fbl->vfx_fb_b);
+	GPU_framebuffer_clear_color_depth(fbl->vfx_fb_b, clearcol, 1.0f);
+
+	/* draw effect pass */
+	DRW_draw_pass_subset(vfxpass, shgrp, shgrp);
+
+	/* copy pass from b to a for ping-pong frame buffers */
+	GPU_framebuffer_bind(fbl->vfx_fb_a);
+	GPU_framebuffer_clear_color_depth(fbl->vfx_fb_a, clearcol, 1.0f);
+	DRW_draw_pass(copypass);
+}
+
+/* draw all vfx passes */
+void DRW_gpencil_vfx_draw(struct GPENCIL_Data *vedata, struct tGPencilObjectCache *cache)
+{
+	GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
+	GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl;
+	GPENCIL_FramebufferList *fbl = ((GPENCIL_Data *)vedata)->fbl;
+	Object *ob = cache->ob;
+	int ob_idx = cache->idx;
+
+	/* loop VFX modifiers */
+	for (ModifierData *md = ob->modifiers.first; md; md = md->next) {
+		if (modifier_is_active(ob, md, stl->storage->is_render)) {
+			switch (md->type) {
+				case eModifierType_GpencilWave:
+					if (cache->vfx_wave_sh) {
+						gpencil_draw_vfx_pass(psl->vfx_wave_pass, psl->vfx_copy_pass,
+							fbl, cache->vfx_wave_sh);
+					}
+					break;
+				case eModifierType_GpencilBlur:
+					if (cache->vfx_blur_sh) {
+						int samples = stl->vfx[ob_idx].vfx_blur.samples;
+						/* be sure is even */
+						if (samples % 2 != 0) {
+							samples++;
+						}
+
+						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++) {
+							/* 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);
+						}
+					}
+					break;
+				case eModifierType_GpencilPixel:
+					if (cache->vfx_pixel_sh) {
+						gpencil_draw_vfx_pass(psl->vfx_pixel_pass, psl->vfx_copy_pass,
+							fbl, cache->vfx_pixel_sh);
+					}
+					break;
+				case eModifierType_GpencilSwirl:
+					if (cache->vfx_swirl_sh) {
+						gpencil_draw_vfx_pass(psl->vfx_swirl_pass, psl->vfx_copy_pass,
+							fbl, cache->vfx_swirl_sh);
+					}
+					break;
+				case eModifierType_GpencilFlip:
+					if (cache->vfx_flip_sh) {
+						gpencil_draw_vfx_pass(psl->vfx_flip_pass, psl->vfx_copy_pass,
+							fbl, cache->vfx_flip_sh);
+					}
+					break;
+				case eModifierType_GpencilLight:
+					if (cache->vfx_light_sh) {
+						gpencil_draw_vfx_pass(psl->vfx_light_pass, psl->vfx_copy_pass,
+							fbl, cache->vfx_light_sh);
+					}
+					break;
+			}
+		}
+	}
+
+}
+



More information about the Bf-blender-cvs mailing list