Browse Source

Merge pull request #17529 from sunag/dev-node-fixes

NodeMaterial fixes
Mr.doob 5 years ago
parent
commit
65d50c03f6

+ 31 - 6
examples/jsm/nodes/accessors/NormalNode.js

@@ -9,12 +9,13 @@ function NormalNode( scope ) {
 
 
 	TempNode.call( this, 'v3' );
 	TempNode.call( this, 'v3' );
 
 
-	this.scope = scope || NormalNode.LOCAL;
+	this.scope = scope || NormalNode.VIEW;
 
 
 }
 }
 
 
 NormalNode.LOCAL = 'local';
 NormalNode.LOCAL = 'local';
 NormalNode.WORLD = 'world';
 NormalNode.WORLD = 'world';
+NormalNode.VIEW = 'view';
 
 
 NormalNode.prototype = Object.create( TempNode.prototype );
 NormalNode.prototype = Object.create( TempNode.prototype );
 NormalNode.prototype.constructor = NormalNode;
 NormalNode.prototype.constructor = NormalNode;
@@ -34,22 +35,40 @@ NormalNode.prototype.generate = function ( builder, output ) {
 
 
 	switch ( this.scope ) {
 	switch ( this.scope ) {
 
 
-		case NormalNode.LOCAL:
+		case NormalNode.VIEW:
 
 
-			if ( builder.isShader( 'vertex' ) ) result = 'objectNormal';
+			if ( builder.isShader( 'vertex' ) ) result = 'transformedNormal';
 			else result = 'geometryNormal';
 			else result = 'geometryNormal';
 
 
 			break;
 			break;
 
 
+		case NormalNode.LOCAL:
+
+			if ( builder.isShader( 'vertex' ) ) {
+				
+				result = 'objectNormal';
+				
+			} else {
+				
+				builder.requires.normal = true;
+				
+				result = 'vObjectNormal';
+				
+			}
+
+			break;
+
 		case NormalNode.WORLD:
 		case NormalNode.WORLD:
 
 
 			if ( builder.isShader( 'vertex' ) ) {
 			if ( builder.isShader( 'vertex' ) ) {
 
 
-				result = '( modelMatrix * vec4( objectNormal, 0.0 ) ).xyz';
+				result = 'inverseTransformDirection( transformedNormal, viewMatrix ).xyz';
 
 
 			} else {
 			} else {
 
 
-				result = 'inverseTransformDirection( normal, viewMatrix )';
+				builder.requires.worldNormal = true;
+
+				result = 'vWNormal';
 
 
 			}
 			}
 
 
@@ -89,7 +108,13 @@ NormalNode.prototype.toJSON = function ( meta ) {
 
 
 NodeLib.addKeyword( 'viewNormal', function () {
 NodeLib.addKeyword( 'viewNormal', function () {
 
 
-	return new NormalNode();
+	return new NormalNode( NormalNode.VIEW );
+
+} );
+
+NodeLib.addKeyword( 'localNormal', function () {
+
+	return new NormalNode( NormalNode.NORMAL );
 
 
 } );
 } );
 
 

+ 1 - 1
examples/jsm/nodes/core/NodeBuilder.js

@@ -227,7 +227,7 @@ NodeBuilder.prototype = {
 
 
 			this.addVaryCode( 'varying vec3 vWNormal;' );
 			this.addVaryCode( 'varying vec3 vWNormal;' );
 
 
-			this.addVertexFinalCode( 'vWNormal = ( modelMatrix * vec4( objectNormal, 0.0 ) ).xyz;' );
+			this.addVertexFinalCode( 'vWNormal = inverseTransformDirection( transformedNormal, viewMatrix ).xyz;' );
 
 
 		}
 		}
 
 

+ 1 - 1
examples/jsm/nodes/misc/TextureCubeNode.js

@@ -84,7 +84,7 @@ TextureCubeNode.prototype.generate = function ( builder, output ) {
 
 
 		if ( builder.context.bias ) {
 		if ( builder.context.bias ) {
 
 
-			builder.context.bias.setTexture( this );
+			builder.context.bias.setTexture( this.value );
 
 
 		}
 		}
 
 

+ 1 - 1
examples/jsm/nodes/misc/TextureCubeUVNode.js

@@ -171,7 +171,7 @@ TextureCubeUVNode.prototype.generate = function ( builder, output ) {
 
 
 		var textureCubeUV = builder.include( TextureCubeUVNode.Nodes.textureCubeUV );
 		var textureCubeUV = builder.include( TextureCubeUVNode.Nodes.textureCubeUV );
 
 
-		var biasNode = this.bias || builder.context.bias;
+		var biasNode = this.bias || builder.context.roughness;
 
 
 		return builder.format( textureCubeUV + '( ' + this.uv.build( builder, 'v3' ) + ', ' +
 		return builder.format( textureCubeUV + '( ' + this.uv.build( builder, 'v3' ) + ', ' +
 			biasNode.build( builder, 'f' ) + ', ' +
 			biasNode.build( builder, 'f' ) + ', ' +

+ 13 - 1
examples/jsm/nodes/postprocessing/NodePostProcessing.js

@@ -85,9 +85,21 @@ NodePostProcessing.prototype = {
 
 
 	},
 	},
 
 
+	setPixelRatio: function ( value ) {
+
+		this.renderer.setPixelRatio( value );
+
+		var size = this.renderer.getSize( new Vector2() );
+
+		this.setSize( size.width, size.height );
+
+	},
+
 	setSize: function ( width, height ) {
 	setSize: function ( width, height ) {
 
 
-		this.renderTarget.setSize( width, height );
+		var pixelRatio = this.renderer.getPixelRatio();
+
+		this.renderTarget.setSize( width * pixelRatio, height * pixelRatio );
 
 
 		this.renderer.setSize( width, height );
 		this.renderer.setSize( width, height );
 
 

+ 3 - 1
examples/jsm/nodes/utils/MaxMIPLevelNode.js

@@ -26,7 +26,9 @@ Object.defineProperties( MaxMIPLevelNode.prototype, {
 
 
 			if ( this.maxMIPLevel === 0 ) {
 			if ( this.maxMIPLevel === 0 ) {
 
 
-				var image = this.texture.value.image ? this.texture.value.image[ 0 ] : undefined;
+				var image = this.texture.value.image;
+
+				if ( Array.isArray( image ) ) image = image[ 0 ];
 
 
 				this.maxMIPLevel = image !== undefined ? Math.log( Math.max( image.width, image.height ) ) * Math.LOG2E : 0;
 				this.maxMIPLevel = image !== undefined ? Math.log( Math.max( image.width, image.height ) ) * Math.LOG2E : 0;
 
 

+ 1 - 0
examples/webgl_materials_nodes.html

@@ -2579,6 +2579,7 @@
 						// GUI
 						// GUI
 
 
 						addGui( 'scope', {
 						addGui( 'scope', {
+							view: Nodes.NormalNode.VIEW,
 							local: Nodes.NormalNode.LOCAL,
 							local: Nodes.NormalNode.LOCAL,
 							world: Nodes.NormalNode.WORLD
 							world: Nodes.NormalNode.WORLD
 						}, function ( val ) {
 						}, function ( val ) {