[Bf-blender-cvs] [0c6ddc2a7be] greasepencil-object: New VFX Gaussian Blur modifier

Antonio Vazquez noreply at git.blender.org
Tue Aug 8 11:19:11 CEST 2017


Commit: 0c6ddc2a7be44086a697307f9a6a3a1a129cfc37
Author: Antonio Vazquez
Date:   Sun Aug 6 13:20:50 2017 +0200
Branches: greasepencil-object
https://developer.blender.org/rB0c6ddc2a7be44086a697307f9a6a3a1a129cfc37

New VFX Gaussian Blur modifier

This modifier works only at viewport level and cannot be applied.

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

M	source/blender/draw/CMakeLists.txt
M	source/blender/draw/engines/gpencil/gpencil_engine.c
M	source/blender/draw/engines/gpencil/gpencil_engine.h
A	source/blender/draw/engines/gpencil/gpencil_vfx.c
M	source/blender/draw/engines/gpencil/shaders/gpencil_gaussian_blur_frag.glsl
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/intern/MOD_gpencilblur.c

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

diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index d27ac5b7947..a8dcffc94ee 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -92,6 +92,7 @@ set(SRC
 	engines/gpencil/gpencil_engine.c
 	engines/gpencil/gpencil_draw_cache_impl.c
 	engines/gpencil/gpencil_geom.c
+	engines/gpencil/gpencil_vfx.c
 
 	DRW_engine.h
 	intern/DRW_render.h
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index a3589f2b867..5d634717114 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -232,7 +232,6 @@ static void GPENCIL_cache_populate(void *vedata, Object *ob)
 	const DRWContextState *draw_ctx = DRW_context_state_get();
 	Scene *scene = draw_ctx->scene;
 	ToolSettings *ts = scene->toolsettings;
-	tGPencilObjectCache *cache;
 
 	/* object datablock (this is not draw now) */
 	if (ob->type == OB_GPENCIL && ob->gpd) {
@@ -247,26 +246,6 @@ static void GPENCIL_cache_populate(void *vedata, Object *ob)
 		gpencil_array_modifiers(stl, ob);
 		/* draw current painting strokes */
 		DRW_gpencil_populate_buffer_strokes(vedata, ts, ob->gpd);
-
-		/* VFX pass */
-		struct Gwn_Batch *vfxquad = DRW_cache_fullscreen_quad_get();
-		cache = &stl->g_data->gp_object_cache[stl->g_data->gp_cache_used - 1];
-
-		/* horizontal blur */
-		DRWShadingGroup *vfx_shgrp = DRW_shgroup_create(e_data.gpencil_vfx_blur_sh, psl->vfx_pass);
-		DRW_shgroup_call_add(vfx_shgrp, vfxquad, NULL);
-		DRW_shgroup_uniform_buffer(vfx_shgrp, "strokeColor", &e_data.temp_fbcolor_color_tx);
-		DRW_shgroup_uniform_buffer(vfx_shgrp, "strokeDepth", &e_data.temp_fbcolor_depth_tx);
-		DRW_shgroup_uniform_vec2(vfx_shgrp, "dir", stl->storage->blur1, 1);
-		cache->init_vfx_sh = vfx_shgrp;
-
-		/* vertical blur */
-		vfx_shgrp = DRW_shgroup_create(e_data.gpencil_vfx_blur_sh, psl->vfx_pass);
-		DRW_shgroup_call_add(vfx_shgrp, vfxquad, NULL);
-		DRW_shgroup_uniform_buffer(vfx_shgrp, "strokeColor", &e_data.temp_fbcolor_color_tx);
-		DRW_shgroup_uniform_buffer(vfx_shgrp, "strokeDepth", &e_data.temp_fbcolor_depth_tx);
-		DRW_shgroup_uniform_vec2(vfx_shgrp, "dir", stl->storage->blur2, 1);
-		cache->end_vfx_sh = vfx_shgrp;
 	}
 }
 
@@ -276,6 +255,7 @@ static void GPENCIL_cache_finish(void *vedata)
 	const DRWContextState *draw_ctx = DRW_context_state_get();
 	Scene *scene = draw_ctx->scene;
 	ToolSettings *ts = scene->toolsettings;
