diff options
author | OmarSquircleArt <omar.squircleart@gmail.com> | 2019-08-14 11:53:19 +0300 |
---|---|---|
committer | OmarSquircleArt <omar.squircleart@gmail.com> | 2019-08-14 11:53:19 +0300 |
commit | 7a7eadaf7f6be4008f49a83d76c5a6d5a6294f14 (patch) | |
tree | 8a064999db636d7c8c49f41156fd526193cee658 /intern/cycles/render/nodes.cpp | |
parent | c9acc5faad08422e07be59fc160a028a45b7440c (diff) |
Shading: Add a clamp option to the Map Range node.
If the option is enabled, the output is clamped to the target range.
The target range is [To Min, To Max]. The option is enabled by default.
The clamp option is implemented in EEVEE by linking to the `clamp_value`
GLSL function. And it is implemented in Cycles using a graph expand
function.
Reviewers: brecht, JacquesLucke
Differential Revision: https://developer.blender.org/D5477
Diffstat (limited to 'intern/cycles/render/nodes.cpp')
-rw-r--r-- | intern/cycles/render/nodes.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp index 18a7180c446..1a0225e19a8 100644 --- a/intern/cycles/render/nodes.cpp +++ b/intern/cycles/render/nodes.cpp @@ -5280,6 +5280,21 @@ MapRangeNode::MapRangeNode() : ShaderNode(node_type) { } +void MapRangeNode::expand(ShaderGraph *graph) +{ + if (clamp) { + ShaderOutput *result_out = output("Result"); + if (!result_out->links.empty()) { + ClampNode *clamp_node = new ClampNode(); + clamp_node->min = to_min; + clamp_node->max = to_max; + graph->add(clamp_node); + graph->relink(result_out, clamp_node->output("Result")); + graph->connect(result_out, clamp_node->input("Value")); + } + } +} + void MapRangeNode::constant_fold(const ConstantFolder &folder) { if (folder.all_inputs_constant()) { |