diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_sample_texture.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_sample_texture.cc index a29e26dfe0a..f176912b7a0 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_attribute_sample_texture.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_sample_texture.cc @@ -54,6 +54,7 @@ static AttributeDomain get_result_domain(const GeometryComponent &component, { /* Use the domain of the result attribute if it already exists. */ ReadAttributePtr result_attribute = component.attribute_try_get_for_read(result_attribute_name); + if (result_attribute) { return result_attribute->domain(); } @@ -87,8 +88,17 @@ static void execute_on_component(GeometryComponent &component, const GeoNodeExec const AttributeDomain result_domain = get_result_domain( component, result_attribute_name, mapping_name); + ReadAttributePtr result_attribute = component.attribute_try_get_for_read(result_attribute_name); + + CustomDataType data_type = CD_PROP_COLOR; + + if (result_attribute && result_attribute->custom_data_type() == CD_PROP_FLOAT3) { + data_type = CD_PROP_FLOAT3; + } + OutputAttributePtr attribute_out = component.attribute_try_get_for_output( - result_attribute_name, result_domain, CD_PROP_COLOR); + result_attribute_name, result_domain, data_type); + if (!attribute_out) { return; } @@ -96,15 +106,33 @@ static void execute_on_component(GeometryComponent &component, const GeoNodeExec Float3ReadAttribute mapping_attribute = component.attribute_get_for_read( mapping_name, result_domain, {0, 0, 0}); - MutableSpan colors = attribute_out->get_span(); - for (const int i : IndexRange(mapping_attribute.size())) { - TexResult texture_result = {0}; - const float3 position = mapping_attribute[i]; - /* For legacy reasons we have to map [0, 1] to [-1, 1] to support uv mappings. */ - const float3 remapped_position = position * 2.0f - float3(1.0f); - BKE_texture_get_value(nullptr, texture, remapped_position, &texture_result, false); - colors[i] = {texture_result.tr, texture_result.tg, texture_result.tb, texture_result.ta}; + if (data_type == CD_PROP_FLOAT3) { + MutableSpan colors = attribute_out->get_span(); + + for (const int i : colors.index_range()) { + TexResult texture_result = {0}; + const float3 position = mapping_attribute[i]; + /* For legacy reasons we have to map [0, 1] to [-1, 1] to support uv mappings. */ + const float3 remapped_position = position * 2.0f - float3(1.0f); + BKE_texture_get_value(nullptr, texture, remapped_position, &texture_result, false); + + colors[i] = {texture_result.tr, texture_result.tg, texture_result.tb}; + } } + else { + MutableSpan colors = attribute_out->get_span(); + + for (const int i : colors.index_range()) { + TexResult texture_result = {0}; + const float3 position = mapping_attribute[i]; + /* For legacy reasons we have to map [0, 1] to [-1, 1] to support uv mappings. */ + const float3 remapped_position = position * 2.0f - float3(1.0f); + BKE_texture_get_value(nullptr, texture, remapped_position, &texture_result, false); + + colors[i] = {texture_result.tr, texture_result.tg, texture_result.tb, texture_result.ta}; + } + } + attribute_out.apply_span_and_save(); }