[Bf-blender-cvs] [2392dc82460] greasepencil-object: New VFX Flip modifier

Antonio Vazquez noreply at git.blender.org
Wed Nov 29 09:37:03 CET 2017


Commit: 2392dc82460bdc6a23679d0b3aa52b012d7b809d
Author: Antonio Vazquez
Date:   Wed Nov 29 09:36:43 2017 +0100
Branches: greasepencil-object
https://developer.blender.org/rB2392dc82460bdc6a23679d0b3aa52b012d7b809d

New VFX Flip modifier

This modifier flip horiz. or vertically the current gp object image. The flip works in screen space

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

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/draw/CMakeLists.txt
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
A	source/blender/draw/engines/gpencil/shaders/gpencil_flip_frag.glsl
M	source/blender/editors/space_outliner/outliner_draw.c
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/CMakeLists.txt
M	source/blender/modifiers/MOD_modifiertypes.h
A	source/blender/modifiers/intern/MOD_gpencilflip.c
M	source/blender/modifiers/intern/MOD_util.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 96d6f946a4d..99dae1c17e4 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1883,6 +1883,13 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         col.separator()
         col.prop(md, "transparent")
 
+    def GP_FLIP(self, layout, ob, md):
+        split = layout.split()
+
+        col = split.column()
+        col.prop(md, "flip_horizontal")
+        col.prop(md, "flip_vertical")
+
     def GP_HOOK(self, layout, ob, md):
         gpd = ob.data
         split = layout.split()
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index 776cd6823f9..466c2aedd8a 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -243,6 +243,7 @@ data_to_c_simple(engines/gpencil/shaders/gpencil_gaussian_blur_frag.glsl SRC)
 data_to_c_simple(engines/gpencil/shaders/gpencil_wave_frag.glsl SRC)
 data_to_c_simple(engines/gpencil/shaders/gpencil_pixel_frag.glsl SRC)
 data_to_c_simple(engines/gpencil/shaders/gpencil_swirl_frag.glsl SRC)
+data_to_c_simple(engines/gpencil/shaders/gpencil_flip_frag.glsl SRC)
 data_to_c_simple(engines/gpencil/shaders/gpencil_painting_frag.glsl SRC)
 data_to_c_simple(engines/gpencil/shaders/gpencil_paper_frag.glsl SRC)
 data_to_c_simple(engines/gpencil/shaders/gpencil_edit_point_vert.glsl SRC)
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 784196d87f3..97fec0ba69b 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -56,6 +56,7 @@ extern char datatoc_gpencil_gaussian_blur_frag_glsl[];
 extern char datatoc_gpencil_wave_frag_glsl[];
 extern char datatoc_gpencil_pixel_frag_glsl[];
 extern char datatoc_gpencil_swirl_frag_glsl[];
+extern char datatoc_gpencil_flip_frag_glsl[];
 extern char datatoc_gpencil_painting_frag_glsl[];
 extern char datatoc_gpencil_paper_frag_glsl[];
 extern char datatoc_gpencil_edit_point_vert_glsl[];
@@ -178,6 +179,7 @@ static void GPENCIL_engine_free(void)
 	DRW_SHADER_FREE_SAFE(e_data.gpencil_vfx_wave_sh);
 	DRW_SHADER_FREE_SAFE(e_data.gpencil_vfx_pixel_sh);
 	DRW_SHADER_FREE_SAFE(e_data.gpencil_vfx_swirl_sh);
+	DRW_SHADER_FREE_SAFE(e_data.gpencil_vfx_flip_sh);
 	DRW_SHADER_FREE_SAFE(e_data.gpencil_painting_sh);
 	DRW_SHADER_FREE_SAFE(e_data.gpencil_front_depth_sh);
 	DRW_SHADER_FREE_SAFE(e_data.gpencil_paper_sh);
@@ -249,6 +251,9 @@ static void GPENCIL_cache_init(void *vedata)
 	if (!e_data.gpencil_vfx_swirl_sh) {
 		e_data.gpencil_vfx_swirl_sh = DRW_shader_create_fullscreen(datatoc_gpencil_swirl_frag_glsl, NULL);
 	}
+	if (!e_data.gpencil_vfx_flip_sh) {
+		e_data.gpencil_vfx_flip_sh = DRW_shader_create_fullscreen(datatoc_gpencil_flip_frag_glsl, NULL);
+	}
 	if (!e_data.gpencil_painting_sh) {
 		e_data.gpencil_painting_sh = DRW_shader_create_fullscreen(datatoc_gpencil_painting_frag_glsl, NULL);
 	}
