[Bf-blender-cvs] [6e81e5c7095] sculpt-mode-features: Sculpt vertex colors: Initial implementation

Pablo Dobarro noreply at git.blender.org
Fri Apr 5 17:57:44 CEST 2019


Commit: 6e81e5c70952004f6d24f58d2047227f2e73f1e9
Author: Pablo Dobarro
Date:   Fri Apr 5 17:56:58 2019 +0200
Branches: sculpt-mode-features
https://developer.blender.org/rB6e81e5c70952004f6d24f58d2047227f2e73f1e9

Sculpt vertex colors: Initial implementation

This adds a new CustomDataLayer to store per vertex color data in a way
that can be used from sculpt mode. This vertex paint mode uses the same
brush, pbvh, undo and rendering code as sculpt mode, so it has much
better performance.  It also enables other features like sculpting and
painting at the same time.

I also added some extra features that are needed to start testing this
paint mode, such as:
- New paint brush optimized for painting. It doesn't modify any vertex
position data.
- Sculpt mode sample color operator that uses the active vertex from the
cursor
- Remesh reprojection support: sculpt vertex colors are reprojected into
the new mesh when using the remesh operator if the mesh has that option
enabled.
- Store and load sculpt vertex colors into the regular vertex color
layers to keep compatibility.
- Use the single color display mode to disable sculpt vertex colors in
sculpt mode.

A lot of decisions needs to be made to integrate this in Blender, so I
decided to keep the implementation as unintrusive as possible to start
working on the tools. This has the following limitations:

- Sculpt and paint at the same time is only enabled in the draw brush.
You need to set the Color Mode to Mix in the brush options.
- Dyntopo and multires modes and viewport display are broken
- Only mix as a color blend mode
- No brush texture support
- Sculpt and color share the same strength
- Limited to one layer per object
- No rendering support. You will need to copy the sculpt vertex colors
to the old color layers first.

All of these issues should be addressed once the main workflow, final UI
and behavior are decided.

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

M	release/scripts/startup/bl_ui/properties_data_mesh.py
M	release/scripts/startup/bl_ui/space_topbar.py
M	release/scripts/startup/bl_ui/space_view3d_toolbar.py
M	source/blender/blenkernel/BKE_paint.h
M	source/blender/blenkernel/BKE_pbvh.h
M	source/blender/blenkernel/intern/customdata.c
M	source/blender/blenkernel/intern/paint.c
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/draw/engines/workbench/shaders/workbench_prepass_frag.glsl
M	source/blender/draw/engines/workbench/shaders/workbench_prepass_vert.glsl
M	source/blender/draw/engines/workbench/workbench_materials.c
M	source/blender/editors/object/object_edit.c
M	source/blender/editors/object/object_intern.h
M	source/blender/editors/object/object_ops.c
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h
M	source/blender/editors/sculpt_paint/sculpt_undo.c
M	source/blender/gpu/GPU_buffers.h
M	source/blender/gpu/intern/gpu_buffers.c
M	source/blender/makesdna/DNA_brush_types.h
M	source/blender/makesdna/DNA_customdata_types.h
M	source/blender/makesdna/DNA_mesh_types.h
M	source/blender/makesdna/DNA_meshdata_types.h
M	source/blender/makesrna/intern/rna_brush.c
M	source/blender/makesrna/intern/rna_mesh.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_mesh.py b/release/scripts/startup/bl_ui/properties_data_mesh.py
index de178496c56..bf2a1d00d20 100644
--- a/release/scripts/startup/bl_ui/properties_data_mesh.py
+++ b/release/scripts/startup/bl_ui/properties_data_mesh.py
@@ -453,6 +453,10 @@ class DATA_PT_vertex_colors(MeshButtonsPanel, Panel):
         col.operator("mesh.vertex_color_add", icon='ADD', text="")
         col.operator("mesh.vertex_color_remove", icon='REMOVE', text="")
 
+        row = layout.row()
+        col = row.column()
+        col.operator("object.vertex_to_loop_colors", text="Store sculpt color")
+        col.operator("object.loop_to_vertex_colors", text="Load sculpt color")
 
 class DATA_PT_remesh(MeshButtonsPanel, Panel):
     bl_label = "Remesh"
