Bläddra i källkod

fix NormalNode

sunag 6 år sedan
förälder
incheckning
e47f073f81

+ 0 - 1
examples/jsm/nodes/accessors/NormalNode.d.ts

@@ -12,5 +12,4 @@ export class NormalNode extends TempNode {
 
   static LOCAL: string;
   static WORLD: string;
-  static VIEW: string;
 }

+ 5 - 29
examples/jsm/nodes/accessors/NormalNode.js

@@ -15,23 +15,16 @@ function NormalNode( scope ) {
 
 NormalNode.LOCAL = 'local';
 NormalNode.WORLD = 'world';
-NormalNode.VIEW = 'view';
 
 NormalNode.prototype = Object.create( TempNode.prototype );
 NormalNode.prototype.constructor = NormalNode;
 NormalNode.prototype.nodeType = "Normal";
 
-NormalNode.prototype.getShared = function ( /* builder */ ) {
+NormalNode.prototype.getUnique = function () {
 
-	switch ( this.scope ) {
-
-		case NormalNode.WORLD:
-
-			return true;
+	// if unique is true, TempNode will not create temp variable (for optimization)
 
-	}
-
-	return false;
+	return this.scope === NormalNode.LOCAL;
 
 };
 
@@ -43,9 +36,6 @@ NormalNode.prototype.generate = function ( builder, output ) {
 
 		case NormalNode.LOCAL:
 
-			// to use vObjectNormal as vertex normal
-			//builder.requires.normal = true;
-
 			result = 'normal';
 
 			break;
@@ -54,24 +44,16 @@ NormalNode.prototype.generate = function ( builder, output ) {
 
 			if ( builder.isShader( 'vertex' ) ) {
 
-				return '( modelMatrix * vec4( objectNormal, 0.0 ) ).xyz';
+				result = '( modelMatrix * vec4( objectNormal, 0.0 ) ).xyz';
 
 			} else {
 
-				builder.requires.worldNormal = true;
-
-				result = 'vWNormal';
+				result = 'inverseTransformDirection( normal, viewMatrix )';
 
 			}
 
 			break;
 
-		case NormalNode.VIEW:
-
-			result = 'vNormal';
-
-			break;
-
 	}
 
 	return builder.format( result, this.getType( builder ), output );
@@ -116,10 +98,4 @@ NodeLib.addKeyword( 'worldNormal', function () {
 
 } );
 
-NodeLib.addKeyword( 'viewNormal', function () {
-
-	return new NormalNode( NormalNode.VIEW );
-
-} );
-
 export { NormalNode };

+ 1 - 1
examples/jsm/nodes/accessors/PositionNode.js

@@ -148,7 +148,7 @@ NodeLib.addKeyword( 'worldPosition', function () {
 
 NodeLib.addKeyword( 'viewPosition', function () {
 
-	return new PositionNode( NormalNode.VIEW );
+	return new PositionNode( PositionNode.VIEW );
 
 } );
 

+ 1 - 2
examples/webgl_materials_nodes.html

@@ -2280,8 +2280,7 @@
 
 						addGui( 'scope', {
 							local: Nodes.NormalNode.LOCAL,
-							world: Nodes.NormalNode.WORLD,
-							view: Nodes.NormalNode.VIEW
+							world: Nodes.NormalNode.WORLD
 						}, function ( val ) {
 
 							node.scope = val;