[Bf-blender-cvs] [a3930268e14] greasepencil-object: New VFX light modifier

Antonio Vazquez noreply at git.blender.org
Wed Dec 6 21:38:10 CET 2017


Commit: a3930268e147e9e190e303d23a53d0afabe8fb02
Author: Antonio Vazquez
Date:   Wed Dec 6 17:41:56 2017 +0100
Branches: greasepencil-object
https://developer.blender.org/rBa3930268e147e9e190e303d23a53d0afabe8fb02

New VFX light modifier

This modifier simulates a point light over the stroke. There is not shadows support and use its own internal lamp point. Only ambient and diffuse.

The use of this VFX is to get special effects. In the future, a real lighting system can be implemented using normal Blender lamps, but this is different of this modifier.

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

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_light_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_gpencillight.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 ba5b2ea95bc..ea233423bd7 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1903,6 +1903,23 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         col.prop(md, "flip_horizontal")
         col.prop(md, "flip_vertical")
 
+    def GP_LIGHT(self, layout, ob, md):
+        split = layout.split()
+
+        col = split.column()
+        col.prop(md, "offset")
+
+        col = split.column(align=True)
+        col.label("Settings:")
+        col.prop(md, "energy")
+        col.prop(md, "ambient")
+
+        split = layout.split()
+
+        col = split.column()
+        col.prop(md, "distance")
+        col.prop(md, "color")
+
     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 a4e4fa37615..65cbf8835e7 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -245,6 +245,7 @@ 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_light_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 93176051620..cd4644144bc 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -57,6 +57,7 @@ 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_light_frag_glsl[];
 extern char datatoc_gpencil_painting_frag_glsl[];
 extern char datatoc_gpencil_paper_frag_glsl[];
 extern char datatoc_gpencil_edit_point_vert_glsl[];
@@ -180,6 +181,7 @@ static void GPENCIL_engine_free(void)
 	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_vfx_light_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);
@@ -255,6 +257,9 @@ static void GPENCIL_cache_init(void *vedata)
 	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_vfx_light_sh) {
+		e_data.gpencil_vfx_light_sh = DRW_shader_create_fullscreen(datatoc_gpencil_light_frag_glsl, NULL);
+	}
 	if (!e_data.gpencil_painting_sh) {
 		e_data.gpencil_painting_sh = DRW_shader_create_fullscreen(datatoc_gpencil_painting_frag_glsl, NULL);
 	}