@@ -467,6 +471,7 @@ class DATA_PT_remesh(MeshButtonsPanel, Panel):
         mesh = context.mesh
         col.prop(mesh, "voxel_size")
         col.prop(mesh, "smooth_normals")
+        col.prop(mesh, "reproject_vertex_paint")
         col.operator("object.remesh", text="Remesh")
 
 
diff --git a/release/scripts/startup/bl_ui/space_topbar.py b/release/scripts/startup/bl_ui/space_topbar.py
index 7b9b324066a..71c46b2f931 100644
--- a/release/scripts/startup/bl_ui/space_topbar.py
+++ b/release/scripts/startup/bl_ui/space_topbar.py
@@ -229,8 +229,10 @@ class _draw_left_context_mode:
                 return
 
             from .properties_paint_common import (
+                UnifiedPaintPanel,
                 brush_basic_sculpt_settings,
             )
+            UnifiedPaintPanel.prop_unified_color(layout, context, brush, "color", text="")
             brush_basic_sculpt_settings(layout, context, brush, compact=True)
 
         @staticmethod
diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index aee7a01b34e..73021097218 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -313,6 +313,10 @@ class VIEW3D_PT_tools_brush(Panel, View3DPaintPanel):
             row = col.row()
             row.prop(brush, "automasking_mode")
 
