Cycles: add support for rendering sculpt vertex colors

Ref T78041
This commit is contained in:
Brecht Van Lommel 2020-06-25 13:48:44 +02:00
parent d69bb06db8
commit 8903368490
Notes: blender-bot 2023-02-14 09:02:41 +01:00
Referenced by issue #78248, Vertex color rendering freezes Blender and doesn't look right in Cycles
Referenced by issue #78041, Sculpt vertex color improvements for 2.91
3 changed files with 70 additions and 35 deletions

View File

@ -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) {

View File

@ -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;
if (desc.element == ATTR_ELEMENT_CORNER_BYTE || desc.element == ATTR_ELEMENT_VERTEX) {
float4 f0, f1, f2;
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) {
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)

View File

@ -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);