forked from bartvdbraak/blender
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.
This commit is contained in:
parent
1fea6220a2
commit
2c58e96685
@ -365,6 +365,45 @@ void ShaderGraph::remove_proxy_nodes(vector<bool>& 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<MixClosureNode*>(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<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);
|
||||
}
|
||||
}
|
||||
/* 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user