Cycles: Constant fold for the Gamma Node.
authorThomas Dinges <blender@dingto.org>
Tue, 22 Dec 2015 12:53:13 +0000 (13:53 +0100)
committerThomas Dinges <blender@dingto.org>
Tue, 22 Dec 2015 12:53:13 +0000 (13:53 +0100)
intern/cycles/kernel/svm/svm_gamma.h
intern/cycles/kernel/svm/svm_math_util.h
intern/cycles/render/nodes.cpp
intern/cycles/render/nodes.h

index b645ff3f0f9f3d4299404d56af41e77b09deaa8d..171945a60bce20a7b6a7a6e5efaa3768ba012090 100644 (file)
@@ -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);
index 645cbd3fc734fb2ad0ebc1ac92cfad78b43a6f86..3f7d18a02fe3c0d87f03a7091799b28dfcaab3c5 100644 (file)
@@ -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
 
index 2771d35990e2f381a861d6e70e25ae68dc8ea834..678f7b313346d24cfb87016f969712bbf326242e 100644 (file)
@@ -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");
index 51efbc37f385e89557c21908534157878413e129..8c5f6651463580d4125245a6ff566652b1e6469e 100644 (file)
@@ -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; }
 };