diff options
author | Kévin Dietrich <kevin.dietrich@mailoo.org> | 2021-08-12 10:59:05 +0300 |
---|---|---|
committer | Kévin Dietrich <kevin.dietrich@mailoo.org> | 2021-08-12 10:59:05 +0300 |
commit | 2875995efe0f99b22ccf8e60087251d59d6814f1 (patch) | |
tree | 7540644e4d9f114bf2e49f76239329d1f02a4509 /intern | |
parent | 2941fd6afde16836171e18ad656f1a2e59ec36ce (diff) |
Fallback to object texture coordinates if no original coordinates are found
Diffstat (limited to 'intern')
-rw-r--r-- | intern/cycles/kernel/svm/svm_attribute.h | 48 | ||||
-rw-r--r-- | intern/cycles/render/alembic.cpp | 33 |
2 files changed, 48 insertions, 33 deletions
diff --git a/intern/cycles/kernel/svm/svm_attribute.h b/intern/cycles/kernel/svm/svm_attribute.h index f598bfb8f8f..62740824ad1 100644 --- a/intern/cycles/kernel/svm/svm_attribute.h +++ b/intern/cycles/kernel/svm/svm_attribute.h @@ -72,6 +72,22 @@ ccl_device void svm_node_attr(KernelGlobals *kg, ShaderData *sd, float *stack, u } #endif + if (node.y == ATTR_STD_GENERATED && desc.element == ATTR_ELEMENT_NONE) { + /* No generated attribute, fall back to object coordinates. */ + float3 f = sd->P; + object_inverse_position_transform(kg, sd, &f); + if (type == NODE_ATTR_OUTPUT_FLOAT) { + stack_store_float(stack, out_offset, average(f)); + } + else if (type == NODE_ATTR_OUTPUT_FLOAT3) { + stack_store_float3(stack, out_offset, f); + } + else { + stack_store_float(stack, out_offset, 1.0f); + } + return; + } + /* Surface. */ if (desc.type == NODE_ATTR_FLOAT) { float f = primitive_surface_attribute_float(kg, sd, desc, NULL, NULL); @@ -145,6 +161,22 @@ ccl_device void svm_node_attr_bump_dx(KernelGlobals *kg, ShaderData *sd, float * } #endif + if (node.y == ATTR_STD_GENERATED && desc.element == ATTR_ELEMENT_NONE) { + /* No generated attribute, fall back to object coordinates. */ + float3 f = sd->P + sd->dP.dx; + object_inverse_position_transform(kg, sd, &f); + if (type == NODE_ATTR_OUTPUT_FLOAT) { + stack_store_float(stack, out_offset, average(f)); + } + else if (type == NODE_ATTR_OUTPUT_FLOAT3) { + stack_store_float3(stack, out_offset, f); + } + else { + stack_store_float(stack, out_offset, 1.0f); + } + return; + } + /* Surface */ if (desc.type == NODE_ATTR_FLOAT) { float dx; @@ -222,6 +254,22 @@ ccl_device void svm_node_attr_bump_dy(KernelGlobals *kg, ShaderData *sd, float * } #endif + if (node.y == ATTR_STD_GENERATED && desc.element == ATTR_ELEMENT_NONE) { + /* No generated attribute, fall back to object coordinates. */ + float3 f = sd->P + sd->dP.dy; + object_inverse_position_transform(kg, sd, &f); + if (type == NODE_ATTR_OUTPUT_FLOAT) { + stack_store_float(stack, out_offset, average(f)); + } + else if (type == NODE_ATTR_OUTPUT_FLOAT3) { + stack_store_float3(stack, out_offset, f); + } + else { + stack_store_float(stack, out_offset, 1.0f); + } + return; + } + /* Surface */ if (desc.type == NODE_ATTR_FLOAT) { float dy; diff --git a/intern/cycles/render/alembic.cpp b/intern/cycles/render/alembic.cpp index c1a3cf91a02..a2ace6d9054 100644 --- a/intern/cycles/render/alembic.cpp +++ b/intern/cycles/render/alembic.cpp @@ -954,12 +954,6 @@ static void update_attributes(AttributeSet &attributes, CachedData &cached_data, /* remove any attributes not in cached_attributes */ list<Attribute>::iterator it; for (it = attributes.attributes.begin(); it != attributes.attributes.end();) { - /* Do not remove generated attribute, it will be updated in the data reading function */ - if (it->std == ATTR_STD_GENERATED) { - ++it; - continue; - } - if (cached_attributes.find(&(*it)) == cached_attributes.end()) { attributes.remove(it++); continue; @@ -1309,14 +1303,6 @@ void AlembicProcedural::read_mesh(AlembicObject *abc_object, Abc::chrono_t frame cached_data.min_delta.copy_to_socket(frame_time, mesh, mesh->get_min_delta_socket()); cached_data.max_delta.copy_to_socket(frame_time, mesh, mesh->get_max_delta_socket()); - /* we don't yet support arbitrary attributes, for now add vertex - * coordinates as generated coordinates if requested */ - if (mesh->need_attribute(scene_, ATTR_STD_GENERATED)) { - Attribute *attr = mesh->attributes.add(ATTR_STD_GENERATED); - memcpy( - attr->data_float3(), mesh->get_verts().data(), sizeof(float3) * mesh->get_verts().size()); - } - if (mesh->is_modified()) { bool need_rebuild = mesh->triangles_is_modified(); mesh->tag_update(scene_, need_rebuild); @@ -1408,14 +1394,6 @@ void AlembicProcedural::read_subd(AlembicObject *abc_object, Abc::chrono_t frame update_attributes(mesh->subd_attributes, cached_data, frame_time); - /* we don't yet support arbitrary attributes, for now add vertex - * coordinates as generated coordinates if requested */ - if (mesh->need_attribute(scene_, ATTR_STD_GENERATED)) { - Attribute *attr = mesh->attributes.add(ATTR_STD_GENERATED); - memcpy( - attr->data_float3(), mesh->get_verts().data(), sizeof(float3) * mesh->get_verts().size()); - } - if (mesh->is_modified()) { bool need_rebuild = (mesh->triangles_is_modified()) || (mesh->subd_num_corners_is_modified()) || @@ -1465,17 +1443,6 @@ void AlembicProcedural::read_curves(AlembicObject *abc_object, Abc::chrono_t fra update_attributes(hair->attributes, cached_data, frame_time); - /* we don't yet support arbitrary attributes, for now add first keys as generated coordinates if - * requested */ - if (hair->need_attribute(scene_, ATTR_STD_GENERATED)) { - Attribute *attr_generated = hair->attributes.add(ATTR_STD_GENERATED); - float3 *generated = attr_generated->data_float3(); - - for (size_t i = 0; i < hair->num_curves(); i++) { - generated[i] = hair->get_curve_keys()[hair->get_curve(i).first_key]; - } - } - cached_data.min_delta.copy_to_socket(frame_time, hair, hair->get_min_delta_socket()); cached_data.max_delta.copy_to_socket(frame_time, hair, hair->get_max_delta_socket()); |