+            col.separator()
+            row = col.row()
+            row.prop(brush, "sculpt_color_mix_mode")
+
             # topology_rake_factor
             if (
                     capabilities.has_topology_rake and
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index 7909900faa0..991f47e6366 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -209,6 +209,7 @@ typedef struct SculptSession {
 	int totvert, totpoly;
 	struct KeyBlock *kb;
 	float *vmask;
+	struct MVertCol *vcol;
 
 	/* Mesh connectivity */
 	struct MeshElemMap *pmap;
diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index 11f4a1be04b..118393a02c3 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -296,6 +296,8 @@ typedef struct PBVHVertexIter {
 	short *no;
 	float *fno;
 	float *mask;
+	struct MVertCol *col;
+	struct MVertCol *vcol;
 } PBVHVertexIter;
 
 void pbvh_vertex_iter_init(PBVH *bvh, PBVHNode *node,
@@ -337,6 +339,8 @@ void pbvh_vertex_iter_init(PBVH *bvh, PBVHNode *node,
 					vi.no = vi.mvert->no; \
 					if (vi.vmask) \
 						vi.mask = &vi.vmask[vi.vert_indices[vi.gx]]; \
+					if (vi.vcol) \
+						vi.col = &vi.vcol[vi.vert_indices[vi.gx]]; \
 				} \
 				else { \
 					if (!BLI_gsetIterator_done(&vi.bm_unique_verts)) {\
diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index 1b1cc1fa30f..5a2a5785a76 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -1372,6 +1372,10 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
 	{sizeof(short[4][3]), "", 0, NULL, NULL, NULL, NULL, layerSwap_flnor, NULL},
 	/* 41: CD_CUSTOMLOOPNORMAL */
 	{sizeof(short[2]), "vec2s", 1, NULL, NULL, NULL, NULL, NULL, NULL},
+	/* 42: CD_MVERTCOL */
+	{sizeof(MVertCol), "MVertCol", 1, N_("Col"), NULL, NULL, layerInterp_mloopcol, NULL,
+	 layerDefault_mloopcol, NULL, layerEqual_mloopcol, layerMultiply_mloopcol, layerInitMinMax_mloopcol,
+	 layerAdd_mloopcol, layerDoMinMax_mloopcol, layerCopyValue_mloopcol, NULL, NULL, NULL, layerMaxNum_mloopcol},
 };
 
 
@@ -1387,7 +1391,7 @@ static const char *LAYERTYPENAMES[CD_NUMTYPES] = {
 	/* 30-34 */ "CDSubSurfCrease", "CDOrigSpaceLoop", "CDPreviewLoopCol", "CDBMElemPyPtr", "CDPaintMask",
 	/* 35-36 */ "CDGridPaintMask", "CDMVertSkin",
 	/* 37-38 */ "CDFreestyleEdge", "CDFreestyleFace",
-	/* 39-41 */ "CDMLoopTangent", "CDTessLoopNormal", "CDCustomLoopNormal",
+	/* 39-42 */ "CDMLoopTangent", "CDTessLoopNormal", "CDCustomLoopNormal", "CDMVertCol"
 };
 
 
@@ -1406,7 +1410,7 @@ const CustomData_MeshMasks CD_MASK_BAREMESH_ORIGINDEX = {
     .pmask = CD_MASK_MPOLY | CD_MASK_FACEMAP | CD_MASK_ORIGINDEX,
 };
 const CustomData_MeshMasks CD_MASK_MESH = {
-    .vmask = (CD_MASK_MVERT | CD_MASK_MDEFORMVERT | CD_MASK_MVERT_SKIN | CD_MASK_PAINT_MASK | CD_MASK_GENERIC_DATA),
+    .vmask = (CD_MASK_MVERT | CD_MASK_MDEFORMVERT | CD_MASK_MVERT_SKIN | CD_MASK_PAINT_MASK | CD_MASK_GENERIC_DATA | CD_MASK_MVERTCOL),
     .emask = (CD_MASK_MEDGE | CD_MASK_FREESTYLE_EDGE | CD_MASK_GENERIC_DATA),
     .fmask = 0,
     .lmask = (CD_MASK_MLOOP | CD_MASK_MDISPS | CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_CUSTOMLOOPNORMAL |
@@ -1415,7 +1419,7 @@ const CustomData_MeshMasks CD_MASK_MESH = {
 };
 const CustomData_MeshMasks CD_MASK_EDITMESH = {
     .vmask = (CD_MASK_MDEFORMVERT | CD_MASK_PAINT_MASK | CD_MASK_MVERT_SKIN | CD_MASK_SHAPEKEY |
-              CD_MASK_SHAPE_KEYINDEX | CD_MASK_GENERIC_DATA),
+              CD_MASK_SHAPE_KEYINDEX | CD_MASK_GENERIC_DATA | CD_MASK_MVERTCOL),
     .emask = (CD_MASK_GENERIC_DATA),
     .fmask = 0,
     .lmask = (CD_MASK_MDISPS | CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_CUSTOMLOOPNORMAL |
@@ -1433,7 +1437,7 @@ const CustomData_MeshMasks CD_MASK_DERIVEDMESH = {
 };
 const CustomData_MeshMasks CD_MASK_BMESH = {
     .vmask = (CD_MASK_MDEFORMVERT | CD_MASK_BWEIGHT | CD_MASK_MVERT_SKIN | CD_MASK_SHAPEKEY |
-              CD_MASK_SHAPE_KEYINDEX | CD_MASK_PAINT_MASK | CD_MASK_GENERIC_DATA),
+              CD_MASK_SHAPE_KEYINDEX | CD_MASK_PAINT_MASK | CD_MASK_GENERIC_DATA | CD_MASK_MVERTCOL),
     .emask = (CD_MASK_BWEIGHT | CD_MASK_CREASE | CD_MASK_FREESTYLE_EDGE | CD_MASK_GENERIC_DATA),
     .fmask = 0,
     .lmask = (CD_MASK_MDISPS | CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_CUSTOMLOOPNORMAL |
@@ -1455,7 +1459,7 @@ const CustomData_MeshMasks CD_MASK_FACECORNERS = {
 const CustomData_MeshMasks CD_MASK_EVERYTHING = {
     .vmask = (CD_MASK_MVERT | CD_MASK_BM_ELEM_PYPTR | CD_MASK_ORIGINDEX | CD_MASK_NORMAL | CD_MASK_MDEFORMVERT |
               CD_MASK_BWEIGHT | CD_MASK_MVERT_SKIN | CD_MASK_ORCO | CD_MASK_CLOTH_ORCO | CD_MASK_SHAPEKEY |
-              CD_MASK_SHAPE_KEYINDEX | CD_MASK_PAINT_MASK | CD_MASK_GENERIC_DATA),
+              CD_MASK_SHAPE_KEYINDEX | CD_MASK_PAINT_MASK | CD_MASK_GENERIC_DATA | CD_MASK_MVERTCOL),
     .emask = (CD_MASK_MEDGE | CD_MASK_BM_ELEM_PYPTR | CD_MASK_ORIGINDEX | CD_MASK_BWEIGHT | CD_MASK_CREASE |
               CD_MASK_FREESTYLE_EDGE | CD_MASK_GENERIC_DATA),
     .fmask = (CD_MASK_MFACE | CD_MASK_ORIGINDEX | CD_MASK_NORMAL | CD_MASK_MTFACE | CD_MASK_MCOL |
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index be0d176dddc..8e30efbd73b 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -1119,6 +1119,7 @@ void BKE_sculpt_update_mesh_elements(
 		ss->mloop = me->mloop;
 		ss->multires = NULL;
 		ss->vmask = CustomData_get_layer(&me->vdata, CD_PAINT_MASK);
+		ss->vcol = CustomData_get_layer(&me->vdata, CD_MVERTCOL);
 	}
 
 	ss->subdiv_ccg = me_eval->runtime.subdiv_ccg;
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 17443c9ebdc..5ff90c41be4 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -1155,6 +1155,7 @@ static void pbvh_update_draw_buffers(PBVH *bvh, PBVHNode **nodes, int totnode)
 					        node->uniq_verts +
 					        node->face_verts,
 					        CustomData_get_layer(bvh->vdata, CD_PAINT_MASK),
+					        CustomData_get_layer(bvh->vdata, CD_MVERTCOL),
 					        node->face_vert_indices,
 					        update_flags);
 					break;
@@ -2350,6 +2351,24 @@ void pbvh_vertex_iter_init(PBVH *bvh, PBVHNode *node,
 	vi->mask = NULL;
 	if (bvh->type == PBVH_FACES)
 		vi->vmask = CustomData_get_layer(bvh->vdata, CD_PAINT_MASK);
+	vi->vcol = NULL;
+	if (bvh->type == PBVH_FACES)
+		vi->vcol = CustomData_get_layer(bvh->vdata, CD_MVERTCOL);
+}
+
+bool pbvh_has_color(PBVH *bvh)
+{
+	switch (bvh->type) {
+		case PBVH_GRIDS:
+			return false;
+		case PBVH_FACES:
+			return (bvh->vdata && CustomData_get_layer(bvh->vdata,
+			                      CD_MVERTCOL));
+		case PBVH_BMESH:
+			return false;
+	}
+
+	return false;
 }
 
 bool pbvh_has_mask(PBVH *bvh)
diff --git a/source/blender/draw/engines/workbench/shaders/workbench_prepass_frag.glsl b/source/blender/draw/engines/workbench/shaders/workbench_prepass_frag.glsl
index db51d3da15f..9a179e918ea 100644
--- a/source/blender/draw/engines/workbench/shaders/workbench_prepass_frag.glsl
+++ b/source/blender/draw/engines/workbench/shaders/workbench_prepass_frag.glsl
@@ -8,6 +8,7 @@ uniform sampler2D image;
 uniform float ImageTransparencyCutoff = 0.1;
 uniform bool imageSrgb;
 uniform bool imageNearest;
+uniform bool useVertexPaint;
 
 #ifdef NORMAL_VIEWPORT_PASS_ENABLED
 in vec3 normal_viewport;
@@ -31,6 +32,8 @@ layout(location=1) out uint objectId;
 layout(location=2) out WB_Normal normalViewport;
 #endif
 
+in vec4 out_color;
+
 void main()
 {
 #ifdef MATDATA_PASS_ENABLED
@@ -44,6 +47,10 @@ void main()
 	}
 #  else
 	color.rgb = materialDiffuseColor;
+	if (useVertexPaint) {
+		color.rgb = vec3(out_color.r, out_color.g, out_color.b);
+		color = srgb_to_linearrgb(color);
+	}
 #  endif
 
 #  ifdef V3D_LIGHTING_MATCAP
diff --gi

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list