[Bf-blender-cvs] [96df629b690] temp-greasepencil-vfx: WIP: More steps to back VFX

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


Commit: 96df629b6908864bf670b54b9062c43d7dcb0103
Author: Antonio Vazquez
Date:   Tue Jun 26 19:39:02 2018 +0200
Branches: temp-greasepencil-vfx
https://developer.blender.org/rB96df629b6908864bf670b54b9062c43d7dcb0103

WIP: More steps to back VFX

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

M	source/blender/blenkernel/BKE_shader_fx.h
M	source/blender/blenkernel/intern/shader_fx.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_fx.c
M	source/blender/shader_fx/intern/FX_shader_blur.c
M	source/blender/shader_fx/intern/FX_shader_flip.c
M	source/blender/shader_fx/intern/FX_shader_light.c
M	source/blender/shader_fx/intern/FX_shader_pixel.c
M	source/blender/shader_fx/intern/FX_shader_swirl.c
M	source/blender/shader_fx/intern/FX_shader_wave.c

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

diff --git a/source/blender/blenkernel/BKE_shader_fx.h b/source/blender/blenkernel/BKE_shader_fx.h
index 00c0234d2fe..ede3cb40e3b 100644
--- a/source/blender/blenkernel/BKE_shader_fx.h
+++ b/source/blender/blenkernel/BKE_shader_fx.h
@@ -56,7 +56,7 @@ typedef enum {
 	eShaderFxType_NoneType,
 
 	/* grease pencil effects */
-	eShaderFxType_Gpencil,
+	eShaderFxType_GpencilType,
 }  ShaderFxType;
 
 typedef enum {
@@ -182,4 +182,6 @@ void BKE_shaderfx_foreachIDLink(struct Object *ob, ShaderFxIDWalkFunc walk, void
 void BKE_shaderfx_apply(
 	struct Depsgraph *depsgraph, struct Object *ob, bool is_render);
 
+bool BKE_shaderfx_has_gpencil(struct Object *ob);
+
 #endif /* __BKE_SHADER_FX_H__ */
diff --git a/source/blender/blenkernel/intern/shader_fx.c b/source/blender/blenkernel/intern/shader_fx.c
index 1ee6e33ddc4..49876c388de 100644
--- a/source/blender/blenkernel/intern/shader_fx.c
+++ b/source/blender/blenkernel/intern/shader_fx.c
@@ -67,7 +67,8 @@ bool BKE_shaderfx_has_gpencil(Object *ob)
 {
 	ShaderFxData *fx;
 	for (fx = ob->shader_fx.first; fx; fx = fx->next) {
-		if (fx->type & eShaderFxType_Gpencil) {
+		ShaderFxTypeInfo *fxi = BKE_shaderfxType_getInfo(fx->type);
+		if (fxi->type == eShaderFxType_GpencilType) {
 			return true;
 		}
 	}
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 9f39fcf5327..184fb9ecf91 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -29,6 +29,7 @@
 #include "BKE_object.h"
 #include "BKE_paint.h"
 #include "BKE_gpencil.h"
+#include "BKE_shader_fx.h"
 
 #include "DNA_gpencil_types.h"
 #include "DNA_view3d_types.h"
@@ -345,6 +346,11 @@ 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;
@@ -446,8 +452,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, "strokeColor", &e_data.input_color_tx);
-		DRW_shgroup_uniform_texture_ref(mix_shgrp, "strokeDepth", &e_data.input_depth_tx);
+		DRW_shgroup_uniform_texture_ref(mix_shgrp_noblend, "strokeColor", &e_data.input_color_tx);
+		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);
 
 		/* Painting session pass (used only to speedup while the user is drawing )
@@ -567,6 +573,12 @@ void GPENCIL_cache_finish(void *vedata)
 			if (stl->storage->is_render == true) {
 				gpd->flag |= GP_DATA_CACHE_IS_DIRTY;
 			}
+			/* FX pass */
+			tGPencilObjectCache *cache = &stl->g_data->gp_object_cache[i];
+			if ((!is_multiedit) && (ob->shader_fx.first)) {
+				DRW_gpencil_fx_prepare(&e_data, vedata, cache);
+			}
+
 		}
 	}
 }
@@ -702,10 +714,16 @@ void GPENCIL_draw_scene(void *ved)
 
 					MULTISAMPLE_GP_SYNC_DISABLE(stl->storage->multisamples, fbl, fbl->temp_fb_a, txl);
 				}
+
 				/* Current buffer drawing */
 				if ((!is_render) && (gpd->sbuffer_size > 0)) {
 					DRW_draw_pass(psl->drawing_pass);
 				}
+				/* fx passes */
+				if (BKE_shaderfx_has_gpencil(ob)) {
+					stl->storage->tonemapping = 0;
+					DRW_gpencil_fx_draw(&e_data, vedata, cache);
+				}
 
 				e_data.input_depth_tx = e_data.temp_depth_tx_a;
 				e_data.input_color_tx = e_data.temp_color_tx_a;
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 3d30531fef2..4278fa7073a 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -346,6 +346,14 @@ struct GpencilBatchCache *gpencil_batch_cache_get(struct Object *ob, int cfra);
 /* modifier functions */
 void gpencil_instance_modifiers(struct GPENCIL_StorageList *stl, struct Object *ob);
 
+/* effects */
+void DRW_gpencil_fx_prepare(
+	struct GPENCIL_e_data *e_data, struct GPENCIL_Data *vedata,
+	struct tGPencilObjectCache *cache);
+void DRW_gpencil_fx_draw(
+	struct GPENCIL_e_data *e_data, struct GPENCIL_Data *vedata,
+	struct tGPencilObjectCache *cache);
+
 /* main functions */
 void GPENCIL_engine_init(void *vedata);
 void GPENCIL_cache_init(void *vedata);
