[Bf-blender-cvs] [e5522474891] blender2.8: MeshEditMode: refactor

Jeroen Bakker noreply at git.blender.org
Fri Jun 15 15:38:24 CEST 2018


Commit: e5522474891459c8a2a08a735666850f5756b96f
Author: Jeroen Bakker
Date:   Fri Jun 15 15:36:04 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBe5522474891459c8a2a08a735666850f5756b96f

MeshEditMode: refactor

- added a lib for shaded functions
- decreased active face inner size

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

M	source/blender/draw/CMakeLists.txt
M	source/blender/draw/modes/edit_mesh_mode.c
A	source/blender/draw/modes/shaders/edit_mesh_overlay_common_lib.glsl
M	source/blender/draw/modes/shaders/edit_mesh_overlay_frag.glsl
M	source/blender/draw/modes/shaders/edit_mesh_overlay_geom_edge.glsl
M	source/blender/draw/modes/shaders/edit_mesh_overlay_geom_tri.glsl

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

diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index 805da27b81b..2f268663186 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -244,6 +244,7 @@ data_to_c_simple(modes/shaders/armature_shape_outline_vert.glsl SRC)
 data_to_c_simple(modes/shaders/armature_shape_outline_geom.glsl SRC)
 data_to_c_simple(modes/shaders/armature_stick_vert.glsl SRC)
 data_to_c_simple(modes/shaders/armature_stick_frag.glsl SRC)
+data_to_c_simple(modes/shaders/edit_mesh_overlay_common_lib.glsl SRC)
 data_to_c_simple(modes/shaders/edit_mesh_overlay_frag.glsl SRC)
 data_to_c_simple(modes/shaders/edit_mesh_overlay_vert.glsl SRC)
 data_to_c_simple(modes/shaders/edit_mesh_overlay_geom_tri.glsl SRC)
diff --git a/source/blender/draw/modes/edit_mesh_mode.c b/source/blender/draw/modes/edit_mesh_mode.c
index 94eeb58dcb2..5544dea800f 100644
--- a/source/blender/draw/modes/edit_mesh_mode.c
+++ b/source/blender/draw/modes/edit_mesh_mode.c
@@ -45,6 +45,7 @@
 extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */
 extern struct GlobalsUboStorage ts; /* draw_common.c */
 
+extern char datatoc_edit_mesh_overlay_common_lib_glsl[];
 extern char datatoc_edit_mesh_overlay_frag_glsl[];
 extern char datatoc_edit_mesh_overlay_vert_glsl[];
 extern char datatoc_edit_mesh_overlay_geom_tri_glsl[];
@@ -178,6 +179,18 @@ static char *EDIT_MESH_sh_defines(ToolSettings *tsettings, RegionView3D *rv3d, b
 	BLI_dynstr_free(ds);
 	return str;
 }
