[Bf-blender-cvs] [ef0fb2ccc74] temp-greasepencil-vfx: Complete refactor to reduce memory and several FX

Antonio Vazquez noreply at git.blender.org
Mon Jul 2 12:43:00 CEST 2018


Commit: ef0fb2ccc74282ee65dd328d741c4e0b0f239adc
Author: Antonio Vazquez
Date:   Mon Jul 2 12:39:53 2018 +0200
Branches: temp-greasepencil-vfx
https://developer.blender.org/rBef0fb2ccc74282ee65dd328d741c4e0b0f239adc

Complete refactor to reduce memory and several FX

These changes reduce the internal struct data used by shader FX and allow to create several FX of the same type for the same object.

Before, there was a limitiation design to enable several times the same FX type.

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

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
M	source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_blur_frag.glsl
M	source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_flip_frag.glsl
M	source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_pixel_frag.glsl
M	source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_rim_frag.glsl
M	source/blender/draw/engines/gpencil/shaders/fx/gpencil_fx_swirl_frag.glsl
M	source/blender/makesdna/DNA_shader_fx_types.h
M	source/blender/makesrna/intern/rna_shader_fx.c
M	source/blender/shader_fx/intern/FX_shader_light.c
M	source/blender/shader_fx/intern/FX_shader_rim.c
M	source/blender/shader_fx/intern/FX_shader_swirl.c

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

diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index e18e78ffd07..d70704fe095 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -289,11 +289,6 @@ void GPENCIL_cache_init(void *vedata)
 		stl->shgroups = MEM_mallocN(sizeof(GPENCIL_shgroup) * GPENCIL_MAX_SHGROUPS, "GPENCIL_shgroup");
 	}
 
-	/* prepare effects */
-	if (!stl->fx) {
-		stl->fx = MEM_mallocN(sizeof(GPENCIL_fx) * GPENCIL_MAX_GP_OBJ, "GPENCIL_fx");
-	}
-
 	/* init gp objects cache */
 	stl->g_data->gp_cache_used = 0;
 	stl->g_data->gp_cache_size = 0;
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index ffb99224100..ac2eb2ca390 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -57,59 +57,8 @@ 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 GPencilFXRim {
-	float loc[3];
-	float offset[2];
-	float rim_rgba[4];
-	float mask_rgba[4];
-	int mode;
-} GPencilFXRim;
-
-typedef struct GPencilFXBlur {
-	float radius[2];
-	int samples;
-} GPencilFXBlur;
 