@@ -374,6 +379,8 @@ static void GPENCIL_cache_init(void *vedata)
 
 		psl->vfx_swirl_pass = DRW_pass_create("GPencil VFX Swirl Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS);
 
+		psl->vfx_flip_pass = DRW_pass_create("GPencil VFX Flip Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS);
+
 		/* Painting session pass (used only to speedup while the user is drawing ) */
 		struct Gwn_Batch *paintquad = DRW_cache_fullscreen_quad_get();
 		psl->painting_pass = DRW_pass_create("GPencil Painting Session Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS);
@@ -590,6 +597,21 @@ static void gpencil_vfx_passes(void *vedata, tGPencilObjectCache *cache)
 		DRW_framebuffer_clear(true, true, false, clearcol, 1.0f);
 		DRW_draw_pass(psl->vfx_copy_pass);
 	}
+	/* --------------
+	* Flip pass
+	* --------------*/
+	if ((cache->init_vfx_flip_sh) && (cache->end_vfx_flip_sh)) {
+		DRW_framebuffer_bind(fbl->vfx_color_fb_b);
+		DRW_framebuffer_clear(true, true, false, clearcol, 1.0f);
+		/* flip pass */
+		DRW_draw_pass_subset(psl->vfx_flip_pass,
+			cache->init_vfx_flip_sh,
+			cache->end_vfx_flip_sh);
+		/* copy pass from b to a */
+		DRW_framebuffer_bind(fbl->vfx_color_fb_a);
+		DRW_framebuffer_clear(true, true, false, clearcol, 1.0f);
+		DRW_draw_pass(psl->vfx_copy_pass);
+	}
 }
 
 /* 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 395ef274d64..39e6824d50f 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -97,6 +97,12 @@ typedef struct GPencilVFXWave {
 	float wsize[2];
 } GPencilVFXWave;
 
+typedef struct GPencilVFXFlip {
+	float flipmode[2]; /* use float to pass to shader, but only will be 0 or 1 */
+	float wsize[2];
+} GPencilVFXFlip;
+
+
  /* used to save gpencil objects */
 typedef struct tGPencilObjectCache {
 	struct Object *ob;
@@ -118,6 +124,9 @@ typedef struct tGPencilObjectCache {
 
 	DRWShadingGroup *init_vfx_swirl_sh;
 	DRWShadingGroup *end_vfx_swirl_sh;
+
+	DRWShadingGroup *init_vfx_flip_sh;
+	DRWShadingGroup *end_vfx_flip_sh;
 	float zdepth;
 } tGPencilObjectCache;
 
@@ -127,6 +136,7 @@ typedef struct GPENCIL_vfx {
 	GPencilVFXWave vfx_wave;
 	GPencilVFXPixel vfx_pixel;
 	GPencilVFXSwirl vfx_swirl;
+	GPencilVFXFlip vfx_flip;
 } GPENCIL_vfx;
 
 typedef struct GPENCIL_shgroup {
@@ -182,6 +192,7 @@ typedef struct GPENCIL_PassList {
 	struct DRWPass *vfx_blur_pass_4;
 	struct DRWPass *vfx_pixel_pass;
 	struct DRWPass *vfx_swirl_pass;
+	struct DRWPass *vfx_flip_pass;
 	struct DRWPass *painting_pass;
 	struct DRWPass *paper_pass;
 } GPENCIL_PassList;
@@ -250,6 +261,7 @@ typedef struct GPENCIL_e_data {
 	struct GPUShader *gpencil_vfx_wave_sh;
 	struct GPUShader *gpencil_vfx_pixel_sh;
 	struct GPUShader *gpencil_vfx_swirl_sh;
+	struct GPUShader *gpencil_vfx_flip_sh;
 	struct GPUShader *gpencil_painting_sh;
 	struct GPUShader *gpencil_front_depth_sh;
 	struct GPUShader *gpencil_paper_sh;
diff --git a/source/blender/draw/engines/gpencil/gpencil_vfx.c b/source/blender/draw/engines/gpencil/gpencil_vfx.c
index 18ef4ed435b..ee59f8ac386 100644
--- a/source/blender/draw/engines/gpencil/gpencil_vfx.c
+++ b/source/blender/draw/engines/gpencil/gpencil_vfx.c
@@ -337,6 +337,54 @@ static void DRW_gpencil_vfx_swirl(
 	cache->end_vfx_swirl_sh = vfx_shgrp;
 }
 
+/* Flip VFX */
+static void DRW_gpencil_vfx_flip(
+	ModifierData *md, int ob_idx, GPENCIL_e_data *e_data, GPENCIL_Data *vedata,
+	Object *ob, tGPencilObjectCache *cache)
+{
+	if (md == NULL) {
+		return;
+	}
+
+	GpencilFlipModifierData *mmd = (GpencilFlipModifierData *)md;
+
+	GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
+	GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl;
+	DRWShadingGroup *vfx_shgrp;
+	if (mmd->flag & GP_FLIP_HORIZONTAL) {
+		stl->vfx[ob_idx].vfx_flip.flipmode[0] = 1.0f;
+	}
+	else {
+		stl->vfx[ob_idx].vfx_flip.flipmode[0] = 0;
+	};
+	if (mmd->flag & GP_FLIP_VERTICAL) {
+		stl->vfx[ob_idx].vfx_flip.flipmode[1] = 1.0f;
+	}
+	else {
+		stl->vfx[ob_idx].vfx_flip.flipmode[1] = 0;
+	};
+
+	struct Gwn_Batch *vfxquad = DRW_cache_fullscreen_quad_get();
+	vfx_shgrp = DRW_shgroup_create(e_data->gpencil_vfx_flip_sh, psl->vfx_flip_pass);
+	++stl->g_data->tot_sh;
+	DRW_shgroup_call_add(vfx_shgrp, vfxquad, NULL);
+	DRW_shgroup_uniform_buffer(vfx_shgrp, "strokeColor", &e_data->vfx_fbcolor_color_tx_a);
+	DRW_shgroup_uniform_buffer(vfx_shgrp, "strokeDepth", &e_data->vfx_fbcolor_depth_tx_a);
+	DRW_shgroup_uniform_vec2(vfx_shgrp, "mode", &stl->vfx[ob_idx].vfx_flip.flipmode[0], 1);
+
+	const float *viewport_size = DRW_viewport_size_get();
+	copy_v2_v2(stl->vfx[ob_idx].vfx_flip.wsize, viewport_size);
+	DRW_shgroup_uniform_vec2(vfx_shgrp, "wsize", stl->vfx[ob_idx].vfx_flip.wsize, 1);
+
+	/* set first effect sh */
+	if (cache->init_vfx_flip_sh == NULL) {
+		cache->init_vfx_flip_sh = vfx_shgrp;
+	}
+
+	/* set last effect sh */
+	cache->end_vfx_flip_sh = vfx_shgrp;
+}
+
 void DRW_gpencil_vfx_modifiers(
         int ob_idx, struct GPENCIL_e_data *e_data, struct GPENCIL_Data *vedata,
         struct Object *ob, struct tGPencilObjectCache *cache)
@@ -381,6 +429,15 @@ void DRW_gpencil_vfx_modifiers(
 					DRW_gpencil_vfx_swirl(md, ob_idx, e_data, vedata, ob, cache);
 				}
 				break;
+			case eModifierType_GpencilFlip:
+				if (modifier_is_active(ob, md)) {
+					if (!ready) {
+						DRW_gpencil_vfx_copy(ob_idx, e_data, vedata, ob, cache);
+						ready = true;
+					}
+					DRW_gpencil_vfx_flip(md, ob_idx, e_data, vedata, ob, cache);
+				}
+				break;
 		}
 	}
 
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_flip_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_flip_frag.glsl
new file mode 100644
index 00000000000..d2d038cbc84
--- /dev/null
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_flip_frag.glsl
@@ -0,0 +1,27 @@
+out vec4 FragColor;
+
+uniform sampler2D strokeColor;
+uniform sampler2D strokeDepth;
+uniform vec2 wsize;
+uniform vec2 mode;
+
+void main()
+{
+	vec2 uv = vec2(gl_FragCoord.xy);
+	float stroke_depth;
+	vec4 outcolor;
+
+	if (mode[0] > 0) {
+		uv.x = wsize.x - uv.x;
+	}
+	if (mode[1] > 0) {
+		uv.y = wsize.y - uv.y;
+	}
+	
+	ivec2 iuv = ivec2(uv.x, uv.y);
+	stroke_depth = texelFetch(strokeDepth, iuv, 0).r;
+	outcolor = texelFetch(strokeColor, iuv, 0);
+
+	gl_FragDepth = stroke_depth;
+	FragColor = outcolor;
+}
diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c
index 7aca6f9ffe0..fd88188f117 100644
--- a/source/blender/editors/space_outliner/outliner_draw.c
+++ b/source/blender/editors/space_outliner/outliner_draw.c
@@ -1065,6 +1065,7 @@ static void tselem_draw_icon(uiBlock *block, int xmax, float x, float y, TreeSto
 					case eModifierType_GpencilWave:
 					case eModifierType_GpencilPixel:
 					case eModifierType_GpencilSwirl:
+					case eModifierType_GpencilFlip:
 						ICON_DRAW(ICON_SOLO_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list