[Bf-blender-cvs] [62baf41861d] temp-greasepencil-vfx: Cleanup code and comments

Antonio Vazquez noreply at git.blender.org
Wed Jun 27 10:16:01 CEST 2018


Commit: 62baf41861d9c714f56ffb2b46429161e4e692de
Author: Antonio Vazquez
Date:   Wed Jun 27 10:15:55 2018 +0200
Branches: temp-greasepencil-vfx
https://developer.blender.org/rB62baf41861d9c714f56ffb2b46429161e4e692de

Cleanup code and comments

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

M	source/blender/draw/engines/gpencil/gpencil_fx.c

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

diff --git a/source/blender/draw/engines/gpencil/gpencil_fx.c b/source/blender/draw/engines/gpencil/gpencil_fx.c
index a3b73d8df23..67d69bc1e27 100644
--- a/source/blender/draw/engines/gpencil/gpencil_fx.c
+++ b/source/blender/draw/engines/gpencil/gpencil_fx.c
@@ -67,40 +67,38 @@ static bool effect_is_active(Object *ob, ShaderFxData *fx, bool is_render)
 	return false;
 }
 
-/* Wave Distorsion FX */
-static void DRW_gpencil_fx_wave(
-        ShaderFxData *fx, int ob_idx, GPENCIL_e_data *e_data, GPENCIL_Data *vedata,
-        tGPencilObjectCache *cache)
+/* get normal of draw using one stroke of visible layer
+* /param gpd        GP datablock
+* /param r_point    Point on plane
+* /param r_normal   Normal vector
+*/
+static bool get_normal_vector(bGPdata *gpd, float r_point[3], float r_normal[3])
 {
-	if (fx == NULL) {
-		return;
-	}
-
-	WaveShaderFxData *fxd = (WaveShaderFxData *)fx;
-
-	GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
-	GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl;
-	stl->fx[ob_idx].fx_wave.amplitude = fxd->amplitude;
-	stl->fx[ob_idx].fx_wave.period = fxd->period;
-	stl->fx[ob_idx].fx_wave.phase = fxd->phase;
-	stl->fx[ob_idx].fx_wave.orientation = fxd->orientation;
-
-	struct Gwn_Batch *fxquad = DRW_cache_fullscreen_quad_get();
+	for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+		if (gpl->flag & GP_LAYER_HIDE)
+			continue;
 
-	DRWShadingGroup *fx_shgrp = DRW_shgroup_create(e_data->gpencil_fx_wave_sh, psl->fx_wave_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_float(fx_shgrp, "amplitude", &stl->fx[ob_idx].fx_wave.amplitude, 1);
-	DRW_shgroup_uniform_float(fx_shgrp, "period", &stl->fx[ob_idx].fx_wave.period, 1);
-	DRW_shgroup_uniform_float(fx_shgrp, "phase", &stl->fx[ob_idx].fx_wave.phase, 1);
-	DRW_shgroup_uniform_int(fx_shgrp, "orientation", &stl->fx[ob_idx].fx_wave.orientation, 1);
-	DRW_shgroup_uniform_vec2(fx_shgrp, "wsize", DRW_viewport_size_get(), 1);
+		/* get frame  */
+		bGPDframe *gpf = gpl->actframe;
+		if (gpf == NULL)
+			continue;
+		for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
+			if (gps->totpoints >= 3) {
+				bGPDspoint *pt = &gps->points[0];
+				BKE_gpencil_stroke_normal(gps, r_normal);
+				/* in some weird situations, the normal cannot be calculated, so try next stroke */
+				if ((r_normal[0] != 0.0f) || (r_normal[1] != 0.0f) || (r_normal[2] != 0.0f)) {
+					copy_v3_v3(r_point, &pt->x);
+					return true;
+				}
+			}
+		}
+	}
 
-	cache->fx_wave_sh = fx_shgrp;
+	return false;
 }
 
