Cycles: Fix displacement code creating cyclic dependencies in graph

Bump result was passed to set_normal node and then set_node was connected
to all unconnected Normal inputs, including the one from original Bump
node, causing cycles.
This commit is contained in:
Sergey Sharybin 2015-03-17 19:36:29 +05:00
parent dd38dce7f0
commit a43d00d51e

@ -727,10 +727,18 @@ void ShaderGraph::bump_from_displacement()
/* connect bump output to normal input nodes that aren't set yet. actually
* this will only set the normal input to the geometry node that we created
* and connected to all other normal inputs already. */
foreach(ShaderNode *node, nodes)
foreach(ShaderInput *input, node->inputs)
foreach(ShaderNode *node, nodes) {
/* Don't connect normal to the bump node we're coming from,
* otherwise it'll be a cycle in graph.
*/
if(node == bump) {
continue;
}
foreach(ShaderInput *input, node->inputs) {
if(!input->link && input->default_value == ShaderInput::NORMAL)
connect(set_normal->output("Normal"), input);
}
}
/* for displacement bump, clear the normal input in case the above loop
* connected the setnormal out to the bump normalin */