diff options
-rw-r--r-- | intern/cycles/blender/blender_shader.cpp | 4 | ||||
-rw-r--r-- | intern/cycles/render/graph.cpp | 50 | ||||
-rw-r--r-- | intern/cycles/render/graph.h | 1 |
3 files changed, 51 insertions, 4 deletions
diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp index 4c9379c905a..33c7bf5f859 100644 --- a/intern/cycles/blender/blender_shader.cpp +++ b/intern/cycles/blender/blender_shader.cpp @@ -229,6 +229,10 @@ static ShaderNode *add_node(Scene *scene, BL::BlendData b_data, BL::Scene b_scen BL::ShaderNodeMixRGB b_mix_node(b_node); MixNode *mix = new MixNode(); mix->type = MixNode::type_enum[b_mix_node.blend_type()]; + /* Tag if it's Mix */ + if(b_mix_node.blend_type() == 0) + mix->special_type = SHADER_SPECIAL_TYPE_MIX_RGB; + mix->use_clamp = b_mix_node.use_clamp(); node = mix; } diff --git a/intern/cycles/render/graph.cpp b/intern/cycles/render/graph.cpp index 904060c30e7..d90e5c4b2c9 100644 --- a/intern/cycles/render/graph.cpp +++ b/intern/cycles/render/graph.cpp @@ -320,20 +320,20 @@ void ShaderGraph::remove_unneeded_nodes() { vector<bool> removed(num_node_ids, false); bool any_node_removed = false; - + /* find and unlink proxy nodes */ foreach(ShaderNode *node, nodes) { if(node->special_type == SHADER_SPECIAL_TYPE_PROXY) { ProxyNode *proxy = static_cast<ProxyNode*>(node); ShaderInput *input = proxy->inputs[0]; ShaderOutput *output = proxy->outputs[0]; - + /* temp. copy of the output links list. * output->links is modified when we disconnect! */ vector<ShaderInput*> links(output->links); ShaderOutput *from = input->link; - + /* bypass the proxy node */ if(from) { disconnect(input); @@ -402,7 +402,7 @@ void ShaderGraph::remove_unneeded_nodes() if(mix->inputs[0]->value.x == 0.0f) { ShaderOutput *output = mix->inputs[1]->link; vector<ShaderInput*> inputs = mix->outputs[0]->links; - + foreach(ShaderInput *sock, mix->inputs) if(sock->link) disconnect(sock); @@ -434,6 +434,48 @@ void ShaderGraph::remove_unneeded_nodes() } } } + else if(node->special_type == SHADER_SPECIAL_TYPE_MIX_RGB) { + MixNode *mix = static_cast<MixNode*>(node); + + /* remove unused Mix RGB inputs when factor is 0.0 or 1.0 */ + /* check for color links and make sure factor link is disconnected */ + if(mix->outputs[0]->links.size() && mix->inputs[1]->link && mix->inputs[2]->link && !mix->inputs[0]->link) { + /* factor 0.0 */ + if(mix->inputs[0]->value.x == 0.0f) { + ShaderOutput *output = mix->inputs[1]->link; + vector<ShaderInput*> inputs = mix->outputs[0]->links; + + foreach(ShaderInput *sock, mix->inputs) + if(sock->link) + disconnect(sock); + + foreach(ShaderInput *input, inputs) { + disconnect(input); + if(output) + connect(output, input); + } + removed[mix->id] = true; + any_node_removed = true; + } + /* factor 1.0 */ + else if(mix->inputs[0]->value.x == 1.0f) { + ShaderOutput *output = mix->inputs[2]->link; + vector<ShaderInput*> inputs = mix->outputs[0]->links; + + foreach(ShaderInput *sock, mix->inputs) + if(sock->link) + disconnect(sock); + + foreach(ShaderInput *input, inputs) { + disconnect(input); + if(output) + connect(output, input); + } + removed[mix->id] = true; + any_node_removed = true; + } + } + } } /* remove nodes */ diff --git a/intern/cycles/render/graph.h b/intern/cycles/render/graph.h index 89a066195d6..7bfd51cdee3 100644 --- a/intern/cycles/render/graph.h +++ b/intern/cycles/render/graph.h @@ -76,6 +76,7 @@ enum ShaderNodeSpecialType { SHADER_SPECIAL_TYPE_NONE, SHADER_SPECIAL_TYPE_PROXY, SHADER_SPECIAL_TYPE_MIX_CLOSURE, + SHADER_SPECIAL_TYPE_MIX_RGB, /* Only Mix subtype */ SHADER_SPECIAL_TYPE_AUTOCONVERT, SHADER_SPECIAL_TYPE_GEOMETRY, SHADER_SPECIAL_TYPE_SCRIPT |