[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55681] trunk/blender/intern/cycles/render /graph.cpp: Cycles / Shader Graph optimization:

Thomas Dinges blender at dingto.org
Sun Mar 31 03:18:12 CEST 2013


Revision: 55681
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55681
Author:   dingto
Date:     2013-03-31 01:18:10 +0000 (Sun, 31 Mar 2013)
Log Message:
-----------
Cycles / Shader Graph optimization:
* Unnecessary shader inputs inside the Mix Shader are now ignored, in case the factor is 0.0 / 1.0 and not connected. 
This way we save some render time for complex node graphs. 

Example: http://www.pasteall.org/pic/show.php?id=48226
Check the Mix Shader at the end: In this case, Cycles will now avoid the complete huge shader tree, and only calculate the Diffuse Shader.
Rendertime decreased from 1:50 min to 1:20 min on CPU. GPU rendering benefits as well from this. 

This only affects SVM, OSL was already doing these optimizations. 

Modified Paths:
--------------
    trunk/blender/intern/cycles/render/graph.cpp

Modified: trunk/blender/intern/cycles/render/graph.cpp
===================================================================
--- trunk/blender/intern/cycles/render/graph.cpp	2013-03-31 01:11:07 UTC (rev 55680)
+++ trunk/blender/intern/cycles/render/graph.cpp	2013-03-31 01:18:10 UTC (rev 55681)
@@ -365,6 +365,45 @@
 				}
 			}
 		}
+		
+		/* remove unused mix closure input when factor is 0.0 or 1.0 */
+		if(node->special_type == SHADER_SPECIAL_TYPE_MIX_CLOSURE) {
+			MixClosureNode *mix = static_cast<MixClosureNode*>(node);
+			/* Check for closure 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);
+					}
+				}
+				/* 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);
+					}
+				}
+			}
+		}
 	}
 }
 




More information about the Bf-blender-cvs mailing list