[Bf-blender-cvs] [89033684907] master: Cycles: add support for rendering sculpt vertex colors

Brecht Van Lommel noreply at git.blender.org
Thu Jun 25 14:00:19 CEST 2020


Commit: 890336849071dd716bc254edbbfa474ed9e61432
Author: Brecht Van Lommel
Date:   Thu Jun 25 13:48:44 2020 +0200
Branches: master
https://developer.blender.org/rB890336849071dd716bc254edbbfa474ed9e61432

Cycles: add support for rendering sculpt vertex colors

Ref T78041

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

M	intern/cycles/blender/blender_mesh.cpp
M	intern/cycles/kernel/geom/geom_triangle.h
M	source/blender/editors/space_node/drawnode.c

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

diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp
index a6f380a9ae7..49407799fcd 100644
--- a/intern/cycles/blender/blender_mesh.cpp
+++ b/intern/cycles/blender/blender_mesh.cpp
@@ -278,25 +278,59 @@ static void mikk_compute_tangents(
   genTangSpaceDefault(&context);
 }
 
+/* Create sculpt vertex color attributes. */
+static void attr_create_sculpt_vertex_color(Scene *scene,
+                                            Mesh *mesh,
+                                            BL::Mesh &b_mesh,
+                                            bool subdivision)
+{
+  BL::Mesh::sculpt_vertex_colors_iterator l;
+
+  for (b_mesh.sculpt_vertex_colors.begin(l); l != b_mesh.sculpt_vertex_colors.end(); ++l) {
+    const bool active_render = l->active_render();
+    AttributeStandard vcol_std = (active_render) ? ATTR_STD_VERTEX_COLOR : ATTR_STD_NONE;
+    ustring vcol_name = ustring(l->name().c_str());
+
+    const bool need_vcol = mesh->need_attribute(scene, vcol_name) ||
+                           mesh->need_attribute(scene, vcol_std);
+
+    if (!need_vcol) {
+      continue;
+    }
+
+    AttributeSet &attributes = (subdivision) ? mesh->subd_attributes : mesh->attributes;
+    Attribute *vcol_attr = attributes.add(vcol_name, TypeRGBA, ATTR_ELEMENT_VERTEX);
+    vcol_attr->std = vcol_std;
+
+    float4 *cdata = vcol_attr->data_float4();
+    int numverts = b_mesh.vertices.length();
+
+    for (int i = 0; i < numverts; i++) {
+      *(cdata++) = get_float4(l->data[i].color());
+    }
+  }
+}
+
 /* Create vertex color attributes. */
 static void attr_create_vertex_color(Scene *scene, Mesh *mesh, BL::Mesh &b_mesh, bool subdivision)
 {
-  if (subdivision) {
-    BL::Mesh::vertex_colors_iterator l;
+  BL::Mesh::vertex_colors_iterator l;
 
-    for (b_mesh.vertex_colors.begin(l); l != b_mesh.vertex_colors.end(); ++l) {
-      const bool active_render = l->active_render();
-      AttributeStandard vcol_std = (active_render) ? ATTR_STD_VERTEX_COLOR : ATTR_STD_NONE;
-      ustring vcol_name = ustring(l->name().c_str());
+  for (b_mesh.vertex_colors.begin(l); l != b_mesh.vertex_colors.end(); ++l) {
+    const bool active_render = l->active_render();
+    AttributeStandard vcol_std = (active_render) ? ATTR_STD_VERTEX_COLOR : ATTR_STD_NONE;
+    ustring vcol_name = ustring(l->name().c_str());
 
-      const bool need_vcol = mesh->need_attribute(scene, vcol_name) ||
-                             mesh->need_attribute(scene, vcol_std);
+    const bool need_vcol = mesh->need_attribute(scene, vcol_name) ||
+                           mesh->need_attribute(scene, vcol_std);
 
-      if (!need_vcol) {
-        continue;
-      }
+    if (!need_vcol) {
+      continue;
+    }
 
-      Attribute *vcol_attr = NULL;
+    Attribute *vcol_attr = NULL;
+
+    if (subdivision) {
       if (active_render) {
         vcol_attr = mesh->subd_attributes.add(vcol_std, vcol_name);
       }
@@ -316,22 +350,7 @@ static void attr_create_vertex_color(Scene *scene, Mesh *mesh, BL::Mesh &b_mesh,
         }
       }
     }
-  }
-  else {
-    BL::Mesh::vertex_colors_iterator l;
-    for (b_mesh.vertex_colors.begin(l); l != b_mesh.vertex_colors.end(); ++l) {
-      const bool active_render = l->active_render();
-      AttributeStandard vcol_std = (active_render) ? ATTR_STD_VERTEX_COLOR : ATTR_STD_NONE;
-      ustring vcol_name = ustring(l->name().c_str());
-
-      const bool need_vcol = mesh->need_attribute(scene, vcol_name) ||
-                             mesh->need_attribute(scene, vcol_std);
-
-      if (!need_vcol) {
-        continue;
-      }
-
-      Attribute *vcol_attr = NULL;
+    else {
       if (active_render) {
         vcol_attr = mesh->attributes.add(vcol_std, vcol_name);
       }
@@ -828,6 +847,7 @@ static void create_mesh(Scene *scene,
    */
   attr_create_pointiness(scene, mesh, b_mesh, subdivision);
   attr_create_vertex_color(scene, mesh, b_mesh, subdivision);
+  attr_create_sculpt_vertex_color(scene, mesh, b_mesh, subdivision);
   attr_create_random_per_island(scene, mesh, b_mesh, subdivision);
 
   if (subdivision) {
diff --git a/intern/cycles/kernel/geom/geom_triangle.h b/intern/cycles/kernel/geom/geom_triangle.h
index a2731bf2bd0..0278f3ade8e 100644
--- a/intern/cycles/kernel/geom/geom_triangle.h
+++ b/intern/cycles/kernel/geom/geom_triangle.h
@@ -312,12 +312,21 @@ ccl_device float4 triangle_attribute_float4(KernelGlobals *kg,
                                             float4 *dx,
                                             float4 *dy)
 {
-  if (desc.element == ATTR_ELEMENT_CORNER_BYTE) {
-    int tri = desc.offset + sd->prim * 3;
-
-    float4 f0 = color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, tri + 0));
-    float4 f1 = color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, tri + 1));
-    float4 f2 = color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, tri + 2));
+  if (desc.element == ATTR_ELEMENT_CORNER_BYTE || desc.element == ATTR_ELEMENT_VERTEX) {
+    float4 f0, f1, f2;
+
+    if (desc.element == ATTR_ELEMENT_CORNER_BYTE) {
+      int tri = desc.offset + sd->prim * 3;
+      f0 = color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, tri + 0));
+      f1 = color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, tri + 1));
+      f2 = color_uchar4_to_float4(kernel_tex_fetch(__attributes_uchar4, tri + 2));
+    }
+    else {
+      uint4 tri_vindex = kernel_tex_fetch(__tri_vindex, sd->prim);
+      f0 = kernel_tex_fetch(__attributes_float3, desc.offset + tri_vindex.x);
+      f1 = kernel_tex_fetch(__attributes_float3, desc.offset + tri_vindex.y);
+      f2 = kernel_tex_fetch(__attributes_float3, desc.offset + tri_vindex.z);
+    }
 
 #ifdef __RAY_DIFFERENTIALS__
     if (dx)
diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index c3ebbeb5889..234ca5d5ce6 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -1014,8 +1014,14 @@ static void node_shader_buts_vertex_color(uiLayout *layout, bContext *C, Pointer
   PointerRNA obptr = CTX_data_pointer_get(C, "active_object");
   if (obptr.data && RNA_enum_get(&obptr, "type") == OB_MESH) {
     PointerRNA dataptr = RNA_pointer_get(&obptr, "data");
-    uiItemPointerR(
-        layout, ptr, "layer_name", &dataptr, "sculpt_vertex_colors", "", ICON_GROUP_VCOL);
+
+    if (RNA_collection_length(&dataptr, "sculpt_vertex_colors")) {
+      uiItemPointerR(
+          layout, ptr, "layer_name", &dataptr, "sculpt_vertex_colors", "", ICON_GROUP_VCOL);
+    }
+    else {
+      uiItemPointerR(layout, ptr, "layer_name", &dataptr, "vertex_colors", "", ICON_GROUP_VCOL);
+    }
   }
   else {
     uiItemL(layout, "No mesh in active object.", ICON_ERROR);



More information about the Bf-blender-cvs mailing list