diff options
author | Alexander Gavrilov <angavrilov@gmail.com> | 2016-07-30 21:03:49 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2016-07-31 03:34:34 +0300 |
commit | 1776f75c3b3621a28ed7af535192ce7f05faea8f (patch) | |
tree | 65df1e88a03007dd12444f73308292fd66eb9f06 /intern/cycles/render/nodes.cpp | |
parent | ea2ebf7a00f9adef9c14aaa24b79532b44043eba (diff) |
Cycles: constant fold add/mul type nodes with known 0 and 1 arguments.
These values often either turn the node into a no-op, or even make it
evaluate to 0 no matter what the other input value is, thus allowing
deletion of a branch of the node graph that otherwise is not constant.
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D2085
Diffstat (limited to 'intern/cycles/render/nodes.cpp')
-rw-r--r-- | intern/cycles/render/nodes.cpp | 43 |
1 files changed, 8 insertions, 35 deletions
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp index b3b010841e9..9009d71da2f 100644 --- a/intern/cycles/render/nodes.cpp +++ b/intern/cycles/render/nodes.cpp @@ -3701,44 +3701,11 @@ void MixNode::compile(OSLCompiler& compiler) void MixNode::constant_fold(const ConstantFolder& folder) { - ShaderInput *fac_in = input("Fac"); - ShaderInput *color1_in = input("Color1"); - ShaderInput *color2_in = input("Color2"); - - /* evaluate fully constant node */ if(folder.all_inputs_constant()) { folder.make_constant_clamp(svm_mix(type, fac, color1, color2), use_clamp); - return; - } - - /* remove no-op node when factor is 0.0 */ - if(!fac_in->link && fac <= 0.0f) { - /* note that some of the modes will clamp out of bounds values even without use_clamp */ - if(type == NODE_MIX_LIGHT || type == NODE_MIX_DODGE || type == NODE_MIX_BURN) { - if(!color1_in->link) { - folder.make_constant_clamp(svm_mix(type, 0.0f, color1, color1), use_clamp); - return; - } - } - else if(folder.try_bypass_or_make_constant(color1_in, color1, use_clamp)) { - return; - } } - - if(type == NODE_MIX_BLEND) { - /* remove useless mix colors nodes */ - if(color1_in->link ? (color1_in->link == color2_in->link) : (!color2_in->link && color1 == color2)) { - if(folder.try_bypass_or_make_constant(color1_in, color1, use_clamp)) { - return; - } - } - - /* remove no-op mix color node when factor is 1.0 */ - if(!fac_in->link && fac >= 1.0f) { - if(folder.try_bypass_or_make_constant(color2_in, color2, use_clamp)) { - return; - } - } + else { + folder.fold_mix(type, use_clamp); } } @@ -4624,6 +4591,9 @@ void MathNode::constant_fold(const ConstantFolder& folder) if(folder.all_inputs_constant()) { folder.make_constant_clamp(svm_math(type, value1, value2), use_clamp); } + else { + folder.fold_math(type, use_clamp); + } } void MathNode::compile(SVMCompiler& compiler) @@ -4696,6 +4666,9 @@ void VectorMathNode::constant_fold(const ConstantFolder& folder) folder.make_constant(vector); } } + else { + folder.fold_vector_math(type); + } } void VectorMathNode::compile(SVMCompiler& compiler) |