Cycles: Fold Value and RGB node as well.
authorThomas Dinges <blender@dingto.org>
Sun, 6 Dec 2015 22:47:38 +0000 (23:47 +0100)
committerThomas Dinges <blender@dingto.org>
Sun, 6 Dec 2015 22:47:38 +0000 (23:47 +0100)
This way, connecting Value or RGB node to e.g. a Math node will still allow folding.

Note: The same should be done for the ConvertNode, but I leave that for another day.

intern/cycles/render/graph.cpp
intern/cycles/render/nodes.cpp
intern/cycles/render/nodes.h

index c9f39d449a45b68f69ce05e2391028218c6aa01a..def43876adaa3e808ca429d771e3ca40c030bdb7 100644 (file)
@@ -617,7 +617,7 @@ void ShaderGraph::constant_fold()
                         */
                        foreach(ShaderInput *input, output->links) {
                                if(scheduled.find(input->parent) != scheduled.end()) {
-                                       /* Node might be not yet optimized but scheduled already
+                                       /* Node might not be optimized yet but scheduled already
                                         * by other dependencies. No need to re-schedule it.
                                         */
                                        continue;
index fd8410ce71b8b42aae6fcb3b78324bf861d52cad..e4f5885df0d1268bf8a2b09259931ab3691a2f2b 100644 (file)
@@ -3177,6 +3177,13 @@ ValueNode::ValueNode()
        add_output("Value", SHADER_SOCKET_FLOAT);
 }
 
+bool ValueNode::constant_fold(ShaderOutput *socket, float3 *optimized_value)
+{
+       *optimized_value = make_float3(value, value, value);
+
+       return true;
+}
+
 void ValueNode::compile(SVMCompiler& compiler)
 {
        ShaderOutput *val_out = output("Value");
@@ -3201,6 +3208,13 @@ ColorNode::ColorNode()
        add_output("Color", SHADER_SOCKET_COLOR);
 }
 
+bool ColorNode::constant_fold(ShaderOutput *socket, float3 *optimized_value)
+{
+       *optimized_value = value;
+
+       return true;
+}
+
 void ColorNode::compile(SVMCompiler& compiler)
 {
        ShaderOutput *color_out = output("Color");
index 1fa4b67c6b97512c8cd9dffcd5087784932c045c..51efbc37f385e89557c21908534157878413e129 100644 (file)
@@ -485,6 +485,8 @@ class ValueNode : public ShaderNode {
 public:
        SHADER_NODE_CLASS(ValueNode)
 
+       bool constant_fold(ShaderOutput *socket, float3 *optimized_value);
+
        float value;
 };
 
@@ -492,6 +494,8 @@ class ColorNode : public ShaderNode {
 public:
        SHADER_NODE_CLASS(ColorNode)
 
+       bool constant_fold(ShaderOutput *socket, float3 *optimized_value);
+
        float3 value;
 };