Procházet zdrojové kódy

fix-irradiance nodematerial

sunag před 6 roky
rodič
revize
982e093fae

+ 22 - 10
examples/jsm/nodes/materials/nodes/StandardNode.js

@@ -153,7 +153,14 @@ StandardNode.prototype.build = function ( builder ) {
 		if ( this.shadow ) this.shadow.analyze( builder );
 		if ( this.emissive ) this.emissive.analyze( builder, { slot: 'emissive' } );
 
-		if ( this.environment ) this.environment.analyze( builder, { cache: 'env', context: contextEnvironment, slot: 'environment' } ); // isolate environment from others inputs ( see TextureNode, CubeTextureNode )
+		if ( this.environment ) {
+
+			// 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' } ); 
+
+		}
 
 		// build code
 
@@ -179,7 +186,16 @@ StandardNode.prototype.build = function ( builder ) {
 		var shadow = this.shadow ? this.shadow.flow( builder, 'c' ) : undefined;
 		var emissive = this.emissive ? this.emissive.flow( builder, 'c', { slot: 'emissive' } ) : undefined;
 
-		var environment = this.environment ? this.environment.flow( builder, 'c', { cache: 'env', context: contextEnvironment, slot: 'environment' } ) : undefined;
+		var environment;
+
+		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' } ),
+			};
+
+		}
 
 		var clearCoatEnv = useClearCoat && environment ? this.environment.flow( builder, 'c', { cache: 'clearCoat', context: contextEnvironment, slot: 'environment' } ) : undefined;
 
@@ -371,7 +387,8 @@ StandardNode.prototype.build = function ( builder ) {
 
 		if ( environment ) {
 
-			output.push( environment.code );
+			output.push( environment.radiance.code );
+			output.push( environment.irradiance.code );
 
 			if ( clearCoatEnv ) {
 
@@ -382,13 +399,8 @@ StandardNode.prototype.build = function ( builder ) {
 
 			}
 
-			output.push( "radiance += " + environment.result + ";" );
-
-			if ( environment.extra.irradiance ) {
-
-				output.push( "irradiance += PI * " + environment.extra.irradiance + ";" );
-
-			}
+			output.push( "radiance += " + environment.radiance.result + ";" );
+			output.push( "irradiance += PI * " + environment.irradiance.result + ";" );
 
 		}
 

+ 3 - 5
examples/jsm/nodes/misc/TextureCubeNode.js

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

+ 8 - 2
examples/webgl_materials_envmaps_pmrem_nodes.html

@@ -46,6 +46,7 @@
 			import {
 				StandardNodeMaterial,
 				FloatNode,
+				OperatorNode,
 				TextureNode,
 				TextureCubeNode
 			} from './jsm/nodes/Nodes.js';
@@ -55,13 +56,14 @@
 				roughness: 0.0,
 				metalness: 0.0,
 				exposure: 1.0,
+				intensity: 1.0,
 				animate: true,
 				debug: false
 			};
 
 			var container, stats;
 			var camera, scene, renderer, controls;
-			var nodeMaterial, nodeTexture, nodeTextureSize, torusMesh, planeMesh;
+			var nodeMaterial, nodeTexture, nodeTextureSize, nodeTextureIntensity, torusMesh, planeMesh;
 			var hdrCubeRenderTarget;
 			var hdrCubeMap;
 
@@ -118,8 +120,9 @@
 
 				nodeTexture = new TextureNode();
 				nodeTextureSize = new FloatNode( 1024 );
+				nodeTextureIntensity = new FloatNode( 1 );
 
-				nodeMaterial.environment = new TextureCubeNode( nodeTexture, nodeTextureSize );
+				nodeMaterial.environment = new OperatorNode( new TextureCubeNode( nodeTexture, nodeTextureSize ), nodeTextureIntensity, OperatorNode.MUL );
 
 				torusMesh = new THREE.Mesh( geometry, nodeMaterial );
 				scene.add( torusMesh );
@@ -164,6 +167,7 @@
 				gui.add( params, 'roughness', 0, 1, 0.01 );
 				gui.add( params, 'metalness', 0, 1, 0.01 );
 				gui.add( params, 'exposure', 0, 2, 0.01 );
+				gui.add( params, 'intensity', 0, 2, 0.01 );
 				gui.add( params, 'animate', true );
 				gui.add( params, 'debug', false );
 				gui.open();
@@ -197,6 +201,8 @@
 				torusMesh.material.roughness.value = params.roughness;
 				torusMesh.material.metalness.value = params.metalness;
 
+				nodeTextureIntensity.value = params.intensity;
+
 				if ( nodeTextureSize.value !== params.textureSize ) {
 
 					generate( params.textureSize );