[Bf-blender-cvs] [333f562cf78] greasepencil-object: GP: Define new Draw Mode

Antonioya noreply at git.blender.org
Thu Feb 21 12:36:08 CET 2019


Commit: 333f562cf78ced3271472db8cafce49f1e33740f
Author: Antonioya
Date:   Thu Feb 21 12:25:28 2019 +0100
Branches: greasepencil-object
https://developer.blender.org/rB333f562cf78ced3271472db8cafce49f1e33740f

GP: Define new Draw Mode

Add a new Draw Mode to display panel in order to define the z-.depth order of the strokes using the real 3D position and not the 2D layer position.

This change makes possible to use VR with grease pencil drawings because the depth of the strokes change with camera position.

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

M	release/scripts/startup/bl_ui/properties_data_gpencil.py
M	source/blender/draw/engines/gpencil/gpencil_draw_utils.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/shaders/gpencil_fill_frag.glsl
M	source/blender/makesdna/DNA_gpencil_types.h
M	source/blender/makesrna/intern/rna_gpencil.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_gpencil.py b/release/scripts/startup/bl_ui/properties_data_gpencil.py
index d6633c99456..c0ce3ce961f 100644
--- a/release/scripts/startup/bl_ui/properties_data_gpencil.py
+++ b/release/scripts/startup/bl_ui/properties_data_gpencil.py
@@ -346,6 +346,7 @@ class DATA_PT_gpencil_display(DataButtonsPanel, Panel):
         gpd = context.gpencil_data
         gpl = context.active_gpencil_layer
 
