Browse Source

optimization for no LightNode

SUNAG 9 năm trước cách đây
mục cha
commit
9bb7ae8390

+ 11 - 7
examples/js/nodes/materials/PhongNode.js

@@ -160,7 +160,6 @@ THREE.PhongNode.prototype.build = function( builder ) {
 
 				// prevent undeclared material
 			"	BlinnPhongMaterial material;",
-			"	material.diffuseColor = vec3( 1.0 );",
 
 				color.code,
 			"	vec3 diffuseColor = " + color.result + ";",
@@ -203,6 +202,10 @@ THREE.PhongNode.prototype.build = function( builder ) {
 
 		}
 
+		// optimization for now
+
+		output.push( 'material.diffuseColor = ' + ( light ? 'vec3( 1.0 )' : 'diffuseColor' ) + ';' );
+
 		output.push(
 			THREE.ShaderChunk[ "shadowmap_fragment" ],
 
@@ -221,13 +224,14 @@ THREE.PhongNode.prototype.build = function( builder ) {
 				"reflectedLight.directDiffuse = " + light.result + ";"
 			);
 
-		}
+			// apply color
 
-		// apply color
-		output.push(
-			"reflectedLight.directDiffuse *= diffuseColor;",
-			"reflectedLight.indirectDiffuse *= diffuseColor;"
-		);
+			output.push(
+				"reflectedLight.directDiffuse *= diffuseColor;",
+				"reflectedLight.indirectDiffuse *= diffuseColor;"
+			);
+
+		}
 
 		if ( ao ) {
 

+ 13 - 8
examples/js/nodes/materials/StandardNode.js

@@ -214,12 +214,16 @@ THREE.StandardNode.prototype.build = function( builder ) {
 
 		}
 
+		// optimization for now
+
+		output.push( 'material.diffuseColor = ' + ( light ? 'vec3( 1.0 )' : 'diffuseColor * (1.0 - metalnessFactor)' ) + ';' );
+
 		output.push(
 			THREE.ShaderChunk[ "shadowmap_fragment" ],
 
 			// accumulation
 			'material.specularRoughness = clamp( roughnessFactor, 0.001, 1.0 );', // disney's remapping of [ 0, 1 ] roughness to [ 0.001, 1 ]
-			'material.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );',
+			'material.specularColor = mix( vec3( 0.04 ), diffuseColor, metalnessFactor );',
 
 			THREE.ShaderChunk[ "lights_template" ]
 		);
@@ -231,15 +235,16 @@ THREE.StandardNode.prototype.build = function( builder ) {
 				"reflectedLight.directDiffuse = " + light.result + ";"
 			);
 
-		}
+			// apply color
 
-		// apply color
-		output.push(
-			"diffuseColor *= 1.0 - metalnessFactor;",
+			output.push(
+				"diffuseColor *= 1.0 - metalnessFactor;",
 
-			"reflectedLight.directDiffuse *= diffuseColor;",
-			"reflectedLight.indirectDiffuse *= diffuseColor;"
-		);
+				"reflectedLight.directDiffuse *= diffuseColor;",
+				"reflectedLight.indirectDiffuse *= diffuseColor;"
+			);
+
+		}
 
 		if ( ao ) {