Browse Source

normal normalnode, view, local, world

sunag 5 years ago
parent
commit
26639d8217

+ 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 - 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 ) {