+        layout.prop(gpd, "draw_mode", text="Mode")
         layout.prop(gpd, "xray_mode", text="Depth Ordering")
         layout.prop(ob, "empty_display_size", text="Marker Size")
 
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
index 6d8cfb4e58d..901e87b63d2 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
@@ -302,6 +302,8 @@ static DRWShadingGroup *DRW_gpencil_shgroup_fill_create(
 	DRW_shgroup_uniform_int(grp, "texture_flip", &stl->shgroups[id].texture_flip, 1);
 
 	DRW_shgroup_uniform_int(grp, "xraymode", (const int *) &gpd->xray_mode, 1);
+	DRW_shgroup_uniform_int(grp, "drawmode", (const int *)&gpd->draw_mode, 1);
+
 	/* image texture */
 	if ((gp_style->flag & GP_STYLE_COLOR_TEX_MIX) ||
 	    (gp_style->fill_style & GP_STYLE_FILL_STYLE_TEXTURE))
@@ -1306,6 +1308,7 @@ static void DRW_gpencil_shgroups_create(
 	GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
 	GPENCIL_PassList *psl = ((GPENCIL_Data *)vedata)->psl;
 	bGPdata *gpd = (bGPdata *)ob->data;
+	DRWPass *stroke_pass = (gpd->draw_mode == GP_DRAWMODE_3D) ? psl->stroke_pass_3d : psl->stroke_pass_2d;
 
 	GpencilBatchGroup *elm = NULL;
 	DRWShadingGroup *shgrp = NULL;
@@ -1364,7 +1367,7 @@ static void DRW_gpencil_shgroups_create(
 				const int len = elm->vertex_idx - start_stroke;
 
 				shgrp = DRW_gpencil_shgroup_stroke_create(
-				        e_data, vedata, psl->stroke_pass, e_data->gpencil_stroke_sh,
+				        e_data, vedata, stroke_pass, e_data->gpencil_stroke_sh,
 				        ob, gpd, gps, gp_style, stl->storage->shgroup_id, elm->onion, scale);
 
 				DRW_shgroup_call_range_add(
@@ -1381,7 +1384,7 @@ static void DRW_gpencil_shgroups_create(
 				const int len = elm->vertex_idx - start_point;
 
 				shgrp = DRW_gpencil_shgroup_point_create(
-				        e_data, vedata, psl->stroke_pass, e_data->gpencil_point_sh,
+				        e_data, vedata, stroke_pass, e_data->gpencil_point_sh,
 				        ob, gpd, gp_style, stl->storage->shgroup_id, elm->onion, scale);
 
 				DRW_shgroup_call_range_add(
@@ -1398,7 +1401,7 @@ static void DRW_gpencil_shgroups_create(
 				const int len = elm->vertex_idx - start_fill;
 
 				shgrp = DRW_gpencil_shgroup_fill_create(
-				        e_data, vedata, psl->stroke_pass, e_data->gpencil_fill_sh,
+				        e_data, vedata, stroke_pass, e_data->gpencil_fill_sh,
 				        gpd, gpl, gp_style, stl->storage->shgroup_id);
 
 				DRW_shgroup_call_range_add(
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index dda0f5c1126..b440decf716 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -332,11 +332,16 @@ void GPENCIL_cache_init(void *vedata)
 	stl->g_data->gp_object_cache = NULL;
 
 	{
-		/* Stroke pass */
-		psl->stroke_pass = DRW_pass_create(
+		/* Stroke pass 2D */
+		psl->stroke_pass_2d = DRW_pass_create(
 		        "GPencil Stroke Pass",
 		        DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_ALWAYS | DRW_STATE_BLEND);
 		stl->storage->shgroup_id = 0;
+		/* Stroke pass 3D */
+		psl->stroke_pass_3d = DRW_pass_create(
+			"GPencil Stroke Pass",
+			DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_BLEND);
+		stl->storage->shgroup_id = 0;
 
 		/* edit pass */
 		psl->edit_pass = DRW_pass_create(
@@ -689,7 +694,7 @@ static void gpencil_free_obj_runtime(GPENCIL_StorageList *stl)
 static void gpencil_draw_pass_range(
 	GPENCIL_FramebufferList *fbl, GPENCIL_StorageList *stl,
 	GPENCIL_PassList *psl, GPENCIL_TextureList *txl,
-	GPUFrameBuffer *fb,
+	GPUFrameBuffer *fb, bGPdata *gpd,
 	DRWShadingGroup *init_shgrp, DRWShadingGroup *end_shgrp, bool multi)
 {
 	if (init_shgrp == NULL) {
@@ -702,7 +707,8 @@ static void gpencil_draw_pass_range(
 	}
 
 	DRW_draw_pass_subset(
-		psl->stroke_pass, init_shgrp, end_shgrp);
+		(gpd->draw_mode == GP_DRAWMODE_3D) ? psl->stroke_pass_3d : psl->stroke_pass_2d,
+		init_shgrp, end_shgrp);
 
 	if ((!stl->storage->is_mat_preview) && (multi)) {
 		MULTISAMPLE_GP_SYNC_DISABLE(stl->storage->multisamples, fbl, fb, txl);
@@ -811,7 +817,7 @@ void GPENCIL_draw_scene(void *ved)
 							/* draw pending groups */
 							gpencil_draw_pass_range(
 								fbl, stl, psl, txl, fbl->temp_fb_a,
-								init_shgrp, end_shgrp, is_last);
+								gpd, init_shgrp, end_shgrp, is_last);
 
 							/* draw current group in separated texture */
 							init_shgrp = array_elm->init_shgrp;
@@ -821,7 +827,7 @@ void GPENCIL_draw_scene(void *ved)
 							GPU_framebuffer_clear_color_depth(fbl->temp_fb_fx, clearcol, 1.0f);
 							gpencil_draw_pass_range(
 							        fbl, stl, psl, txl, fbl->temp_fb_fx,
-							        init_shgrp, end_shgrp,
+							        gpd, init_shgrp, end_shgrp,
 							        is_last);
 
 							/* Blend A texture and FX texture */
@@ -850,7 +856,7 @@ void GPENCIL_draw_scene(void *ved)
 					/* last group */
 					gpencil_draw_pass_range(
 					        fbl, stl, psl, txl, fbl->temp_fb_a,
-					        init_shgrp, end_shgrp,
+					        gpd, init_shgrp, end_shgrp,
 					        true);
 				}
 
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index 97e3b7c576e..376c4993f42 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -174,7 +174,8 @@ typedef struct GPENCIL_StorageList {
 } GPENCIL_StorageList;
 
 typedef struct GPENCIL_PassList {
-	struct DRWPass *stroke_pass;
+	struct DRWPass *stroke_pass_2d;
+	struct DRWPass *stroke_pass_3d;
 	struct DRWPass *edit_pass;
 	struct DRWPass *drawing_pass;
 	struct DRWPass *mix_pass;
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_fill_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_fill_frag.glsl
index 1d57cdc4bcf..435d9583fb0 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_fill_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_fill_frag.glsl
@@ -15,6 +15,7 @@ uniform int texture_mix;
 uniform int texture_flip;
 uniform float texture_opacity;
 uniform int xraymode;
+uniform int drawmode;
 uniform float layer_opacity;
 
 uniform sampler2D myTexture;
@@ -32,6 +33,9 @@ uniform int texture_clamp;
 #define GP_XRAY_3DSPACE 1
 #define GP_XRAY_BACK  2
 
+#define GP_DRAWMODE_2D 0
+#define GP_DRAWMODE_3D 1
+
 in vec4 finalColor;
 in vec2 texCoord_interp;
 out vec4 fragColor;
@@ -144,4 +148,9 @@ void main()
 	else {
 		gl_FragDepth = 0.000001;
 	}
+	
+	/* if 3D mode, move slightly the fill to avoid z-fighting between stroke and fill on same stroke */
+	if (drawmode == GP_DRAWMODE_3D) {
+		gl_FragDepth *= 1.0001;
+	}
 }
diff --git a/source/blender/makesdna/DNA_gpencil_types.h b/source/blender/makesdna/DNA_gpencil_types.h
index 4f9de5e6fd8..3c5b90acd60 100644
--- a/source/blender/makesdna/DNA_gpencil_types.h
+++ b/source/blender/makesdna/DNA_gpencil_types.h
@@ -510,7 +510,11 @@ typedef struct bGPdata {
 	char _pad2[6];
 	int   totstroke;
 	int   totpoint;
-	char _pad3[4];
+
+	/** Draw mode for strokes (eGP_DrawMode). */
+	short draw_mode;
+	char _pad3[2];
+
 	bGPgrid grid;
 
 	bGPdata_Runtime runtime;
@@ -616,6 +620,12 @@ typedef enum eGP_DepthOrdering {
 	GP_XRAY_BACK  = 2,
 } eGP_DepthOrdering;
 
+/* draw modes (Use 2D or 3D position) */
+typedef enum eGP_DrawMode {
+	GP_DRAWMODE_2D = 0,
+	GP_DRAWMODE_3D = 1
+} eGP_DrawMode;
+
 /* ***************************************** */
 /* Mode Checking Macros */
 
diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c
index d4859a2c202..cdbf32b1310 100644
--- a/source/blender/makesrna/intern/rna_gpencil.c
+++ b/source/blender/makesrna/intern/rna_gpencil.c
@@ -51,6 +51,12 @@ static const EnumPropertyItem parent_type_items[] = {
 };
 
 #ifndef RNA_RUNTIME
+static EnumPropertyItem rna_enum_gpencil_drawmodes_items[] = {
+	{GP_DRAWMODE_2D, "2D", 0, "2D Layers",	"Draw strokes using grease pencil layers to define order"},
+	{GP_DRAWMODE_3D, "3D", 0, "3D Space", "Draw strokes using real 3D position in 3D space"},
+	{0, NULL, 0, NULL, NULL},
+};
+
 static EnumPropertyItem rna_enum_gpencil_xraymodes_items[] = {
 	{GP_XRAY_FRONT, "FRONT", 0, "Front", "Draw all strokes in front"},
 	{GP_XRAY_3DSPACE, "3DSPACE", 0, "3D Space", "Draw strokes relative to other objects in 3D space"},
@@ -1490,6 +1496,14 @@ static void rna_def_gpencil_data(BlenderRNA *brna)
 	RNA_def_property_srna(prop, "IDMaterials"); /* see rna_ID.c */
 	RNA_def_property_collection_funcs(prop, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "rna_IDMaterials_assign_int");
 
+	/* draw modes */
+	prop = RNA_def_property(srna, "draw_mode", PROP_ENUM, PROP_NONE);
+	RNA_def_property_enum_sdna(prop, NULL, "draw_mode");
+	RNA_def_property_enum_items(prop, rna_enum_gpencil_drawmodes_items);
+	RNA_def_property_ui_text(prop, "Mode",
+		"Defines how the strokes are ordered in 3D space");
+	RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update");
+
 	/* xray modes */
 	prop = RNA_def_property(srna, "xray_mode", PROP_ENUM, PROP_NONE);
 	RNA_def_property_enum_sdna(prop, NULL, "xray_mode");



More information about the Bf-blender-cvs mailing list