@@ -382,6 +387,8 @@ static void GPENCIL_cache_init(void *vedata)
 
 		psl->vfx_flip_pass = DRW_pass_create("GPencil VFX Flip Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS);
 
+		psl->vfx_light_pass = DRW_pass_create("GPencil VFX Light 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);
@@ -515,6 +522,22 @@ static int gpencil_object_cache_compare_zdepth(const void *a1, const void *a2)
 	return 0;
 }
 
+/* helper to draw VFX pass */
+static void gpencil_draw_vfx_pass(DRWPass *vfxpass, DRWPass *copypass, 
+	GPENCIL_FramebufferList *fbl, DRWShadingGroup *init, DRWShadingGroup *end)
+{
+	float clearcol[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
+
+	DRW_framebuffer_bind(fbl->vfx_color_fb_b);
+	DRW_framebuffer_clear(true, true, false, clearcol, 1.0f);
+	/* flip pass */
+	DRW_draw_pass_subset(vfxpass, init, end);
+	/* 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(copypass);
+}
+
 /* Draw all passes related to VFX modifiers 
  * the passes are created using two framebuffers and use a ping-pong selection
  * to alternate use. By default all vfx modifiers start with tx_a as input
@@ -613,6 +636,13 @@ 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);
 	}
+	/* --------------
+	* Light pass
+	* --------------*/
+	if ((cache->init_vfx_light_sh) && (cache->end_vfx_light_sh)) {
+		gpencil_draw_vfx_pass(psl->vfx_light_pass, psl->vfx_copy_pass,
+			fbl, cache->init_vfx_light_sh, cache->end_vfx_light_sh);
+	}
 }
 
 /* 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 5e227b0e8c5..67d12c25df3 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -102,8 +102,15 @@ typedef struct GPencilVFXFlip {
 	float wsize[2];
 } GPencilVFXFlip;
 
-
- /* used to save gpencil objects */
+typedef struct GPencilVFXLight {
+	float loc[3];
+	float energy;
+	float ambient;
+	float specular;
+	float color[3];
+} GPencilVFXLight;
+
+/* used to save gpencil objects */
 typedef struct tGPencilObjectCache {
 	struct Object *ob;
 	int init_grp, end_grp;
@@ -127,6 +134,9 @@ typedef struct tGPencilObjectCache {
 
 	DRWShadingGroup *init_vfx_flip_sh;
 	DRWShadingGroup *end_vfx_flip_sh;
+
+	DRWShadingGroup *init_vfx_light_sh;
+	DRWShadingGroup *end_vfx_light_sh;
 	float zdepth;
 } tGPencilObjectCache;
 
@@ -137,6 +147,7 @@ typedef struct GPENCIL_vfx {
 	GPencilVFXPixel vfx_pixel;
 	GPencilVFXSwirl vfx_swirl;
 	GPencilVFXFlip vfx_flip;
+	GPencilVFXLight vfx_light;
 } GPENCIL_vfx;
 
 typedef struct GPENCIL_shgroup {
@@ -193,6 +204,7 @@ typedef struct GPENCIL_PassList {
 	struct DRWPass *vfx_pixel_pass;
 	struct DRWPass *vfx_swirl_pass;
 	struct DRWPass *vfx_flip_pass;
+	struct DRWPass *vfx_light_pass;
 	struct DRWPass *painting_pass;
 	struct DRWPass *paper_pass;
 } GPENCIL_PassList;
@@ -262,6 +274,7 @@ typedef struct GPENCIL_e_data {
 	struct GPUShader *gpencil_vfx_pixel_sh;
 	struct GPUShader *gpencil_vfx_swirl_sh;
 	struct GPUShader *gpencil_vfx_flip_sh;
+	struct GPUShader *gpencil_vfx_light_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 ee59f8ac386..023c79c8276 100644
--- a/source/blender/draw/engines/gpencil/gpencil_vfx.c
+++ b/source/blender/draw/engines/gpencil/gpencil_vfx.c
@@ -385,6 +385,56 @@ static void DRW_gpencil_vfx_flip(
 	cache->end_vfx_flip_sh = vfx_shgrp;
 }
 
+/* Light VFX */
+static void DRW_gpencil_vfx_light(
+	ModifierData *md, int ob_idx, GPENCIL_e_data *e_data, GPENCIL_Data *vedata,
+	Object *ob, tGPencilObjectCache *cache)
+{
+	if (md == NULL) {
+		return;
+	}
+
+	GpencilLightModifierData *mmd = (GpencilLightModifierData *)md;
+
+	GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
+	GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl;
+	DRWShadingGroup *vfx_shgrp;
+	const DRWContextState *draw_ctx = DRW_context_state_get();
+	ARegion *ar = draw_ctx->ar;
+
+	struct Gwn_Batch *vfxquad = DRW_cache_fullscreen_quad_get();
+	vfx_shgrp = DRW_shgroup_create(e_data->gpencil_vfx_light_sh, psl->vfx_light_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);
+	
+	/* location of the light using obj location as origin */
+	int co[2];
+	ED_view3d_project_int_global(ar, ob->loc, co, V3D_PROJ_TEST_NOP);
+	stl->vfx[ob_idx].vfx_light.loc[0] = (float)co[0] + mmd->loc[0];
+	stl->vfx[ob_idx].vfx_light.loc[1] = (float)co[1] + mmd->loc[1];
+	stl->vfx[ob_idx].vfx_light.loc[2] = (float)mmd->loc[2];
+	DRW_shgroup_uniform_vec3(vfx_shgrp, "loc", &stl->vfx[ob_idx].vfx_light.loc[0], 1);
+
+	copy_v2_v2(stl->vfx[ob_idx].vfx_light.color, mmd->color);
+	DRW_shgroup_uniform_vec3(vfx_shgrp, "lightcolor", &stl->vfx[ob_idx].vfx_light.color[0], 1);
+
+	stl->vfx[ob_idx].vfx_light.energy = mmd->energy;
+	DRW_shgroup_uniform_float(vfx_shgrp, "energy", &stl->vfx[ob_idx].vfx_light.energy, 1);
+
+	stl->vfx[ob_idx].vfx_light.ambient = mmd->ambient;
+	DRW_shgroup_uniform_float(vfx_shgrp, "ambient", &stl->vfx[ob_idx].vfx_light.ambient, 1);
+
+	/* set first effect sh */
+	if (cache->init_vfx_light_sh == NULL) {
+		cache->init_vfx_light_sh = vfx_shgrp;
+	}
+
+	/* set last effect sh */
+	cache->end_vfx_light_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)
@@ -438,6 +488,15 @@ void DRW_gpencil_vfx_modifiers(
 					DRW_gpencil_vfx_flip(md, ob_idx, e_data, vedata, ob, cache);
 				}
 				break;
+			case eModifierType_GpencilLight:
+				if (modifier_is_active(ob, md)) {
+					if (!ready) {
+						DRW_gpencil_vfx_copy(ob_idx, e_data, vedata, ob, cache);
+						ready = true;
+					}
+					DRW_gpencil_vfx_light(md, ob_idx, e_data, vedata, ob, cache);
+				}
+				break;
 		}
 	}
 
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_light_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpe

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list