-/* helper to get near and far depth of filed values */
+/* helper to get near and far depth of field values */
 static void GPENCIL_dof_nearfar(Object *camera, float coc, float nearfar[2])
 {
 	if (camera == NULL) {
@@ -130,6 +128,8 @@ static void GPENCIL_dof_nearfar(Object *camera, float coc, float nearfar[2])
 	nearfar[1] = (hyperfocal * focus_dist) / (hyperfocal - focal_len);
 }
 
+/* ****************  Shader Effects ***************************** */
+
 /* Gaussian Blur FX
  * The effect is done using two shading groups because is faster to apply horizontal
  * and vertical in different operations.
@@ -205,7 +205,101 @@ static void DRW_gpencil_fx_blur(
 	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;
+}
+
+/* Flip FX */
+static void DRW_gpencil_fx_flip(
+	ShaderFxData *fx, int ob_idx, GPENCIL_e_data *e_data, GPENCIL_Data *vedata,
+	tGPencilObjectCache *cache)
+{
+	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;
+	if (fxd->flag & FX_FLIP_HORIZONTAL) {
+		stl->fx[ob_idx].fx_flip.flipmode[0] = 1.0f;
+	}
+	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;
+	}
+	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_flip_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_vec2(fx_shgrp, "wsize", DRW_viewport_size_get(), 1);
+
+	cache->fx_flip_sh = fx_shgrp;
+}
+
+/* Light FX */
+static void DRW_gpencil_fx_light(
+	ShaderFxData *fx, int ob_idx, GPENCIL_e_data *e_data, GPENCIL_Data *vedata,
+	tGPencilObjectCache *cache)
+{
+	if (fx == NULL) {
+		return;
+	}
+	Object *ob = cache->ob;
+	LightShaderFxData *fxd = (LightShaderFxData *)fx;
+
+	if (fxd->object == NULL) {
+		return;
+	}
+	GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
+	GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl;
+	DRWShadingGroup *fx_shgrp;
+
+	struct Gwn_Batch *fxquad = DRW_cache_fullscreen_quad_get();
+	fx_shgrp = DRW_shgroup_create(e_data->gpencil_fx_light_sh, psl->fx_light_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, "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]);
+
+	/* Calc distance to strokes plane
+	* The w component of location is used to transfer the distance to drawing plane
+	*/
+	float r_point[3], r_normal[3];
+	float r_plane[4];
+	bGPdata *gpd = (bGPdata *)ob->data;
+	if (!get_normal_vector(gpd, r_point, r_normal)) {
+		return;
+	}
+	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);
+
+	stl->fx[ob_idx].fx_light.energy = fxd->energy;
+	DRW_shgroup_uniform_float(fx_shgrp, "energy", &stl->fx[ob_idx].fx_light.energy, 1);
+
+	stl->fx[ob_idx].fx_light.ambient = fxd->ambient;
+	DRW_shgroup_uniform_float(fx_shgrp, "ambient", &stl->fx[ob_idx].fx_light.ambient, 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", &gpd->pixfactor, 1);
+
+	cache->fx_light_sh = fx_shgrp;
 }
 
 /* Pixelate FX */
@@ -292,132 +386,42 @@ static void DRW_gpencil_fx_swirl(
 	cache->fx_swirl_sh = fx_shgrp;
 }
 
-/* Flip FX */
-static void DRW_gpencil_fx_flip(
+/* Wave Distorsion FX */
+static void DRW_gpencil_fx_wave(
 	ShaderFxData *fx, int ob_idx, GPENCIL_e_data *e_data, GPENCIL_Data *vedata,
 	tGPencilObjectCache *cache)
 {
 	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;
-	if (fxd->flag & FX_FLIP_HORIZONTAL) {
-		stl->fx[ob_idx].fx_flip.flipmode[0] = 1.0f;
-	}
-	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;
-	}
-	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_flip_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_vec2(fx_shgrp, "wsize", DRW_viewport_size_get(), 1);
-
-	cache->fx_flip_sh = fx_shgrp;
-}
-
-/* get normal of draw using one stroke of visible layer 
- * /param gpd        GP datablock
- * /param r_point    Point on plane
- * /param r_normal   Normal vector
- */
-static bool get_normal_vector(bGPdata *gpd, float r_point[3], float r_normal[3])
-{
-	for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
-		if (gpl->flag & GP_LAYER_HIDE)
-			continue;
-
-		/* get frame  */
-		bGPDframe *gpf = gpl->actframe;
-		if (gpf == NULL)
-			continue;
-		for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
-			if (gps->totpoints >= 3) {
-				bGPDspoint *pt = &gps->points[0];
-				BKE_gpencil_stroke_normal(gps, r_normal);
-				/* in some weird situations, the normal cannot be calculated, so try next stroke */
-				if ((r_normal[0] != 0.0f) || (r_normal[1] != 0.0f) || (r_normal[2] != 0.0f)) {
-					copy_v3_v3(r_point, &pt->x);
-					return true;
-				}
-			}
-		}
-	}
-
-	return false;
-}
-
-/* Light FX */
-static void DRW_gpencil_fx_light(
-	ShaderFxData *fx, int ob_idx, GPENCIL_e_data *e_data, GPENCIL_Data *vedata,
-	tGPencilObjectCache *cache)
-{
-	if (fx == NULL) {
-		return;
-	}
-	Object *ob = cache->ob;
-	LightShaderFxData *fxd = (LightShaderFxData *)fx;
+	WaveShaderFxData *fxd = (WaveShaderFxData *)fx;
 
-	if (fxd->object == NULL) {
-		return;
-	}
 	GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
 	GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl;
-	DRWShadingGroup *fx_shgrp;
+	stl->fx[ob_idx].fx_wave.amplitude = fxd->amplitude;
+	stl->fx[ob_idx].fx_wave.period = fxd->period;
+	stl->fx[ob_idx].fx_wave.phase = fxd->phase;
+	stl->fx[ob_idx].fx_wave.orientation = fxd->orientation;
 
 	struct Gwn_Batch *fxquad = DRW_cache_fullscreen_quad_get();
-	fx_shgrp = DRW_shgroup_create(e_data->gpencil_fx_light_sh, psl->fx_light_pass);
+
+	

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list