From 2c58e96685e80e4e12dfad56ed3bb51fa3824197 Mon Sep 17 00:00:00 2001 From: Thomas Dinges Date: Sun, 31 Mar 2013 01:18:10 +0000 Subject: [PATCH] Cycles / Shader Graph optimization: * Unnecessary shader inputs inside the Mix Shader are now ignored, in case the factor is 0.0 / 1.0 and not connected. This way we save some render time for complex node graphs. Example: http://www.pasteall.org/pic/show.php?id=48226 Check the Mix Shader at the end: In this case, Cycles will now avoid the complete huge shader tree, and only calculate the Diffuse Shader. Rendertime decreased from 1:50 min to 1:20 min on CPU. GPU rendering benefits as well from this. This only affects SVM, OSL was already doing these optimizations. --- intern/cycles/render/graph.cpp | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/intern/cycles/render/graph.cpp b/intern/cycles/render/graph.cpp index af27b46771c..50fee15c231 100644 --- a/intern/cycles/render/graph.cpp +++ b/intern/cycles/render/graph.cpp @@ -365,6 +365,45 @@ void ShaderGraph::remove_proxy_nodes(vector& removed) } } } + + /* remove unused mix closure input when factor is 0.0 or 1.0 */ + if(node->special_type == SHADER_SPECIAL_TYPE_MIX_CLOSURE) { + MixClosureNode *mix = static_cast(node); + /* Check for closure 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 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); + } + } + /* Factor 1.0 */ + else if (mix->inputs[0]->value.x == 1.0f) { + ShaderOutput *output = mix->inputs[2]->link; + vector 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); + } + } + } + } } }