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:
authorAlexander Gavrilov <angavrilov@gmail.com>2016-09-29 00:35:53 +0300
committerAlexander Gavrilov <angavrilov@gmail.com>2016-10-01 14:37:03 +0300
commit40eedd5df9083ce54c38c6307946488a1fa8aae0 (patch)
treee3060fcab4e8ead3d6ec6c9254fddf5cf0b35aec /intern/cycles/render/constant_fold.cpp
parent95fa303efd0b6e2963af423e601bb2869ac82520 (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/constant_fold.cpp')
-rw-r--r--intern/cycles/render/constant_fold.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/intern/cycles/render/constant_fold.cpp b/intern/cycles/render/constant_fold.cpp
index 200a4c497cd..b7f25663bc3 100644
--- a/intern/cycles/render/constant_fold.cpp
+++ b/intern/cycles/render/constant_fold.cpp
@@ -89,6 +89,19 @@ void ConstantFolder::make_zero() const
}
}
+void ConstantFolder::make_one() const
+{
+ if(output->type() == SocketType::FLOAT) {
+ make_constant(1.0f);
+ }
+ else if(SocketType::is_float3(output->type())) {
+ make_constant(make_float3(1.0f, 1.0f, 1.0f));
+ }
+ else {
+ assert(0);
+ }
+}
+
void ConstantFolder::bypass(ShaderOutput *new_output) const
{
assert(new_output);
@@ -321,6 +334,15 @@ void ConstantFolder::fold_math(NodeMath type, bool clamp) const
make_zero();
}
break;
+ case NODE_MATH_POWER:
+ /* 1 ^ X == X ^ 0 == 1 */
+ if(is_one(value1_in) || is_zero(value2_in)) {
+ make_one();
+ }
+ /* X ^ 1 == X */
+ else if(is_one(value2_in)) {
+ try_bypass_or_make_constant(value1_in, clamp);
+ }
default:
break;
}