+	tGPencilObjectCache *cache;
 
 	/* Draw all pending objects */
 	if (stl->g_data->gp_cache_used > 0) {
@@ -293,6 +273,9 @@ static void GPENCIL_cache_finish(void *vedata)
 				printf("GPENCIL_cache_finish: %s %d->%d\n", ob->id.name, 
 					stl->g_data->gp_object_cache[i].init_grp, stl->g_data->gp_object_cache[i].end_grp);
 			}
+			/* VFX pass */
+			cache = &stl->g_data->gp_object_cache[i];
+			DRW_gpencil_vfx_blur(&e_data, vedata, ob, cache);
 		}
 	}
 }
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index a5dd73f2f14..97cba5a717f 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -42,6 +42,11 @@ struct GPENCIL_StorageList;
 #define GPENCIL_COLOR_PATTERN 2
 
  /* *********** OBJECTS CACHE *********** */
+typedef struct tGPencilVFXBlur {
+	float x;
+	float y;
+} tGPencilVFXBlur;
+
  /* used to save gpencil objects */
 typedef struct tGPencilObjectCache {
 	struct Object *ob;
@@ -62,6 +67,9 @@ typedef struct GPENCIL_shgroup {
 	int fill_style;
 	int keep_size;
 	float obj_scale;
+	/* vfx data */
+	tGPencilVFXBlur vfx_blur;
+
 	struct DRWShadingGroup *shgrps_fill;
 	struct DRWShadingGroup *shgrps_stroke;
 } GPENCIL_shgroup;
@@ -191,4 +199,6 @@ 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_blur(struct GPENCIL_e_data *e_data, struct GPENCIL_Data *vedata, struct Object *ob, struct tGPencilObjectCache *cache);
+
 #endif /* __GPENCIL_ENGINE_H__ */
diff --git a/source/blender/draw/engines/gpencil/gpencil_vfx.c b/source/blender/draw/engines/gpencil/gpencil_vfx.c
new file mode 100644
index 00000000000..a8a68b4f538
--- /dev/null
+++ b/source/blender/draw/engines/gpencil/gpencil_vfx.c
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2017, Blender Foundation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Antonio Vazquez
+ *
+ */
+
+/** \file blender/draw/engines/gpencil/gpencil_vfx.c
+ *  \ingroup draw
+ */
+
+#include "BKE_modifier.h"
+#include "BKE_global.h"
+
+#include "DRW_engine.h"
+#include "DRW_render.h"
+
+#include "DNA_gpencil_types.h"
+#include "DNA_modifier_types.h"
+
+#include "gpencil_engine.h"
+
+/* verify if this modifier is  available in the context, return NULL if not available */
+static ModifierData *modifier_available(Object *ob, ModifierType type)
+{
+	ModifierData  *md = modifiers_findByType(ob, type);
+	if (md == NULL) {
+		return NULL;
+	}
+
+	bGPdata *gpd = ob->gpd;
+	if (gpd == NULL) {
+		return NULL;
+	}
+
+	bool is_edit = (bool)((gpd->flag & (GP_DATA_STROKE_EDITMODE | GP_DATA_STROKE_SCULPTMODE | GP_DATA_STROKE_WEIGHTMODE)));
+	if ((md->mode & eModifierMode_Realtime) && (G.f & G_RENDER_OGL)) {
+		return NULL;
+	}
+
+	if (((md->mode & eModifierMode_Render) == 0) && (G.f & G_RENDER_OGL)) {
+		return NULL;
+	}
+
+	if ((md->mode & eModifierMode_Editmode) && (!is_edit)) {
+		return NULL;
+	}
+
+	return md;
+}
+
+/* Gaussian Blur VFX
+ * The effect is done using two shading groups because is faster to apply horizontal
+ * and vertical in different operations.
+ */
+void DRW_gpencil_vfx_blur(GPENCIL_e_data *e_data, GPENCIL_Data *vedata, Object *ob, tGPencilObjectCache *cache)
+{
+	ModifierData *md = modifier_available(ob, eModifierType_GpencilBlur);
+	if (md == NULL) {
+		return;
+	}
+
+	GpencilBlurModifierData *mmd = (GpencilBlurModifierData *)md;
+
+	GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
+	GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl;
+	const float *viewport_size = DRW_viewport_size_get();
+	int id = cache->init_grp;
+	stl->shgroups[id].vfx_blur.x = mmd->radius[0];
+	stl->shgroups[id].vfx_blur.y = mmd->radius[1] * (viewport_size[1] / viewport_size[0]);
+
+	struct Gwn_Batch *vfxquad = DRW_cache_fullscreen_quad_get();
+	/* horizontal blur */
+	DRWShadingGroup *vfx_shgrp = DRW_shgroup_create(e_data->gpencil_vfx_blur_sh, psl->vfx_pass);
+	DRW_shgroup_call_add(vfx_shgrp, vfxquad, NULL);
+	DRW_shgroup_uniform_buffer(vfx_shgrp, "strokeColor", &e_data->temp_fbcolor_color_tx);
+	DRW_shgroup_uniform_buffer(vfx_shgrp, "strokeDepth", &e_data->temp_fbcolor_depth_tx);
+	DRW_shgroup_uniform_vec2(vfx_shgrp, "dir", stl->storage->blur1, 1);
+	DRW_shgroup_uniform_float(vfx_shgrp, "blur", &stl->shgroups[id].vfx_blur.x, 1);
+
+	/* set first effect sh */
+	if (cache->init_vfx_sh == NULL) {
+		cache->init_vfx_sh = vfx_shgrp;
+	}
+
+	/* vertical blur */
+	vfx_shgrp = DRW_shgroup_create(e_data->gpencil_vfx_blur_sh, psl->vfx_pass);
+	DRW_shgroup_call_add(vfx_shgrp, vfxquad, NULL);
+	DRW_shgroup_uniform_buffer(vfx_shgrp, "strokeColor", &e_data->temp_fbcolor_color_tx);
+	DRW_shgroup_uniform_buffer(vfx_shgrp, "strokeDepth", &e_data->temp_fbcolor_depth_tx);
+	DRW_shgroup_uniform_vec2(vfx_shgrp, "dir", stl->storage->blur2, 1);
+	DRW_shgroup_uniform_float(vfx_shgrp, "blur", &stl->shgroups[id].vfx_blur.y, 1);
+
+	/* set last effect sh */
+	cache->end_vfx_sh = vfx_shgrp;
+}
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_gaussian_blur_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_gaussian_blur_frag.glsl
index f65a04ddd4a..ff5f0d2c3bc 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_gaussian_blur_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_gaussian_blur_frag.glsl
@@ -4,9 +4,7 @@ out vec4 FragColor;
 uniform sampler2D strokeColor;
 uniform sampler2D strokeDepth;
 
-/* next 2 fields must be uniforms, now, valuer are only for testing */
-float resolution = 100.0;
-float radius = 300.0;
+uniform float blur;
 uniform vec2 dir;
 
 void main()
@@ -15,7 +13,6 @@ void main()
 	float stroke_depth = texelFetch(strokeDepth, uv, 0).r;
 	gl_FragDepth = stroke_depth;
 
-	float blur = radius/resolution; 
 	float hstep = dir.x;
     float vstep = dir.y;
 	vec4 outcolor = vec4(0.0);
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 6b6f2e3e25f..90e2a5c7907 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1803,8 +1803,7 @@ typedef enum eGpencilSimplify_Flag {
 
 typedef struct GpencilBlurModifierData {
 	ModifierData modifier;
-	float resolution[2];
-	float radius[2];
+	int radius[2];
 	int flag;                    /* flags */
 	char pad[4];
 } GpencilBlurModifierData;
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index aa18c5ee050..d2639419659 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -132,7 +132,7 @@ EnumPropertyItem rna_enum_object_modifier_type_items[] = {
 	{eModifierType_GpencilColor, "GP_COLOR", ICON_GROUP_VCOL, "Hue/Saturation", "Apply changes to color" },
 	{eModifierType_GpencilOpacity, "GP_OPACITY", ICON_MOD_MASK, "Opacity", "Opacity of the strokes" },
 	{ 0, "", 0, N_("VFX"), "" },

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list