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
This commit is contained in:
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user