[Bf-blender-cvs] [2b3553eff2a] master: GP: Redesign wireframe mode

Antonioya noreply at git.blender.org
Tue Feb 26 17:09:36 CET 2019


Commit: 2b3553eff2a01cf3d1655183de9ebd416abde9c1
Author: Antonioya
Date:   Tue Feb 26 16:55:21 2019 +0100
Branches: master
https://developer.blender.org/rB2b3553eff2a01cf3d1655183de9ebd416abde9c1

GP: Redesign wireframe mode

Now it's possible use the different Wire modes (Single, Object & Random)

Also support for x-ray mode.

For random colors, the name of the object and the name of the layer is used.

Also some parameters cleanup.

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

M	release/scripts/startup/bl_ui/properties_object.py
M	source/blender/draw/engines/gpencil/gpencil_cache_utils.c
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/gpencil_shader_fx.c
M	source/blender/draw/engines/gpencil/shaders/gpencil_fill_frag.glsl
M	source/blender/draw/engines/gpencil/shaders/gpencil_point_vert.glsl
M	source/blender/draw/engines/gpencil/shaders/gpencil_stroke_vert.glsl

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

diff --git a/release/scripts/startup/bl_ui/properties_object.py b/release/scripts/startup/bl_ui/properties_object.py
index 2ec7f1df3a0..e87127c1274 100644
--- a/release/scripts/startup/bl_ui/properties_object.py
+++ b/release/scripts/startup/bl_ui/properties_object.py
@@ -221,6 +221,7 @@ class OBJECT_PT_display(ObjectButtonsPanel, Panel):
         is_wire = (obj_type in {'CAMERA', 'EMPTY'})
         is_empty_image = (obj_type == 'EMPTY' and obj.empty_display_type == 'IMAGE')
         is_dupli = (obj.instance_type != 'NONE')
+        is_gpencil = (obj_type == 'GPENCIL')
 
         col = flow.column()
         col.prop(obj, "show_name", text="Name")
@@ -262,7 +263,7 @@ class OBJECT_PT_display(ObjectButtonsPanel, Panel):
         row.active = obj.show_bounds or (obj.display_type == 'BOUNDS')
         row.prop(obj, "display_bounds_type", text="")
 
-        if is_geometry or is_empty_image:
+        if is_geometry or is_empty_image or is_gpencil:
             # Only useful with object having faces/materials...
             col = flow.column()
             col.prop(obj, "color")
diff --git a/source/blender/draw/engines/gpencil/gpencil_cache_utils.c b/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
index f6702f6f56b..c18aa27ea79 100644
--- a/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_cache_utils.c
@@ -45,6 +45,7 @@ tGPencilObjectCache *gpencil_object_cache_add(
 	const DRWContextState *draw_ctx = DRW_context_state_get();
 	tGPencilObjectCache *cache_elem = NULL;
 	RegionView3D *rv3d = draw_ctx->rv3d;
+	View3D *v3d = draw_ctx->v3d;
 	tGPencilObjectCache *p = NULL;
 
 	/* By default a cache is created with one block with a predefined number of free slots,
@@ -79,6 +80,16 @@ tGPencilObjectCache *gpencil_object_cache_add(
 	cache_elem->pixfactor = cache_elem->gpd->pixfactor;
 	cache_elem->shader_fx = ob->shader_fx;
 
+	/* save wire mode (object mode is always primary option) */
+	if (ob->dt == OB_WIRE) {
+		cache_elem->shading_type = (int)OB_WIRE;
+	}
+	else {
+		if (v3d) {
+			cache_elem->shading_type = (int)v3d->shading.type;
+		}
+	}
+
 	/* shgrp array */
 	cache_elem->tot_layers = 0;
 	int totgpl = BLI_listbase_count(&cache_elem->gpd->layers);
diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
index 7b2cf0bfe65..cbd50c848b9 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
@@ -30,6 +30,8 @@
 #include "BKE_material.h"
 #include "BKE_paint.h"
 
+#include "BLI_hash.h"
+
 #include "ED_gpencil.h"
 
 #include "DNA_gpencil_types.h"
@@ -243,13 +245,77 @@ static void DRW_gpencil_recalc_geometry_caches(
 	}
 }
 
