Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2021-08-20 11:44:29 +0300
committerJacques Lucke <jacques@blender.org>2021-08-20 11:44:29 +0300
commita9970d3cb92baa4991e7825b36033d8d69df43bd (patch)
tree4e641091519ed3179415b6baf4bd201f49d0ce40
parentb812f289f59625e0ee3073231f936c65ee70176a (diff)
bring back clamping in math node
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_math.cc31
1 files changed, 30 insertions, 1 deletions
diff --git a/source/blender/nodes/shader/nodes/node_shader_math.cc b/source/blender/nodes/shader/nodes/node_shader_math.cc
index 8e20a922c92..c30f2948ab1 100644
--- a/source/blender/nodes/shader/nodes/node_shader_math.cc
+++ b/source/blender/nodes/shader/nodes/node_shader_math.cc
@@ -106,13 +106,42 @@ static const blender::fn::MultiFunction *get_base_multi_function(bNode &node)
return nullptr;
}
+class ClampWrapperFunction : public blender::fn::MultiFunction {
+ private:
+ const blender::fn::MultiFunction &fn_;
+
+ public:
+ ClampWrapperFunction(const blender::fn::MultiFunction &fn) : fn_(fn)
+ {
+ this->set_signature(&fn.signature());
+ }
+
+ void call(blender::IndexMask mask,
+ blender::fn::MFParams params,
+ blender::fn::MFContext context) const override
+ {
+ fn_.call(mask, params, context);
+
+ /* Assumes the output parameter is the last one. */
+ const int output_param_index = this->param_amount() - 1;
+ /* This has actually been initialized in the call above. */
+ blender::MutableSpan<float> results = params.uninitialized_single_output<float>(
+ output_param_index);
+
+ for (const int i : mask) {
+ float &value = results[i];
+ CLAMP(value, 0.0f, 1.0f);
+ }
+ }
+};
+
static void sh_node_math_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
{
const blender::fn::MultiFunction *base_function = get_base_multi_function(builder.node());
const bool clamp_output = builder.node().custom2 != 0;
if (clamp_output) {
- /* TODO */
+ builder.construct_and_set_matching_fn<ClampWrapperFunction>(*base_function);
}
else {
builder.set_matching_fn(base_function);