diff options
author | Alexander Gavrilov <angavrilov@gmail.com> | 2016-09-29 00:35:53 +0300 |
---|---|---|
committer | Alexander Gavrilov <angavrilov@gmail.com> | 2016-10-01 14:37:03 +0300 |
commit | 40eedd5df9083ce54c38c6307946488a1fa8aae0 (patch) | |
tree | e3060fcab4e8ead3d6ec6c9254fddf5cf0b35aec /intern/cycles/render/nodes.cpp | |
parent | 95fa303efd0b6e2963af423e601bb2869ac82520 (diff) |
Cycles: implement partial constant folding for exponentiation.
This is also an important mathematical operation that can be folded
if it is known that one argument is a certain constant. For colors
the operation is provided as a Gamma node.
The SVM Gamma node needs a small fix to make it follow the 0 ^ 0 == 1
rule, same as the Power node, or the Gamma node itself in OSL mode.
Reviewers: #cycles
Differential Revision: https://developer.blender.org/D2263
Diffstat (limited to 'intern/cycles/render/nodes.cpp')
-rw-r--r-- | intern/cycles/render/nodes.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp index df43863ea7a..7ea52b28b9c 100644 --- a/intern/cycles/render/nodes.cpp +++ b/intern/cycles/render/nodes.cpp @@ -3896,6 +3896,19 @@ void GammaNode::constant_fold(const ConstantFolder& folder) if(folder.all_inputs_constant()) { folder.make_constant(svm_math_gamma_color(color, gamma)); } + else { + ShaderInput *color_in = input("Color"); + ShaderInput *gamma_in = input("Gamma"); + + /* 1 ^ X == X ^ 0 == 1 */ + if(folder.is_one(color_in) || folder.is_zero(gamma_in)) { + folder.make_one(); + } + /* X ^ 1 == X */ + else if(folder.is_one(gamma_in)) { + folder.try_bypass_or_make_constant(color_in, false); + } + } } void GammaNode::compile(SVMCompiler& compiler) |