+static void set_wireframe_color(Object *ob, bGPDlayer *gpl, View3D *v3d,
+	GPENCIL_StorageList *stl,
+	MaterialGPencilStyle *gp_style, int id)
+{
+	float color[4];
+	if (((gp_style->stroke_rgba[3] < GPENCIL_ALPHA_OPACITY_THRESH) ||
+		 (((gp_style->flag & GP_STYLE_STROKE_SHOW) == 0))) &&
+		(gp_style->fill_rgba[3] >= GPENCIL_ALPHA_OPACITY_THRESH))
+	{
+		copy_v4_v4(color, gp_style->fill_rgba);
+	}
+	else {
+		copy_v4_v4(color, gp_style->stroke_rgba);
+	}
+	float alpha = color[3];
+
+	/* wire color */
+	if ((v3d) && (id > -1)) {
+		switch (v3d->shading.wire_color_type) {
+			case V3D_SHADING_SINGLE_COLOR:
+			{
+				copy_v4_fl(stl->shgroups[id].wire_color, 0.8f);
+				stl->shgroups[id].wire_color[3] = alpha;
+				break;
+			}
+			case V3D_SHADING_OBJECT_COLOR:
+			{
+				copy_v4_v4(stl->shgroups[id].wire_color, ob->color);
+				stl->shgroups[id].wire_color[3] = alpha;
+				break;
+			}
+			case V3D_SHADING_RANDOM_COLOR:
+			{
+				uint gpl_hash = 1;
+				uint ob_hash = BLI_ghashutil_strhash_p_murmur(ob->id.name);
+				if (gpl) {
+					gpl_hash = BLI_ghashutil_strhash_p_murmur(gpl->info);
+				}
+
+				float hue = BLI_hash_int_01(ob_hash * gpl_hash);
+				float hsv[3] = { hue, 0.40f, 0.8f };
+				float wire_col[3];
+				hsv_to_rgb_v(hsv, &wire_col[0]);
+
+				stl->shgroups[id].wire_color[0] = wire_col[0];
+				stl->shgroups[id].wire_color[1] = wire_col[1];
+				stl->shgroups[id].wire_color[2] = wire_col[2];
+				stl->shgroups[id].wire_color[3] = alpha;
+				break;
+			}
+			default:
+			{
+				copy_v4_v4(stl->shgroups[id].wire_color, color);
+				break;
+			}
+		}
+	}
+	else {
+		copy_v4_v4(stl->shgroups[id].wire_color, color);
+	}
+}
+
 /* create shading group for filling */
 static DRWShadingGroup *DRW_gpencil_shgroup_fill_create(
         GPENCIL_e_data *e_data, GPENCIL_Data *vedata, DRWPass *pass,
-        GPUShader *shader, bGPdata *gpd, bGPDlayer *gpl,
-        MaterialGPencilStyle *gp_style, int id)
+        GPUShader *shader, Object *ob, bGPdata *gpd, bGPDlayer *gpl,
+        MaterialGPencilStyle *gp_style, int id, int shading_type)
 {
 	GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
+	const DRWContextState *draw_ctx = DRW_context_state_get();
+	View3D *v3d = draw_ctx->v3d;
 
 	/* e_data.gpencil_fill_sh */
 	DRWShadingGroup *grp = DRW_shgroup_create(shader, pass);
@@ -309,6 +375,17 @@ static DRWShadingGroup *DRW_gpencil_shgroup_fill_create(
 	DRW_shgroup_uniform_int(grp, "xraymode", (const int *) &gpd->xray_mode, 1);
 	DRW_shgroup_uniform_int(grp, "drawmode", (const int *) &gpd->draw_mode, 1);
 
+	/* viewport x-ray */
+	DRW_shgroup_uniform_int(grp, "viewport_xray", &stl->storage->is_xray, 1);
+
+	/* shading type */
+	stl->shgroups[id].shading_type = GPENCIL_USE_SOLID(stl) ? (int)OB_SOLID : shading_type;
+	DRW_shgroup_uniform_int(grp, "shading_type", &stl->shgroups[id].shading_type, 1);
+
+	/* wire color */
+	set_wireframe_color(ob, gpl, v3d, stl, gp_style, id);
+	DRW_shgroup_uniform_vec4(grp, "wire_color", stl->shgroups[id].wire_color, 1);
+
 	/* image texture */
 	if ((gp_style->flag & GP_STYLE_COLOR_TEX_MIX) ||
 	    (gp_style->fill_style & GP_STYLE_FILL_STYLE_TEXTURE))
@@ -359,11 +436,14 @@ bool DRW_gpencil_onion_active(bGPdata *gpd)
 /* create shading group for strokes */
 DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(
         GPENCIL_e_data *e_data, GPENCIL_Data *vedata, DRWPass *pass, GPUShader *shader, Object *ob,
-        bGPdata *gpd, bGPDstroke *gps, MaterialGPencilStyle *gp_style, int id,
-        bool onion, const float scale)
+        bGPdata *gpd, bGPDlayer *gpl, bGPDstroke *gps,
+		MaterialGPencilStyle *gp_style, int id,
+        bool onion, const float scale, int shading_type)
 {
 	GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
 	const float *viewport_size = DRW_viewport_size_get();
+	const DRWContextState *draw_ctx = DRW_context_state_get();
+	View3D *v3d = draw_ctx->v3d;
 
 	/* e_data.gpencil_stroke_sh */
 	DRWShadingGroup *grp = DRW_shgroup_create(shader, pass);
@@ -398,6 +478,13 @@ DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(
 		stl->shgroups[id].caps_mode[0] = gps->caps[0];
 		stl->shgroups[id].caps_mode[1] = gps->caps[1];
 		DRW_shgroup_uniform_int(grp, "caps_mode", &stl->shgroups[id].caps_mode[0], 2);
+
+		stl->shgroups[id].shading_type = (GPENCIL_USE_SOLID(stl) || onion) ? (int)OB_SOLID : shading_type;
+		DRW_shgroup_uniform_int(grp, "shading_type", &stl->shgroups[id].shading_type, 1);
+
+		/* wire color */
+		set_wireframe_color(ob, gpl, v3d, stl, gp_style, id);
+		DRW_shgroup_uniform_vec4(grp, "wire_color", stl->shgroups[id].wire_color, 1);
 	}
 	else {
 		stl->storage->obj_scale = 1.0f;
@@ -414,6 +501,9 @@ DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(
 		}
 		const int zero[2] = { 0, 0 };
 		DRW_shgroup_uniform_int(grp, "caps_mode", &zero[0], 2);
+
+		stl->shgroups[id].shading_type = (int)OB_SOLID;
+		DRW_shgroup_uniform_int(grp, "shading_type", &stl->shgroups[id].shading_type, 1);
 	}
 
 	if ((gpd) && (id > -1)) {
@@ -456,10 +546,14 @@ DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(
 /* create shading group for points */
 static DRWShadingGroup *DRW_gpencil_shgroup_point_create(
         GPENCIL_e_data *e_data, GPENCIL_Data *vedata, DRWPass *pass, GPUShader *shader, Object *ob,
-        bGPdata *gpd, MaterialGPencilStyle *gp_style, int id, bool onion, const float scale)
+        bGPdata *gpd, bGPDlayer *gpl,
+		MaterialGPencilStyle *gp_style, int id, bool onion,
+		const float scale, int shading_type)
 {
 	GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
 	const float *viewport_size = DRW_viewport_size_get();
+	const DRWContextState *draw_ctx = DRW_context_state_get();
+	View3D *v3d = draw_ctx->v3d;
 
 	/* e_data.gpencil_stroke_sh */
 	DRWShadingGroup *grp = DRW_shgroup_create(shader, pass);
@@ -491,6 +585,14 @@ static DRWShadingGroup *DRW_gpencil_shgroup_point_create(
 		DRW_shgroup_uniform_int(grp, "color_type", &stl->shgroups[id].color_type, 1);
 		DRW_shgroup_uniform_int(grp, "mode", &stl->shgroups[id].mode, 1);
 		DRW_shgroup_uniform_float(grp, "pixfactor", &gpd->pixfactor, 1);
+
+		stl->shgroups[id].shading_type = (GPENCIL_USE_SOLID(stl) || onion) ? (int)OB_SOLID : shading_type;
+		DRW_shgroup_uniform_int(grp, "shading_type", &stl->shgroups[id].shading_type, 1);
+
+		/* wire color */
+		set_wireframe_color(ob, gpl, v3d, stl, gp_style, id);
+		DRW_shgroup_uniform_vec4(grp, "wire_color", stl->shgroups[id].wire_color, 1);
+
 	}
 	else {
 		stl->storage->obj_scale = 1.0f;
@@ -507,6 +609,8 @@ static DRWShadingGroup *DRW_gpencil_shgroup_point_create(
 		else {
 			DRW_shgroup_uniform_float(grp, "pixfactor", &stl->storage->pixfactor, 1);
 		}
+		stl->shgroups[id].shading_type = (int)OB_SOLID;
+		DRW_shgroup_uniform_int(grp, "shading_type", &stl->shgroups[id].shading_type, 1);
 	}
 
 	if (gpd) {
@@ -598,7 +702,7 @@ static void gpencil_add_stroke_vertexdata(
         GpencilBatchCache *cache,
         Object *ob, bGPDlayer *gpl, bGPDframe *gpf, bGPDstroke *gps,
         const float opacity, const float tintcolor[4], const bool onion,
-        const bool custonion, const bool use_wiremode)
+        const bool custonion)
 {
 	float tcolor[4];
 	float ink[4];
@@ -616,15 +720,6 @@ static void gpencil_add_stroke_vertexdata(
 			else {
 				interp_v3_v3v3(tcolor, gps->runtime.tmp_stroke_rgba, tintcolor, tintcolor[3]);
 				tcolor[3] = gps->runtime.tmp_stroke_rgba[3] * opacity;
-
-				if ((use_wiremode) &&
-				    ((gps->runtime.tmp_stroke_rg

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list