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.
This commit is contained in:
Sergey Sharybin
2015-09-04 20:03:45 +05:00
parent 713ce037ab
commit 83a36b2829

View File

@@ -336,6 +336,8 @@ void ShaderGraph::remove_unneeded_nodes()
vector<bool> removed(num_node_ids, false); vector<bool> removed(num_node_ids, false);
bool any_node_removed = false; bool any_node_removed = false;
ShaderNode *geom = NULL;
/* find and unlink proxy nodes */ /* find and unlink proxy nodes */
foreach(ShaderNode *node, nodes) { foreach(ShaderNode *node, nodes) {
if(node->special_type == SHADER_SPECIAL_TYPE_PROXY) { if(node->special_type == SHADER_SPECIAL_TYPE_PROXY) {
@@ -423,12 +425,19 @@ void ShaderGraph::remove_unneeded_nodes()
BumpNode *bump = static_cast<BumpNode*>(node); BumpNode *bump = static_cast<BumpNode*>(node);
if(bump->outputs[0]->links.size()) { if(bump->outputs[0]->links.size()) {
/* Height input not connected */ /* Height inputs is not connected. */
/* ToDo: Strength zero? */ /* TODO(sergey): Ignore bump with zero strength. */
if(!bump->inputs[0]->link) { if(bump->inputs[0]->link == NULL) {
vector<ShaderInput*> inputs = bump->outputs[0]->links; vector<ShaderInput*> inputs = bump->outputs[0]->links;
if(bump->inputs[4]->link == NULL) {
relink(bump->inputs, inputs, 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; removed[bump->id] = true;
any_node_removed = true; any_node_removed = true;
} }
@@ -511,6 +520,10 @@ void ShaderGraph::remove_unneeded_nodes()
nodes = newnodes; nodes = newnodes;
} }
if(geom != NULL) {
add(geom);
}
} }
void ShaderGraph::break_cycles(ShaderNode *node, vector<bool>& visited, vector<bool>& on_stack) void ShaderGraph::break_cycles(ShaderNode *node, vector<bool>& visited, vector<bool>& on_stack)