未验证 提交 c5a779eb 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #17096 from sunag/dev-fix-nodenormal

fix NormalNode
...@@ -12,5 +12,4 @@ export class NormalNode extends TempNode { ...@@ -12,5 +12,4 @@ export class NormalNode extends TempNode {
static LOCAL: string; static LOCAL: string;
static WORLD: string; static WORLD: string;
static VIEW: string;
} }
...@@ -15,23 +15,16 @@ function NormalNode( scope ) { ...@@ -15,23 +15,16 @@ function NormalNode( scope ) {
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;
NormalNode.prototype.nodeType = "Normal"; NormalNode.prototype.nodeType = "Normal";
NormalNode.prototype.getShared = function ( /* builder */ ) { NormalNode.prototype.getShared = function () {
switch ( this.scope ) { // if shared is false, TempNode will not create temp variable (for optimization)
case NormalNode.WORLD:
return true;
} return this.scope === NormalNode.WORLD;
return false;
}; };
...@@ -43,9 +36,6 @@ NormalNode.prototype.generate = function ( builder, output ) { ...@@ -43,9 +36,6 @@ NormalNode.prototype.generate = function ( builder, output ) {
case NormalNode.LOCAL: case NormalNode.LOCAL:
// to use vObjectNormal as vertex normal
//builder.requires.normal = true;
result = 'normal'; result = 'normal';
break; break;
...@@ -54,24 +44,16 @@ NormalNode.prototype.generate = function ( builder, output ) { ...@@ -54,24 +44,16 @@ NormalNode.prototype.generate = function ( builder, output ) {
if ( builder.isShader( 'vertex' ) ) { if ( builder.isShader( 'vertex' ) ) {
return '( modelMatrix * vec4( objectNormal, 0.0 ) ).xyz'; result = '( modelMatrix * vec4( objectNormal, 0.0 ) ).xyz';
} else { } else {
builder.requires.worldNormal = true; result = 'inverseTransformDirection( normal, viewMatrix )';
result = 'vWNormal';
} }
break; break;
case NormalNode.VIEW:
result = 'vNormal';
break;
} }
return builder.format( result, this.getType( builder ), output ); return builder.format( result, this.getType( builder ), output );
...@@ -116,10 +98,4 @@ NodeLib.addKeyword( 'worldNormal', function () { ...@@ -116,10 +98,4 @@ NodeLib.addKeyword( 'worldNormal', function () {
} ); } );
NodeLib.addKeyword( 'viewNormal', function () {
return new NormalNode( NormalNode.VIEW );
} );
export { NormalNode }; export { NormalNode };
...@@ -148,7 +148,7 @@ NodeLib.addKeyword( 'worldPosition', function () { ...@@ -148,7 +148,7 @@ NodeLib.addKeyword( 'worldPosition', function () {
NodeLib.addKeyword( 'viewPosition', function () { NodeLib.addKeyword( 'viewPosition', function () {
return new PositionNode( NormalNode.VIEW ); return new PositionNode( PositionNode.VIEW );
} ); } );
......
...@@ -2280,8 +2280,7 @@ ...@@ -2280,8 +2280,7 @@
addGui( 'scope', { addGui( 'scope', {
local: Nodes.NormalNode.LOCAL, local: Nodes.NormalNode.LOCAL,
world: Nodes.NormalNode.WORLD, world: Nodes.NormalNode.WORLD
view: Nodes.NormalNode.VIEW
}, function ( val ) { }, function ( val ) {
node.scope = val; node.scope = val;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册