+static char *EDIT_MESH_sh_lib()
+{
+	char *str = NULL;
+	DynStr *ds = BLI_dynstr_new();
+
+	BLI_dynstr_append(ds, datatoc_common_globals_lib_glsl);
+	BLI_dynstr_append(ds, datatoc_edit_mesh_overlay_common_lib_glsl);
+
+	str = BLI_dynstr_get_cstring(ds);
+	BLI_dynstr_free(ds);
+	return str;
+}
 
 static GPUShader *EDIT_MESH_ensure_shader(ToolSettings *tsettings, RegionView3D *rv3d, bool fast_mode, bool looseedge)
 {
@@ -185,12 +198,14 @@ static GPUShader *EDIT_MESH_ensure_shader(ToolSettings *tsettings, RegionView3D
 	if (looseedge) {
 		if (!e_data.overlay_loose_edge_sh_cache[index]) {
 			char *defines = EDIT_MESH_sh_defines(tsettings, rv3d, true);
+			char *lib = EDIT_MESH_sh_lib();
 			e_data.overlay_loose_edge_sh_cache[index] = DRW_shader_create_with_lib(
 			        datatoc_edit_mesh_overlay_vert_glsl,
 			        datatoc_edit_mesh_overlay_geom_edge_glsl,
 			        datatoc_edit_mesh_overlay_frag_glsl,
-			        datatoc_common_globals_lib_glsl,
+			        lib,
 			        defines);
+			MEM_freeN(lib);
 			MEM_freeN(defines);
 		}
 		return e_data.overlay_loose_edge_sh_cache[index];
@@ -198,12 +213,14 @@ static GPUShader *EDIT_MESH_ensure_shader(ToolSettings *tsettings, RegionView3D
 	else {
 		if (!e_data.overlay_tri_sh_cache[index]) {
 			char *defines = EDIT_MESH_sh_defines(tsettings, rv3d, true);
+			char *lib = EDIT_MESH_sh_lib();
 			e_data.overlay_tri_sh_cache[index] = DRW_shader_create_with_lib(
 			        datatoc_edit_mesh_overlay_vert_glsl,
 			        datatoc_edit_mesh_overlay_geom_tri_glsl,
 			        datatoc_edit_mesh_overlay_frag_glsl,
-			        datatoc_common_globals_lib_glsl,
+			        lib,
 			        defines);
+			MEM_freeN(lib);
 			MEM_freeN(defines);
 		}
 		return e_data.overlay_tri_sh_cache[index];
@@ -232,11 +249,13 @@ static void EDIT_MESH_engine_init(void *vedata)
 	}
 
 	if (!e_data.overlay_vert_sh) {
+		char *lib = EDIT_MESH_sh_lib();
 		e_data.overlay_vert_sh = DRW_shader_create_with_lib(
 		        datatoc_edit_mesh_overlay_loosevert_vert_glsl, NULL,
 		        datatoc_edit_mesh_overlay_frag_glsl,
-		        datatoc_common_globals_lib_glsl,
+		        lib,
 		        "#define VERTEX_SELECTION\n");
+		MEM_freeN(lib);
 	}
 	if (!e_data.overlay_facedot_sh) {
 		e_data.overlay_facedot_sh = DRW_shader_create_with_lib(
diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_common_lib.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_common_lib.glsl
new file mode 100644
index 00000000000..7caf3deaebe
--- /dev/null
+++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_common_lib.glsl
@@ -0,0 +1,55 @@
+#define EDGE_EXISTS     (1 << 0)
+#define EDGE_ACTIVE     (1 << 1)
+#define EDGE_SELECTED   (1 << 2)
+#define EDGE_SEAM       (1 << 3)
+#define EDGE_SHARP      (1 << 4)
+#define EDGE_VERTEX_ACTIVE   (1 << (0 + 8))
+#define EDGE_VERTEX_SELECTED (1 << (1 + 8))
+
+#define VERTEX_ACTIVE   (1 << 0)
+#define VERTEX_SELECTED (1 << 1)
+
+
+vec4 EDIT_MESH_edge_color_outer(int edge_flag, bool face_active, float crease, float bweight)
+{
+	vec4 color = vec4(0.0);
+	color = ((edge_flag & EDGE_SHARP) != 0) ? colorEdgeSharp : color;
+	color = (crease > 0.0) ? vec4(colorEdgeCrease.rgb, crease) : color;
+	color = (bweight > 0.0) ? vec4(colorEdgeBWeight.rgb, bweight) : color;
+	color = ((edge_flag & EDGE_SEAM) != 0) ? colorEdgeSeam : color;
+
+	if (face_active)
+	{
+		color = colorEditMeshActive;
+	}
+	return color;
+}
+
+vec4 EDIT_MESH_edge_color_inner(int edge_flag, bool face_active)
+{
+#ifdef EDGE_SELECTION
+	vec4 color = colorWireEdit;
+	color = ((edge_flag & EDGE_SELECTED) != 0) ? colorEdgeSelect : color;
+	color = ((edge_flag & EDGE_ACTIVE) != 0) ? colorEditMeshActive : color;
+
+#else
+	vec4 color = colorWireInactive;
+	color = ((edge_flag & EDGE_SELECTED) != 0) ? colorEdgeSelect : color;
+#endif
+	return color;
+}
+
+vec4 EDIT_MESH_vertex_color(int vertex_flag)
+{
+	if ((vertex_flag & (VERTEX_ACTIVE | VERTEX_SELECTED)) != 0)
+	{
+		return colorEdgeSelect;
+	}
+	else {
+#ifdef EDGE_SELECTION
+		return colorWireEdit;
+#else
+		return colorWireInactive;
+#endif
+	}
+}
\ No newline at end of file
diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_frag.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_frag.glsl
index eadb774c57e..203e7c3dddc 100644
--- a/source/blender/draw/modes/shaders/edit_mesh_overlay_frag.glsl
+++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_frag.glsl
@@ -44,18 +44,10 @@ flat in vec2 eData2[3];
 
 out vec4 FragColor;
 
-#define EDGE_EXISTS     (1 << 0)
-#define EDGE_ACTIVE     (1 << 1)
-#define EDGE_SELECTED   (1 << 2)
-#define EDGE_SEAM       (1 << 3)
-#define EDGE_SHARP      (1 << 4)
 /* Vertex flag is shifted and combined with the edge flag */
-#define VERTEX_ACTIVE   (1 << (0 + 8))
-#define VERTEX_SELECTED (1 << (1 + 8))
 #define FACE_ACTIVE     (1 << (2 + 8))
 
 #define LARGE_EDGE_SIZE 3.0
-#define LARGE_EDGE_SIZE_ACTIVE_FACE 5.0
 
 
 /* Style Parameters in pixel */
@@ -153,17 +145,7 @@ void main()
 			/* Outer large edge */
 			float largeEdge = e[v] - sizeEdge * LARGE_EDGE_SIZE;
 
-			vec4 large_edge_color = vec4(0.0);
-			large_edge_color = ((flag[v] & EDGE_SHARP) != 0) ? colorEdgeSharp : large_edge_color;
-			large_edge_color = (edgesCrease[v] > 0.0) ? vec4(colorEdgeCrease.rgb, edgesCrease[v]) : large_edge_color;
-			large_edge_color = (edgesBweight[v] > 0.0) ? vec4(colorEdgeBWeight.rgb, edgesBweight[v]) : large_edge_color;
-			large_edge_color = ((flag[v] & EDGE_SEAM) != 0) ? colorEdgeSeam : large_edge_color;
-
-			if ((flag[0] & FACE_ACTIVE) != 0)
-			{
-				large_edge_color = colorEditMeshActive;
-				largeEdge = e[v] - sizeEdge * LARGE_EDGE_SIZE_ACTIVE_FACE;
-			}
+			vec4 large_edge_color = EDIT_MESH_edge_color_outer(flag[v], (flag[0]& FACE_ACTIVE) != 0, edgesCrease[v], edgesBweight[v]);
 
 			if (large_edge_color.a != 0.0) {
 				colorDistEdge(large_edge_color, largeEdge);
@@ -178,14 +160,7 @@ void main()
 #ifdef VERTEX_SELECTION
 			colorDistEdge(vec4(vertexColor, 1.0), innerEdge);
 #else
-#  ifdef EDGE_SELECTION
-			vec4 inner_edge_color = colorWireEdit;
-			inner_edge_color = ((flag[v] & EDGE_SELECTED) != 0) ? colorEdgeSelect : inner_edge_color;
-			inner_edge_color = ((flag[v] & EDGE_ACTIVE) != 0) ? vec4(colorEditMeshActive.rgb, 1.0) : inner_edge_color;
-
-#  else
-			vec4 inner_edge_color = colorWireInactive;
-#  endif
+			vec4 inner_edge_color = EDIT_MESH_edge_color_inner(flag[v], (flag[0]& FACE_ACTIVE) != 0);
 			colorDistEdge(inner_edge_color, innerEdge);
 #endif
 		}
@@ -197,8 +172,8 @@ void main()
 		float size = p[v] - sizeVertex;
 
 		vec4 point_color = colorVertex;
-		point_color = ((flag[v] & VERTEX_SELECTED) != 0) ? colorVertexSelect : point_color;
-		point_color = ((flag[v] & VERTEX_ACTIVE) != 0) ? vec4(colorEditMeshActive.xyz, 1.0) : point_color;
+		point_color = ((flag[v] & EDGE_VERTEX_SELECTED) != 0) ? colorVertexSelect : point_color;
+		point_color = ((flag[v] & EDGE_VERTEX_ACTIVE) != 0) ? vec4(colorEditMeshActive.xyz, 1.0) : point_color;
 
 		colorDist(point_color, size);
 	}
diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_edge.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_edge.glsl
index 6702722e61f..0089f3b004c 100644
--- a/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_edge.glsl
+++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_edge.glsl
@@ -36,9 +36,6 @@ out float facing;
 noperspective out vec2 eData1;
 flat out vec2 eData2[3];
 
-#define VERTEX_ACTIVE   (1 << 0)
-#define VERTEX_SELECTED (1 << 1)
-
 #define FACE_ACTIVE     (1 << 2)
 #define FACE_SELECTED   (1 << 3)
 
@@ -71,22 +68,10 @@ float dist(vec2 pos[3], vec2 vpos, int v)
 	return abs(dot(vpos - e1, orthogonal));
 }
 
-vec3 getVertexColor(int v)
-{
-	if ((vData[v].x & (VERTEX_ACTIVE | VERTEX_SELECTED)) != 0)
-		return colorEdgeSelect.rgb;
-	else
-#ifdef EDGE_SELECTION
-		return colorWireEdit.rgb;
-#else
-		return colorWireInactive.rgb;
-#endif
-}
-
 void doVertex(int v, vec4 pos)
 {
 #ifdef VERTEX_SELECTION
-	vertexColor = getVertexColor(v);
+	vertexColor = EDIT_MESH_vertex_color(vData[v].x).rgb;
 #endif
 
 #ifdef VERTEX_FACING
diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_tri.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_tri.glsl
index 7e778c325a6..890144982ab 100644
--- a/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_tri.glsl
+++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_tri.glsl
@@ -55,9 +55,6 @@ out float facing;
 noperspective out vec2 eData1;
 flat out vec2 eData2[3];
 
-#define VERTEX_ACTIVE   (1 << 0)
-#define VERTEX_SELECTED (1 << 1)
-
 #define FACE_ACTIVE     (1 << 2)
 #define FACE_SELECTED   (1 << 3)
 
@@ -90,18 +87,6 @@ float dist(vec2 pos[3

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list