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:
authorThomas Dinges <blender@dingto.org>2014-09-24 14:52:19 +0400
committerThomas Dinges <blender@dingto.org>2014-09-24 14:52:36 +0400
commitcbffc7499ef89cac19c07ee2116b8e1e5d38afe5 (patch)
tree99c38a372075999e7dd84a9f20656b5b26238810 /intern/cycles/render/graph.cpp
parent6dae643450201ae4e284e3e2ccbbb7ce297fbd2c (diff)
Cycles: Shader Graph Optimization for Mix RGB nodes.
Basically the same as AC2c58e96685e8, but for Mix RGB Shaders, in case we use the Mix type. This way the node can be used as texture switch for example, setting the Factor to 0.0 or 1.0, without wasting extra memory / render time.
Diffstat (limited to 'intern/cycles/render/graph.cpp')
-rw-r--r--intern/cycles/render/graph.cpp50
1 files changed, 46 insertions, 4 deletions
diff --git a/intern/cycles/render/graph.cpp b/intern/cycles/render/graph.cpp
index 904060c30e7..d90e5c4b2c9 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);
@@ -402,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);
@@ -434,6 +434,48 @@ void ShaderGraph::remove_unneeded_nodes()
}
}
}
+ 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 */