Browse Source

detect if require irradiance flow

sunag 6 years ago
parent
commit
d00bbf3cc2

+ 6 - 0
examples/jsm/nodes/core/NodeBuilder.js

@@ -449,6 +449,12 @@ NodeBuilder.prototype = {
 
 	},
 
+	require: function ( name ) {
+
+		this.requires[ name ] = true;
+
+	},
+
 	isDefined: function ( name ) {
 
 		return this.defines[ name ] !== undefined;

+ 21 - 6
examples/jsm/nodes/materials/nodes/StandardNode.js

@@ -157,8 +157,8 @@ StandardNode.prototype.build = function ( builder ) {
 
 			// isolate environment from others inputs ( see TextureNode, CubeTextureNode )
 
-			this.environment.analyze( builder, { cache: 'radianceCache', context: contextEnvironment, slot: 'radiance' } ); 
-			this.environment.analyze( builder, { cache: 'irradianceCache', context: contextEnvironment, slot: 'irradiance' } ); 
+			this.environment.analyze( builder, { cache: 'radiance', context: contextEnvironment, slot: 'radiance' } ); 
+			this.environment.analyze( builder, { cache: 'irradiance', context: contextEnvironment, slot: 'irradiance' } ); 
 
 		}
 
@@ -191,10 +191,15 @@ StandardNode.prototype.build = function ( builder ) {
 		if ( this.environment ) {
 
 			environment = {
-				radiance: this.environment.flow( builder, 'c', { cache: 'radianceCache', context: contextEnvironment, slot: 'radiance' } ),
-				irradiance: this.environment.flow( builder, 'c', { cache: 'irradianceCache', context: contextEnvironment, slot: 'irradiance' } ),
+				radiance: this.environment.flow( builder, 'c', { cache: 'radiance', context: contextEnvironment, slot: 'radiance' } )
 			};
 
+			if ( builder.requires.irradiance ) {
+
+				environment.irradiance = this.environment.flow( builder, 'c', { cache: 'irradiance', context: contextEnvironment, slot: 'irradiance' } );
+
+			}
+
 		}
 
 		var clearCoatEnv = useClearCoat && environment ? this.environment.flow( builder, 'c', { cache: 'clearCoat', context: contextEnvironment, slot: 'environment' } ) : undefined;
@@ -388,7 +393,12 @@ StandardNode.prototype.build = function ( builder ) {
 		if ( environment ) {
 
 			output.push( environment.radiance.code );
-			output.push( environment.irradiance.code );
+
+			if ( builder.requires.irradiance ) {
+
+				output.push( environment.irradiance.code );
+
+			}
 
 			if ( clearCoatEnv ) {
 
@@ -400,7 +410,12 @@ StandardNode.prototype.build = function ( builder ) {
 			}
 
 			output.push( "radiance += " + environment.radiance.result + ";" );
-			output.push( "irradiance += PI * " + environment.irradiance.result + ";" );
+
+			if ( builder.requires.irradiance ) {
+
+				output.push( "irradiance += PI * " + environment.irradiance.result + ";" );
+
+			}
 
 		}
 

+ 4 - 2
examples/jsm/nodes/misc/TextureCubeNode.js

@@ -79,10 +79,12 @@ TextureCubeNode.prototype.generate = function ( builder, output ) {
 
 	if ( builder.isShader( 'fragment' ) ) {
 
+		builder.require( 'irradiance' );
+
 		var cache = builder.slot === 'irradiance' ? this.irradianceCache : this.radianceCache;
-		var code = this.generateTextureCubeUV( builder, cache );
+		var result = this.generateTextureCubeUV( builder, cache );
 
-		return builder.format( 'vec4( ' + code + ', 1.0 )', this.getType( builder ), output );
+		return builder.format( 'vec4( ' + result + ', 1.0 )', this.getType( builder ), output );
 
 	} else {