Commit: 377b52be2ea5fad2e4438415226ae062c04cf8d8
Author: Thomas Dinges
Date:   Tue Dec 22 13:53:13 2015 +0100
Branches: master
https://developer.blender.org/rB377b52be2ea5fad2e4438415226ae062c04cf8d8

Cycles: Constant fold for the Gamma Node.

===================================================================

M       intern/cycles/kernel/svm/svm_gamma.h
M       intern/cycles/kernel/svm/svm_math_util.h
M       intern/cycles/render/nodes.cpp
M       intern/cycles/render/nodes.h

===================================================================

diff --git a/intern/cycles/kernel/svm/svm_gamma.h 
b/intern/cycles/kernel/svm/svm_gamma.h
index b645ff3..171945a 100644
--- a/intern/cycles/kernel/svm/svm_gamma.h
+++ b/intern/cycles/kernel/svm/svm_gamma.h
@@ -21,12 +21,7 @@ ccl_device void svm_node_gamma(ShaderData *sd, float *stack, 
uint in_gamma, uint
        float3 color = stack_load_float3(stack, in_color);
        float gamma = stack_load_float(stack, in_gamma);
 
-       if(color.x > 0.0f)
-               color.x = powf(color.x, gamma);
-       if(color.y > 0.0f)
-               color.y = powf(color.y, gamma);
-       if(color.z > 0.0f)
-               color.z = powf(color.z, gamma);
+       color = svm_math_gamma_color(color, gamma);
 
        if(stack_valid(out_color))
                stack_store_float3(stack, out_color, color);
diff --git a/intern/cycles/kernel/svm/svm_math_util.h 
b/intern/cycles/kernel/svm/svm_math_util.h
index 645cbd3..3f7d18a 100644
--- a/intern/cycles/kernel/svm/svm_math_util.h
+++ b/intern/cycles/kernel/svm/svm_math_util.h
@@ -166,5 +166,17 @@ ccl_device float3 svm_math_blackbody_color(float t) {
        return make_float3(4.70366907f, 0.0f, 0.0f);
 }
 
+ccl_device_inline float3 svm_math_gamma_color(float3 color, float gamma)
+{
+       if(color.x > 0.0f)
+               color.x = powf(color.x, gamma);
+       if(color.y > 0.0f)
+               color.y = powf(color.y, gamma);
+       if(color.z > 0.0f)
+               color.z = powf(color.z, gamma);
+
+       return color;
+}
+
 CCL_NAMESPACE_END
 
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp
index 2771d35..678f7b3 100644
--- a/intern/cycles/render/nodes.cpp
+++ b/intern/cycles/render/nodes.cpp
@@ -3516,6 +3516,23 @@ GammaNode::GammaNode()
        add_output("Color", SHADER_SOCKET_COLOR);
 }
 
+bool GammaNode::constant_fold(ShaderOutput *socket, float3 *optimized_value)
+{
+       ShaderInput *color_in = input("Color");
+       ShaderInput *gamma_in = input("Gamma");
+
+       if(socket == output("Color")) {
+               if(color_in->link == NULL && gamma_in->link == NULL) {
+                       *optimized_value = svm_math_gamma_color(color_in->value,
+                                                               
gamma_in->value.x);
+
+                       return true;
+               }
+       }
+
+       return false;
+}
+
 void GammaNode::compile(SVMCompiler& compiler)
 {
        ShaderInput *color_in = input("Color");
diff --git a/intern/cycles/render/nodes.h b/intern/cycles/render/nodes.h
index 51efbc3..8c5f665 100644
--- a/intern/cycles/render/nodes.h
+++ b/intern/cycles/render/nodes.h
@@ -557,6 +557,9 @@ public:
 class GammaNode : public ShaderNode {
 public:
        SHADER_NODE_CLASS(GammaNode)
+
+       bool constant_fold(ShaderOutput *socket, float3 *optimized_value);
+
        virtual int get_group() { return NODE_GROUP_LEVEL_1; }
 };

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to