From 83a36b2829eece1ff4549d2f5273cb8cdcad4432 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 4 Sep 2015 20:03:45 +0500 Subject: Cycles: Fix for wrong optimization of bump node It can't be simply removed in cases when it's connected to input which is different from Normal. This is because the input wouldn't be connected to default Normal geometry input, possibly breaking shading setup. The fix is not really ideal, but should work at least. This fixes skin having too much glossy reflection in the file from T46013. --- intern/cycles/render/graph.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/intern/cycles/render/graph.cpp b/intern/cycles/render/graph.cpp index e0537101247..f5ff091623b 100644 --- a/intern/cycles/render/graph.cpp +++ b/intern/cycles/render/graph.cpp @@ -336,6 +336,8 @@ void ShaderGraph::remove_unneeded_nodes() vector removed(num_node_ids, false); bool any_node_removed = false; + ShaderNode *geom = NULL; + /* find and unlink proxy nodes */ foreach(ShaderNode *node, nodes) { if(node->special_type == SHADER_SPECIAL_TYPE_PROXY) { @@ -423,12 +425,19 @@ void ShaderGraph::remove_unneeded_nodes() BumpNode *bump = static_cast(node); if(bump->outputs[0]->links.size()) { - /* Height input not connected */ - /* ToDo: Strength zero? */ - if(!bump->inputs[0]->link) { + /* Height inputs is not connected. */ + /* TODO(sergey): Ignore bump with zero strength. */ + if(bump->inputs[0]->link == NULL) { vector inputs = bump->outputs[0]->links; - - relink(bump->inputs, inputs, NULL); + if(bump->inputs[4]->link == NULL) { + if(geom == NULL) { + geom = new GeometryNode(); + } + relink(bump->inputs, inputs, geom->output("Normal")); + } + else { + relink(bump->inputs, inputs, bump->input("Normal")->link); + } removed[bump->id] = true; any_node_removed = true; } @@ -511,6 +520,10 @@ void ShaderGraph::remove_unneeded_nodes() nodes = newnodes; } + + if(geom != NULL) { + add(geom); + } } void ShaderGraph::break_cycles(ShaderNode *node, vector& visited, vector& on_stack) -- cgit v1.2.3