Browse Source

done fixes LDR, HDR and RGBM16

sunag 6 years ago
parent
commit
9c49226194

+ 0 - 9
examples/js/nodes/accessors/ReflectNode.js

@@ -15,7 +15,6 @@ function ReflectNode( scope ) {
 ReflectNode.CUBE = 'cube';
 ReflectNode.CUBE = 'cube';
 ReflectNode.SPHERE = 'sphere';
 ReflectNode.SPHERE = 'sphere';
 ReflectNode.VECTOR = 'vector';
 ReflectNode.VECTOR = 'vector';
-ReflectNode.VECTOR2 = 'vector2';
 
 
 ReflectNode.prototype = Object.create( TempNode.prototype );
 ReflectNode.prototype = Object.create( TempNode.prototype );
 ReflectNode.prototype.constructor = ReflectNode;
 ReflectNode.prototype.constructor = ReflectNode;
@@ -51,14 +50,6 @@ ReflectNode.prototype.generate = function ( builder, output ) {
 
 
 				break;
 				break;
 
 
-			case ReflectNode.VECTOR2:
-
-				builder.addNodeCode( 'vec3 reflectVec2 = vec3( inverseTransformDirection( geometry.normal, viewMatrix ).x, inverseTransformDirection( geometry.normal, viewMatrix ).yz );' );
-
-				result = 'reflectVec2';
-
-				break;
-
 			case ReflectNode.CUBE:
 			case ReflectNode.CUBE:
 
 
 				var reflectVec = new ReflectNode( ReflectNode.VECTOR ).build( builder, 'v3' );
 				var reflectVec = new ReflectNode( ReflectNode.VECTOR ).build( builder, 'v3' );

+ 1 - 1
examples/js/nodes/inputs/CubeTextureNode.js

@@ -54,7 +54,7 @@ CubeTextureNode.prototype.generate = function ( builder, output ) {
 	// include ColorSpace function only for vertex shader (in fragment shader color space functions is added automatically by core)
 	// include ColorSpace function only for vertex shader (in fragment shader color space functions is added automatically by core)
 	// this should be removed in the future
 	// this should be removed in the future
 	// context.include =: is used to include or not functions if used FunctionNode
 	// context.include =: is used to include or not functions if used FunctionNode
-	// context.ignoreCache =: not create variables nodeT0..9 to optimize the code
+	// context.ignoreCache =: not create variables temp nodeT0..9 to optimize the code
 	var context = { include: builder.isShader( 'vertex' ), ignoreCache: true };
 	var context = { include: builder.isShader( 'vertex' ), ignoreCache: true };
 	var outputType = this.getType( builder );
 	var outputType = this.getType( builder );
 
 

+ 1 - 1
examples/js/nodes/inputs/TextureNode.js

@@ -58,7 +58,7 @@ TextureNode.prototype.generate = function ( builder, output ) {
 	// include ColorSpace function only for vertex shader (in fragment shader color space functions is added automatically by core)
 	// include ColorSpace function only for vertex shader (in fragment shader color space functions is added automatically by core)
 	// this should be removed in the future
 	// this should be removed in the future
 	// context.include is used to include or not functions if used FunctionNode
 	// context.include is used to include or not functions if used FunctionNode
-	// context.ignoreCache =: not create variables nodeT0..9 to optimize the code
+	// context.ignoreCache =: not create temp variables nodeT0..9 to optimize the code
 	var context = { include: builder.isShader( 'vertex' ), ignoreCache: true };
 	var context = { include: builder.isShader( 'vertex' ), ignoreCache: true };
 	var outputType = this.getType( builder );
 	var outputType = this.getType( builder );
 
 

+ 1 - 1
examples/js/nodes/materials/nodes/StandardNode.js

@@ -372,7 +372,7 @@ StandardNode.prototype.build = function ( builder ) {
 
 
 			if ( environment.extra.irradiance ) {
 			if ( environment.extra.irradiance ) {
 
 
-				output.push( "irradiance += " + environment.extra.irradiance + ";" );
+				output.push( "irradiance += PI * " + environment.extra.irradiance + ";" );
 
 
 			}
 			}
 
 

+ 17 - 5
examples/js/nodes/misc/TextureCubeNode.js

@@ -7,16 +7,28 @@ import { FloatNode } from '../inputs/FloatNode.js';
 import { ExpressionNode } from '../core/ExpressionNode.js';
 import { ExpressionNode } from '../core/ExpressionNode.js';
 import { TextureCubeUVNode } from './TextureCubeUVNode.js';
 import { TextureCubeUVNode } from './TextureCubeUVNode.js';
 import { ReflectNode } from '../accessors/ReflectNode.js';
 import { ReflectNode } from '../accessors/ReflectNode.js';
+import { NormalNode } from '../accessors/NormalNode.js';
 import { ColorSpaceNode } from '../utils/ColorSpaceNode.js';
 import { ColorSpaceNode } from '../utils/ColorSpaceNode.js';
+import { BlinnExponentToRoughnessNode } from '../bsdfs/BlinnExponentToRoughnessNode.js';
 
 
-function TextureCubeNode( value ) {
+function TextureCubeNode( value, textureSize ) {
 
 
 	TempNode.call( this, 'v4' );
 	TempNode.call( this, 'v4' );
 
 
 	this.value = value;
 	this.value = value;
+	this.textureSize = textureSize || new FloatNode( 1024 );
 
 
-	this.radianceCache = { uv: new TextureCubeUVNode() };
-	this.irradianceCache = { uv: new TextureCubeUVNode( new ReflectNode( ReflectNode.VECTOR2 ), undefined, new FloatNode( 1 ).setReadonly( true ) ) };
+	this.radianceCache = { uv: new TextureCubeUVNode( 
+		new ReflectNode( ReflectNode.VECTOR ), 
+		this.textureSize, 
+		new BlinnExponentToRoughnessNode() 
+	) };
+
+	this.irradianceCache = { uv: new TextureCubeUVNode( 
+		new NormalNode( NormalNode.WORLD ), 
+		this.textureSize, 
+		new FloatNode( 1 ).setReadonly( true ) 
+	) };
 
 
 }
 }
 
 
@@ -37,7 +49,7 @@ TextureCubeNode.prototype.generateTextureCubeUV = function ( builder, cache ) {
 	// include ColorSpace function only for vertex shader (in fragment shader color space functions is added automatically by core)
 	// include ColorSpace function only for vertex shader (in fragment shader color space functions is added automatically by core)
 	// this should be removed in the future
 	// this should be removed in the future
 	// context.include =: is used to include or not functions if used FunctionNode
 	// context.include =: is used to include or not functions if used FunctionNode
-	// context.ignoreCache =: not create variables nodeT0..9 to optimize the code
+	// context.ignoreCache =: not create temp variables nodeT0..9 to optimize the code
 	var context = { include: builder.isShader( 'vertex' ), ignoreCache: true };
 	var context = { include: builder.isShader( 'vertex' ), ignoreCache: true };
 	var outputType = this.getType( builder );
 	var outputType = this.getType( builder );
 
 
@@ -70,7 +82,7 @@ TextureCubeNode.prototype.generate = function ( builder, output ) {
 		var radiance = this.generateTextureCubeUV( builder, this.radianceCache );
 		var radiance = this.generateTextureCubeUV( builder, this.radianceCache );
 		var irradiance = this.generateTextureCubeUV( builder, this.irradianceCache );
 		var irradiance = this.generateTextureCubeUV( builder, this.irradianceCache );
 
 
-		builder.context.extra.irradiance = '( PI * ' + irradiance + ' )';
+		builder.context.extra.irradiance = irradiance;
 
 
 		return builder.format( 'vec4( ' + radiance + ', 1.0 )', this.getType( builder ), output );
 		return builder.format( 'vec4( ' + radiance + ', 1.0 )', this.getType( builder ), output );
 
 

+ 3 - 4
examples/js/nodes/misc/TextureCubeUVNode.js

@@ -8,15 +8,14 @@ import { StructNode } from '../core/StructNode.js';
 import { FunctionNode } from '../core/FunctionNode.js';
 import { FunctionNode } from '../core/FunctionNode.js';
 import { ReflectNode } from '../accessors/ReflectNode.js';
 import { ReflectNode } from '../accessors/ReflectNode.js';
 import { FloatNode } from '../inputs/FloatNode.js';
 import { FloatNode } from '../inputs/FloatNode.js';
-import { BlinnExponentToRoughnessNode } from '../bsdfs/BlinnExponentToRoughnessNode.js';
 
 
 function TextureCubeUVNode( uv, textureSize, blinnExponentToRoughness ) {
 function TextureCubeUVNode( uv, textureSize, blinnExponentToRoughness ) {
 
 
 	TempNode.call( this, 'TextureCubeUVData' ); // TextureCubeUVData is type as StructNode
 	TempNode.call( this, 'TextureCubeUVData' ); // TextureCubeUVData is type as StructNode
 
 
-	this.uv = uv || new ReflectNode( ReflectNode.VECTOR );
-	this.textureSize = textureSize || new FloatNode( 1024 );
-	this.blinnExponentToRoughness = blinnExponentToRoughness || new BlinnExponentToRoughnessNode();
+	this.uv = uv;
+	this.textureSize = textureSize;
+	this.blinnExponentToRoughness = blinnExponentToRoughness;
 
 
 }
 }
 
 

+ 11 - 10
examples/js/nodes/utils/ColorSpaceNode.js

@@ -220,7 +220,7 @@ ColorSpaceNode.getEncodingComponents = function ( encoding ) {
 		case THREE.RGBDEncoding:
 		case THREE.RGBDEncoding:
 			return [ 'RGBD', new FloatNode( 256.0 ).setReadonly( true ) ];
 			return [ 'RGBD', new FloatNode( 256.0 ).setReadonly( true ) ];
 		case THREE.GammaEncoding:
 		case THREE.GammaEncoding:
-			return [ 'Gamma', new ExpressionNode( 'float( GAMMA_FACTOR )' ) ];
+			return [ 'Gamma', new ExpressionNode( 'float( GAMMA_FACTOR )', 'f' ) ];
 
 
 	}
 	}
 
 
@@ -233,25 +233,26 @@ ColorSpaceNode.prototype.nodeType = "ColorSpace";
 ColorSpaceNode.prototype.generate = function ( builder, output ) {
 ColorSpaceNode.prototype.generate = function ( builder, output ) {
 
 
 	var input = this.input.build( builder, 'v4' );
 	var input = this.input.build( builder, 'v4' );
+	var outputType = this.getType( builder );
 
 
-	if ( this.method === ColorSpaceNode.LINEAR_TO_LINEAR ) {
+	var methodNode = ColorSpaceNode.Nodes[ this.method ];
+	var method = builder.include( methodNode );
 
 
-		return builder.format( input, this.getType( builder ), output );
+	if ( method === ColorSpaceNode.LINEAR_TO_LINEAR ) {
 
 
-	} else {
+		return builder.format( input, outputType, output );
 
 
-		var method = [ this.method ];
-		var factor = this.factor ? this.factor.build( builder, 'f' ) : method[ 1 ];
+	} else {
 
 
-		method = builder.include( ColorSpaceNode.Nodes[ method[ 0 ] ] );
+		if ( methodNode.inputs.length === 2 ) {
 
 
-		if ( factor ) {
+			var factor = this.factor.build( builder, 'f' );
 
 
-			return builder.format( method + '( ' + input + ', ' + factor + ' )', this.getType( builder ), output );
+			return builder.format( method + '( ' + input + ', ' + factor + ' )', outputType, output );
 
 
 		} else {
 		} else {
 
 
-			return builder.format( method + '( ' + input + ' )', this.getType( builder ), output );
+			return builder.format( method + '( ' + input + ' )', outputType, output );
 
 
 		}
 		}
 
 

+ 14 - 3
examples/webgl_materials_envmaps_nodes.html

@@ -64,6 +64,8 @@
 				roughness: 0.0,
 				roughness: 0.0,
 				metalness: 0.0,
 				metalness: 0.0,
 				exposure: 1.0,
 				exposure: 1.0,
+				nodes: true,
+				animate: true,
 				debug: false,
 				debug: false,
 			};
 			};
 
 
@@ -101,7 +103,6 @@
 				material.metalness = params.roguhness;
 				material.metalness = params.roguhness;
 
 
 				torusMesh = new THREE.Mesh( geometry, material );
 				torusMesh = new THREE.Mesh( geometry, material );
-				torusMesh.position.y = 35;
 				scene.add( torusMesh );
 				scene.add( torusMesh );
 
 
 				material = new THREE.MeshStandardNodeMaterial();
 				material = new THREE.MeshStandardNodeMaterial();
@@ -110,7 +111,6 @@
 				material.metalness = params.roguhness;
 				material.metalness = params.roguhness;
 
 
 				torusMeshNode = new THREE.Mesh( geometry, material );
 				torusMeshNode = new THREE.Mesh( geometry, material );
-				torusMeshNode.position.y = -35;
 				scene.add( torusMeshNode );
 				scene.add( torusMeshNode );
 
 
 				planeMesh = new THREE.Mesh( new THREE.PlaneBufferGeometry( 200, 200 ), new THREE.MeshBasicMaterial() );
 				planeMesh = new THREE.Mesh( new THREE.PlaneBufferGeometry( 200, 200 ), new THREE.MeshBasicMaterial() );
@@ -207,6 +207,8 @@
 				gui.add( params, 'roughness', 0, 1, 0.01 );
 				gui.add( params, 'roughness', 0, 1, 0.01 );
 				gui.add( params, 'metalness', 0, 1, 0.01 );
 				gui.add( params, 'metalness', 0, 1, 0.01 );
 				gui.add( params, 'exposure', 0, 2, 0.01 );
 				gui.add( params, 'exposure', 0, 2, 0.01 );
+				gui.add( params, 'nodes', true );
+				gui.add( params, 'animate', true );
 				gui.add( params, 'debug', false );
 				gui.add( params, 'debug', false );
 				gui.open();
 				gui.open();
 
 
@@ -242,6 +244,9 @@
 				torusMeshNode.material.roughness = params.roughness;
 				torusMeshNode.material.roughness = params.roughness;
 				torusMeshNode.material.metalness = params.metalness;
 				torusMeshNode.material.metalness = params.metalness;
 
 
+				torusMesh.visible = !params.nodes;
+				torusMeshNode.visible = params.nodes;
+
 				var renderTarget, cubeMap;
 				var renderTarget, cubeMap;
 
 
 				switch ( params.envMap ) {
 				switch ( params.envMap ) {
@@ -275,7 +280,13 @@
 
 
 				}
 				}
 
 
-				//torusMesh.rotation.y += 0.005;
+				if ( params.animate ) {
+
+					torusMesh.rotation.y += 0.005;
+					torusMeshNode.rotation.y = torusMesh.rotation.y;
+
+				}
+
 				planeMesh.visible = params.debug;
 				planeMesh.visible = params.debug;
 
 
 				scene.background = cubeMap;
 				scene.background = cubeMap;