-typedef struct GPencilFXColorize {
-	float low_color[4];
-	float high_color[4];
-	int mode;
-	float factor;
-} GPencilFXColorize;
-
-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 */
+ /* used to save gpencil objects */
 typedef struct tGPencilObjectCache {
 	struct Object *ob;
 	int init_grp, end_grp;
@@ -130,17 +79,6 @@ typedef struct tGPencilObjectCache {
 } tGPencilObjectCache;
 
   /* *********** LISTS *********** */
-typedef struct GPENCIL_fx {
-	GPencilFXBlur fx_blur;
-	GPencilFXColorize fx_colorize;
-	GPencilFXWave fx_wave;
-	GPencilFXPixel fx_pixel;
-	GPencilFXRim fx_rim;
-	GPencilFXSwirl fx_swirl;
-	GPencilFXFlip fx_flip;
-	GPencilFXLight fx_light;
-} GPENCIL_fx;
-
 typedef struct GPENCIL_shgroup {
 	int s_clamp;
 	int stroke_style;
@@ -194,7 +132,6 @@ typedef struct GPENCIL_StorageList {
 	struct GPENCIL_Storage *storage;
 	struct g_data *g_data;
 	struct GPENCIL_shgroup *shgroups;
-	struct GPENCIL_fx *fx;
 } GPENCIL_StorageList;
 
 typedef struct GPENCIL_PassList {
diff --git a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
index fd19083013b..29007b1585b 100644
--- a/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
+++ b/source/blender/draw/engines/gpencil/gpencil_shader_fx.c
@@ -144,8 +144,7 @@ static void GPENCIL_dof_nearfar(Object *camera, float coc, float nearfar[2])
  * and vertical in different operations.
  */
 static void DRW_gpencil_fx_blur(
-        ShaderFxData *fx, int ob_idx, GPENCIL_e_data *e_data, GPENCIL_Data *vedata,
-        tGPencilObjectCache *cache)
+        ShaderFxData *fx, int ob_idx, GPENCIL_e_data *e_data, GPENCIL_Data *vedata)
 {
 	if (fx == NULL) {
 		return;
@@ -160,9 +159,8 @@ static void DRW_gpencil_fx_blur(
 	RegionView3D *rv3d = draw_ctx->rv3d;
 	DRWShadingGroup *fx_shgrp;
 
-	stl->fx[ob_idx].fx_blur.radius[0] = fxd->radius[0];
-	stl->fx[ob_idx].fx_blur.radius[1] = fxd->radius[1];
-	stl->fx[ob_idx].fx_blur.samples = fxd->samples;
+	fxd->blur[0] = fxd->radius[0];
+	fxd->blur[1] = fxd->radius[1];
 
 	/* init weight */
 	if (fxd->flag & FX_BLUR_DOF_MODE) {
@@ -183,8 +181,8 @@ static void DRW_gpencil_fx_blur(
 			float zdepth = stl->g_data->gp_object_cache[ob_idx].zdepth;
 			/* the object is on focus area */
 			if ((zdepth >= nearfar[0]) && (zdepth <= nearfar[1])) {
-				stl->fx[ob_idx].fx_blur.radius[0] = 0;
-				stl->fx[ob_idx].fx_blur.radius[1] = 0;
+				fxd->blur[0] = 0;
+				fxd->blur[1] = 0;
 			}
 			else {
 				float f;
@@ -194,15 +192,15 @@ static void DRW_gpencil_fx_blur(
 				else {
 					f = zdepth - nearfar[1];
 				}
-				stl->fx[ob_idx].fx_blur.radius[0] = f;
-				stl->fx[ob_idx].fx_blur.radius[1] = f;
-				CLAMP2(&stl->fx[ob_idx].fx_blur.radius[0], 0, fxd->radius[0]);
+				fxd->blur[0] = f;
+				fxd->blur[1] = f;
+				CLAMP2(&fxd->blur[0], 0, fxd->radius[0]);
 			}
 		}
 		else {
 			/* if not camera view, the blur is disabled */
-			stl->fx[ob_idx].fx_blur.radius[0] = 0;
-			stl->fx[ob_idx].fx_blur.radius[1] = 0;
+			fxd->blur[0] = 0;
+			fxd->blur[1] = 0;
 		}
 	}
 
@@ -212,75 +210,60 @@ static void DRW_gpencil_fx_blur(
 	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, "blur", &stl->fx[ob_idx].fx_blur.radius[0], 1);
-	cache->fx_blur_sh = fx_shgrp;
+	DRW_shgroup_uniform_int(fx_shgrp, "blur", &fxd->blur[0], 2);
+	fxd->runtime.fx_sh = fx_shgrp;
 }
 
 /* Colorize FX */
 static void DRW_gpencil_fx_colorize(
-	ShaderFxData *fx, int ob_idx, GPENCIL_e_data *e_data, GPENCIL_Data *vedata,
-	tGPencilObjectCache *cache)
+	ShaderFxData *fx, GPENCIL_e_data *e_data, GPENCIL_Data *vedata)
 {
 	if (fx == NULL) {
 		return;
 	}
-	Object *ob = cache->ob;
 	ColorizeShaderFxData *fxd = (ColorizeShaderFxData *)fx;
-
-	GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
 	GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl;
 	DRWShadingGroup *fx_shgrp;
-	bGPdata *gpd = (bGPdata *)ob->data;
-
-	copy_v4_v4(stl->fx[ob_idx].fx_colorize.low_color, fxd->low_color);
-	copy_v4_v4(stl->fx[ob_idx].fx_colorize.high_color, fxd->high_color);
-	stl->fx[ob_idx].fx_colorize.mode = fxd->mode;
-	stl->fx[ob_idx].fx_colorize.factor = fxd->factor;
 
 	struct Gwn_Batch *fxquad = DRW_cache_fullscreen_quad_get();
 	fx_shgrp = DRW_shgroup_create(e_data->gpencil_fx_colorize_sh, psl->fx_shader_pass);
 	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_vec4(fx_shgrp, "low_color", &stl->fx[ob_idx].fx_colorize.low_color[0], 1);
-	DRW_shgroup_uniform_vec4(fx_shgrp, "high_color", &stl->fx[ob_idx].fx_colorize.high_color[0], 1);
-	DRW_shgroup_uniform_int(fx_shgrp, "mode", &stl->fx[ob_idx].fx_colorize.mode, 1);
-	DRW_shgroup_uniform_float(fx_shgrp, "factor", &stl->fx[ob_idx].fx_colorize.factor, 1);
+	DRW_shgroup_uniform_vec4(fx_shgrp, "low_color", &fxd->low_color[0], 1);
+	DRW_shgroup_uniform_vec4(fx_shgrp, "high_color", &fxd->high_color[0], 1);
+	DRW_shgroup_uniform_int(fx_shgrp, "mode", &fxd->mode, 1);
+	DRW_shgroup_uniform_float(fx_shgrp, "factor", &fxd->factor, 1);
 
 	fxd->runtime.fx_sh = fx_shgrp;
 }
 
 /* Flip FX */
 static void DRW_gpencil_fx_flip(
-	ShaderFxData *fx, int ob_idx, GPENCIL_e_data *e_data, GPENCIL_Data *vedata,
-	tGPencilObjectCache *cache)
+	ShaderFxData *fx, GPENCIL_e_data *e_data, GPENCIL_Data *vedata)
 {
 	if (fx == NULL) {
 		return;
 	}
 	FlipShaderFxData *fxd = (FlipShaderFxData *)fx;
-	GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
 	GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl;
 	DRWShadingGroup *fx_shgrp;
+
+	fxd->flipmode = 100;
+	/* the number works as bit flag */
 	if (fxd->flag & FX_FLIP_HORIZONTAL) {
-		stl->fx[ob_idx].fx_flip.flipmode[0] = 1.0f;
+		fxd->flipmode += 10;
 	}
-	else {
-		stl->fx[ob_idx].fx_flip.flipmode[0] = 0;
-	};
 	if (fxd->flag & FX_FLIP_VERTICAL) {
-		stl->fx[ob_idx].fx_flip.flipmode[1] = 1.0f;
+		fxd->flipmode += 1;
 	}
-	else {
-		stl->fx[ob_idx].fx_flip.flipmode[1] = 0;
-	};
 
 	struct Gwn_Batch *fxquad = DRW_cache_fullscreen_quad_get();
 	fx_shgrp = DRW_shgroup_create(e_data->gpencil_fx_flip_sh, psl->fx_shader_pass);
 	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, "mode", &stl->fx[ob_idx].fx_flip.flipmode[0], 1);
+	DRW_shgroup_uniform_int(fx_shgrp, "flipmode", &fxd->flipmode, 1);
 
 	DRW_shgroup_uniform_vec2(fx_shgrp, "wsize", DRW_viewport_size_get(), 1);
 
@@ -289,7 +272,7 @@ static void DRW_gpencil_fx_flip(
 
 /* Light FX */
 static void DRW_gpencil_fx_light(
-	ShaderFxData *fx, int ob_idx, GPENCIL_e_data *e_data, GPENCIL_Data *vedata,
+	ShaderFxData *fx, GPENCIL_e_data *e_data, GPENCIL_Data *vedata,
 	tGPencilObjectCache *cache)
 {
 	if (fx == NULL) {
@@ -314,7 +297,7 @@ static void DRW_gpencil_fx_light(
 	DRW_shgroup_uniform_vec2(fx_shgrp, "Viewport", DRW_viewport_size_get(), 1);
 
 	/* location of the light using obj location as origin */
-	copy_v3_v3(stl->fx[ob_idx].fx_light.loc, &fxd->object->loc[0]);
+	copy_v3_v3(fxd->loc, &fxd->object->loc[0]);
 
 	/* Calc distance to strokes plane
 	* The w component of location is used to transfer the distance to drawing plane
@@ -328,15 +311,12 @@ static void DRW_gpencil_fx_light(
 	mul_mat3_m4_v3(ob->obmat, r_normal); /* only rotation component */
 	plane_from_point_normal_v3(r_plane, r_point, r_normal);
 	float dt = dist_to_plane_v3(fxd->object->loc, r_plane);
-	stl->fx[ob_idx].fx_light.loc[3] = dt;
-
-	DRW_shgroup_uniform_vec4(fx_shgrp, "loc", stl->fx[ob_idx].fx_light.loc, 1);
+	fxd->loc[3] = dt; /* use last element to save it */
 
-	stl->fx[ob_idx].fx_light.energy = fxd->energy;
-	DRW_shgroup_uniform_float(fx_shgrp, "energy", &stl->fx[ob_idx].fx_light.energy, 1);
+	DRW_shgroup_uniform_vec4(fx_shgrp, "loc", &fxd->loc[0], 1);
 
-	stl->fx[ob_idx].fx_light.ambient = fxd->ambient;
-	DRW_shgroup_uniform_float(fx_shgrp, "ambient", &stl->fx

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list