Cycles: Remove Emission shaders from the graph if color or strength is 0.
authorThomas Dinges <blender@dingto.org>
Wed, 13 May 2015 23:08:45 +0000 (01:08 +0200)
committerThomas Dinges <blender@dingto.org>
Wed, 13 May 2015 23:13:40 +0000 (01:13 +0200)
intern/cycles/render/graph.cpp
intern/cycles/render/graph.h
intern/cycles/render/nodes.cpp

index ab89ee3ae37867c4afc8397bcb1eef76ba2d0bb4..9adf6b4b1ed7e826edff368dc4326237dea04bde 100644 (file)
@@ -404,6 +404,21 @@ void ShaderGraph::remove_unneeded_nodes()
                                }
                        }
                }
+               else if(node->special_type == SHADER_SPECIAL_TYPE_EMISSION) {
+                       EmissionNode *em = static_cast<EmissionNode*>(node);
+
+                       if(em->outputs[0]->links.size()) {
+                               /* Black color or zero strength, remove node */
+                               if((!em->inputs[0]->link && em->inputs[0]->value == make_float3(0.0f, 0.0f, 0.0f)) ||
+                                  (!em->inputs[1]->link && em->inputs[1]->value.x == 0.0f)) {
+                                       vector<ShaderInput*> inputs = em->outputs[0]->links;
+
+                                       relink(em->inputs, inputs, NULL);
+                                       removed[em->id] = true;
+                                       any_node_removed = true;
+                               }
+                       }
+               }
                else if(node->special_type == SHADER_SPECIAL_TYPE_MIX_CLOSURE) {
                        MixClosureNode *mix = static_cast<MixClosureNode*>(node);
 
index e6271009999a05eed29af320b6932775feee064b..1a17909bddc76b41697bb6dc3f53b1e6f9840a4c 100644 (file)
@@ -83,6 +83,7 @@ enum ShaderNodeSpecialType {
        SHADER_SPECIAL_TYPE_BACKGROUND,
        SHADER_SPECIAL_TYPE_IMAGE_SLOT,
        SHADER_SPECIAL_TYPE_CLOSURE,
+       SHADER_SPECIAL_TYPE_EMISSION,
 };
 
 /* Enum
index 7eaecc2751c23f7dfc859abd0a9068ca9d01268d..430c059d686aaaec392443f3f513debeb8049514 100644 (file)
@@ -1923,6 +1923,8 @@ bool SubsurfaceScatteringNode::has_bssrdf_bump()
 EmissionNode::EmissionNode()
 : ShaderNode("emission")
 {
+       special_type = SHADER_SPECIAL_TYPE_EMISSION;
+
        add_input("Color", SHADER_SOCKET_COLOR, make_float3(0.8f, 0.8f, 0.8f));
        add_input("Strength", SHADER_SOCKET_FLOAT, 10.0f);
        add_input("SurfaceMixWeight", SHADER_SOCKET_FLOAT, 0.0f, ShaderInput::USE_SVM);