[Bf-blender-cvs] [cbffc74] master: Cycles: Shader Graph Optimization for Mix RGB nodes.

Thomas Dinges noreply at git.blender.org
Wed Sep 24 12:52:58 CEST 2014


Commit: cbffc7499ef89cac19c07ee2116b8e1e5d38afe5
Author: Thomas Dinges
Date:   Wed Sep 24 12:52:19 2014 +0200
Branches: master
https://developer.blender.org/rBcbffc7499ef89cac19c07ee2116b8e1e5d38afe5

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.

===================================================================

M	intern/cycles/blender/blender_shader.cpp
M	intern/cycles/render/graph.cpp
M	intern/cycles/render/graph.h

===================================================================

diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp
index 4c9379c..33c7bf5 100644
--- a/intern/cycles/blender/blender_shader.cpp
+++ b/intern/cycles/blender/blender_shader.cpp
@@ -229,6 +229,10 @@ static ShaderNode *add_node(Scene *scene, BL::BlendData b_data, BL::Scene b_scen
 		BL::ShaderNodeMixRGB b_mix_node(b_node);
 		MixNode *mix = new MixNode();
 		mix->type = MixNode::type_enum[b_mix_node.blend_type()];
+		/* Tag if it's Mix */
+		if(b_mix_node.blend_type() == 0) 
+			mix->special_type = SHADER_SPECIAL_TYPE_MIX_RGB;
+
 		mix->use_clamp = b_mix_node.use_clamp();
 		node = mix;
 	}
diff --git a/intern/cycles/render/graph.cpp b/intern/cycles/render/graph.cpp
index 904060c..d90e5c4 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 */
diff --git a/intern/cycles/render/graph.h b/intern/cycles/render/graph.h
index 89a0661..7bfd51c 100644
--- a/intern/cycles/render/graph.h
+++ b/intern/cycles/render/graph.h
@@ -76,6 +76,7 @@ enum ShaderNodeSpecialType {
 	SHADER_SPECIAL_TYPE_NONE,
 	SHADER_SPECIAL_TYPE_PROXY,
 	SHADER_SPECIAL_TYPE_MIX_CLOSURE,
+	SHADER_SPECIAL_TYPE_MIX_RGB, /* Only Mix subtype */
 	SHADER_SPECIAL_TYPE_AUTOCONVERT,
 	SHADER_SPECIAL_TYPE_GEOMETRY,
 	SHADER_SPECIAL_TYPE_SCRIPT




More information about the Bf-blender-cvs mailing list