diff options
author | Jacques Lucke <jacques@blender.org> | 2021-02-09 13:44:58 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-02-09 13:45:04 +0300 |
commit | 17672efa0e02172b77eed95bfb977c914a5305b9 (patch) | |
tree | 12e7f61bd3dd47a9585cc45e473a3f36fcfca041 /source/blender/blenkernel/intern/attribute_math.cc | |
parent | 4601e3a5916c7746ad29d20add91651929c6f621 (diff) |
Geometry Nodes: initial attribute interpolation between domains
This patch adds support for accessing corner attributes on the point domain.
The immediate benefit of this is that now (interpolated) uv coordinates are
available on points without having to use the Point Distribute node.
This is also very useful for parts of T84297, because once we have vertex
colors, those will also be available on points, even though they are stored
per corner.
Differential Revision: https://developer.blender.org/D10305
Diffstat (limited to 'source/blender/blenkernel/intern/attribute_math.cc')
-rw-r--r-- | source/blender/blenkernel/intern/attribute_math.cc | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/attribute_math.cc b/source/blender/blenkernel/intern/attribute_math.cc new file mode 100644 index 00000000000..4ff3a6ceff5 --- /dev/null +++ b/source/blender/blenkernel/intern/attribute_math.cc @@ -0,0 +1,58 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "BKE_attribute_math.hh" + +namespace blender::attribute_math { + +Color4fMixer::Color4fMixer(MutableSpan<Color4f> output_buffer, Color4f default_color) + : buffer_(output_buffer), + default_color_(default_color), + total_weights_(output_buffer.size(), 0.0f) +{ + buffer_.fill(Color4f(0, 0, 0, 0)); +} + +void Color4fMixer::mix_in(const int64_t index, const Color4f &color, const float weight) +{ + BLI_assert(weight >= 0.0f); + Color4f &output_color = buffer_[index]; + output_color.r += color.r * weight; + output_color.g += color.g * weight; + output_color.b += color.b * weight; + output_color.a += color.a * weight; + total_weights_[index] += weight; +} + +void Color4fMixer::finalize() +{ + for (const int64_t i : buffer_.index_range()) { + const float weight = total_weights_[i]; + Color4f &output_color = buffer_[i]; + if (weight > 0.0f) { + const float weight_inv = 1.0f / weight; + output_color.r *= weight_inv; + output_color.g *= weight_inv; + output_color.b *= weight_inv; + output_color.a *= weight_inv; + } + else { + output_color = default_color_; + } + } +} + +} // namespace blender::attribute_math |