Cycles: add constant folding to displacement nodes.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Sun, 11 Mar 2018 21:42:38 +0000 (22:42 +0100)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Mon, 12 Mar 2018 16:29:44 +0000 (17:29 +0100)
intern/cycles/render/nodes.cpp
intern/cycles/render/nodes.h

index e36a75f..d732189 100644 (file)
@@ -5785,6 +5785,15 @@ DisplacementNode::DisplacementNode()
 {
 }
 
+void DisplacementNode::constant_fold(const ConstantFolder& folder)
+{
+       if(folder.all_inputs_constant()) {
+               if((height - midlevel == 0.0f) || (scale == 0.0f)) {
+                       folder.make_zero();
+               }
+       }
+}
+
 void DisplacementNode::compile(SVMCompiler& compiler)
 {
        ShaderInput *height_in = input("Height");
@@ -5836,6 +5845,16 @@ VectorDisplacementNode::VectorDisplacementNode()
 {
 }
 
+void VectorDisplacementNode::constant_fold(const ConstantFolder& folder)
+{
+       if(folder.all_inputs_constant()) {
+               if((vector == make_float3(0.0f, 0.0f, 0.0f) && midlevel == 0.0f) ||
+                  (scale == 0.0f)) {
+                       folder.make_zero();
+               }
+       }
+}
+
 void VectorDisplacementNode::attributes(Shader *shader, AttributeRequestSet *attributes)
 {
        if(shader->has_surface && space == NODE_NORMAL_MAP_TANGENT) {
index 33df286..58c3d47 100644 (file)
@@ -1063,6 +1063,7 @@ public:
 class DisplacementNode : public ShaderNode {
 public:
        SHADER_NODE_CLASS(DisplacementNode)
+       void constant_fold(const ConstantFolder& folder);
        virtual int get_feature() {
                return NODE_FEATURE_BUMP;
        }
@@ -1079,6 +1080,7 @@ public:
        SHADER_NODE_CLASS(VectorDisplacementNode)
        void attributes(Shader *shader, AttributeRequestSet *attributes);
        bool has_attribute_dependency() { return true; }
+       void constant_fold(const ConstantFolder& folder);
        virtual int get_feature() {
                return NODE_FEATURE_BUMP;
        }