Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'intern/cycles/render/graph.cpp')
-rw-r--r--intern/cycles/render/graph.cpp100
1 files changed, 95 insertions, 5 deletions
diff --git a/intern/cycles/render/graph.cpp b/intern/cycles/render/graph.cpp
index 0ff904d06e7..45b08832fea 100644
--- a/intern/cycles/render/graph.cpp
+++ b/intern/cycles/render/graph.cpp
@@ -320,20 +320,20 @@ void ShaderGraph::remove_unneeded_nodes()
{
vector<bool> removed(num_node_ids, false);
bool any_node_removed = false;
-
+
/* find and unlink proxy nodes */
foreach(ShaderNode *node, nodes) {
if(node->special_type == SHADER_SPECIAL_TYPE_PROXY) {
ProxyNode *proxy = static_cast<ProxyNode*>(node);
ShaderInput *input = proxy->inputs[0];
ShaderOutput *output = proxy->outputs[0];
-
+
/* temp. copy of the output links list.
* output->links is modified when we disconnect!
*/
vector<ShaderInput*> links(output->links);
ShaderOutput *from = input->link;
-
+
/* bypass the proxy node */
if(from) {
disconnect(input);
@@ -391,6 +391,8 @@ void ShaderGraph::remove_unneeded_nodes()
if(output)
connect(output, input);
}
+ removed[mix->id] = true;
+ any_node_removed = true;
}
/* remove unused mix closure input when factor is 0.0 or 1.0 */
@@ -400,7 +402,7 @@ void ShaderGraph::remove_unneeded_nodes()
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);
@@ -410,6 +412,8 @@ void ShaderGraph::remove_unneeded_nodes()
if(output)
connect(output, input);
}
+ removed[mix->id] = true;
+ any_node_removed = true;
}
/* factor 1.0 */
else if(mix->inputs[0]->value.x == 1.0f) {
@@ -425,13 +429,57 @@ void ShaderGraph::remove_unneeded_nodes()
if(output)
connect(output, input);
}
+ removed[mix->id] = true;
+ any_node_removed = true;
+ }
+ }
+ }
+ else if(node->special_type == SHADER_SPECIAL_TYPE_MIX_RGB) {
+ MixNode *mix = static_cast<MixNode*>(node);
+
+ /* remove unused Mix RGB inputs when factor is 0.0 or 1.0 */
+ /* check for color 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);
+ }
+ removed[mix->id] = true;
+ any_node_removed = true;
+ }
+ /* 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);
+ }
+ removed[mix->id] = true;
+ any_node_removed = true;
}
}
}
}
/* remove nodes */
- if (any_node_removed) {
+ if(any_node_removed) {
list<ShaderNode*> newnodes;
foreach(ShaderNode *node, nodes) {
@@ -787,5 +835,47 @@ void ShaderGraph::transform_multi_closure(ShaderNode *node, ShaderOutput *weight
}
}
+void ShaderGraph::dump_graph(const char *filename)
+{
+ FILE *fd = fopen(filename, "w");
+
+ if(fd == NULL) {
+ printf("Error opening file for dumping the graph: %s\n", filename);
+ return;
+ }
+
+ fprintf(fd, "digraph dependencygraph {\n");
+ fprintf(fd, "ranksep=1.5\n");
+ fprintf(fd, "splines=false\n");
+
+ foreach(ShaderNode *node, nodes) {
+ fprintf(fd, "// NODE: %p\n", node);
+ fprintf(fd,
+ "\"%p\" [shape=record,label=\"%s\"]\n",
+ node,
+ node->name.c_str());
+ }
+
+ foreach(ShaderNode *node, nodes) {
+ foreach(ShaderOutput *output, node->outputs) {
+ foreach(ShaderInput *input, output->links) {
+ fprintf(fd,
+ "// CONNECTION: %p->%p (%s:%s)\n",
+ output,
+ input,
+ output->name, input->name);
+ fprintf(fd,
+ "\"%p\":s -> \"%p\":n [label=\"%s:%s\"]\n",
+ output->parent,
+ input->parent,
+ output->name, input->name);
+ }
+ }
+ }
+
+ fprintf(fd, "}\n");
+ fclose(fd);
+}
+
CCL_NAMESPACE_END