diff --git a/source/blender/draw/engines/gpencil/gpencil_fx.c b/source/blender/draw/engines/gpencil/gpencil_fx.c
index 6e3d27db052..6fec570acb6 100644
--- a/source/blender/draw/engines/gpencil/gpencil_fx.c
+++ b/source/blender/draw/engines/gpencil/gpencil_fx.c
@@ -41,18 +41,7 @@
 
 #include "gpencil_engine.h"
 
-/* verify if the object use fx modifiers */
-bool gpencil_object_use_fx(Object *ob)
-{
-	for (ShaderFxData *fx = ob->shader_fx.first; fx; fx = fx->next) {
-		if (fx->type == eShaderFxType_Gpencil) {
-			return true;
-		}
-	}
-	return false;
-}
-
-/* verify if this modifier is active */
+/* verify if this fx is active */
 static bool effect_is_active(Object *ob, ShaderFxData *fx, bool is_render)
 {
 	if (fx == NULL) {
@@ -80,28 +69,28 @@ static bool effect_is_active(Object *ob, ShaderFxData *fx, bool is_render)
 
 /* Wave Distorsion FX */
 static void DRW_gpencil_fx_wave(
-        ShaderFxData *md, int ob_idx, GPENCIL_e_data *e_data, GPENCIL_Data *vedata,
+        ShaderFxData *fx, int ob_idx, GPENCIL_e_data *e_data, GPENCIL_Data *vedata,
         tGPencilObjectCache *cache)
 {
-	if (md == NULL) {
+	if (fx == NULL) {
 		return;
 	}
 
-	WaveShaderFxData *mmd = (WaveShaderFxData *)md;
+	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 = mmd->amplitude;
-	stl->fx[ob_idx].fx_wave.period = mmd->period;
-	stl->fx[ob_idx].fx_wave.phase = mmd->phase;
-	stl->fx[ob_idx].fx_wave.orientation = mmd->orientation;
+	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();
 
 	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->input_color_tx);
-	DRW_shgroup_uniform_texture_ref(fx_shgrp, "strokeDepth", &e_data->input_depth_tx);
+	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);
@@ -146,14 +135,14 @@ static void GPENCIL_dof_nearfar(Object *camera, float coc, float nearfar[2])
  * and vertical in different operations.
  */
 static void DRW_gpencil_fx_blur(
-        ShaderFxData *md, int ob_idx, GPENCIL_e_data *e_data, GPENCIL_Data *vedata,
+        ShaderFxData *fx, int ob_idx, GPENCIL_e_data *e_data, GPENCIL_Data *vedata,
         tGPencilObjectCache *cache)
 {
-	if (md == NULL) {
+	if (fx == NULL) {
 		return;
 	}
 
-	BlurShaderFxData *mmd = (BlurShaderFxData *)md;
+	BlurShaderFxData *fxd = (BlurShaderFxData *)fx;
 
 	GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
 	GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl;
@@ -162,12 +151,12 @@ static void DRW_gpencil_fx_blur(
 	RegionView3D *rv3d = draw_ctx->rv3d;
 	DRWShadingGroup *fx_shgrp;
 
-	stl->fx[ob_idx].fx_blur.radius[0] = mmd->radius[0];
-	stl->fx[ob_idx].fx_blur.radius[1] = mmd->radius[1];
-	stl->fx[ob_idx].fx_blur.samples = mmd->samples;
+	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;
 
 	/* init weight */
-	if (mmd->flag & FX_BLUR_DOF_MODE) {
+	if (fxd->flag & FX_BLUR_DOF_MODE) {
 		/* viewport and opengl render */
 		Object *camera = NULL;
 		if (rv3d) {
@@ -181,7 +170,7 @@ static void DRW_gpencil_fx_blur(
 		
 		if (camera) {
 			float nearfar[2];
-			GPENCIL_dof_nearfar(camera, mmd->coc, nearfar);
+			GPENCIL_dof_nearfar(camera, fxd->coc, nearfar);
 			float zdepth = stl->g_data->gp_object_cache[ob_idx].zdepth;
 			/* the object is on focus area */
 			if ((zdepth >= nearfar[0]) && (zdepth <= nearfar[1])) {
@@ -198,7 +187,7 @@ static void DRW_gpencil_fx_blur(
 				}
 				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, mmd->radius[0]);
+				CLAMP2(&stl->fx[ob_idx].fx_blur.radius[0], 0, fxd->radius[0]);
 			}
 		}
 		else {
@@ -212,8 +201,8 @@ static void DRW_gpencil_fx_blur(
 
 	fx_shgrp = DRW_shgroup_create(e_data->gpencil_fx_blur_sh, psl->fx_blur_pass);
 	DRW_shgroup_call_add(fx_shgrp, fxquad, NULL);
-	DRW_shgroup_uniform_texture_ref(fx_shgrp, "strokeColor", &e_data->input_color_tx);
-	DRW_shgroup_uniform_texture_ref(fx_shgrp, "strokeDepth", &e_data->input_depth_tx);
+	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;
 
@@ -221,30 +210,30 @@ static void DRW_gpencil_fx_blur(
 
 /* Pixelate FX */
 static void DRW_gpencil_fx_pixel(
-        ShaderFxData *md, int ob_idx, GPENCIL_e_data *e_data, GPENCIL_Data *vedata,
+        ShaderFxData *fx, int ob_idx, GPENCIL

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list