-
-
Notifications
You must be signed in to change notification settings - Fork 35.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21208 from sunag/nodematerial-light
WebGPU: NodeMaterial updates
- Loading branch information
Showing
16 changed files
with
494 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import Node from '../core/Node.js'; | ||
import AttributeNode from '../core/AttributeNode.js'; | ||
import VaryNode from '../core/VaryNode.js'; | ||
import ModelNode from '../accessors/ModelNode.js'; | ||
import CameraNode from '../accessors/CameraNode.js'; | ||
import OperatorNode from '../math/OperatorNode.js'; | ||
import MathNode from '../math/MathNode.js'; | ||
|
||
class NormalNode extends Node { | ||
|
||
static LOCAL = 'local'; | ||
static WORLD = 'world'; | ||
static VIEW = 'view'; | ||
|
||
constructor( scope = NormalNode.LOCAL ) { | ||
|
||
super( 'vec3' ); | ||
|
||
this.scope = scope; | ||
|
||
} | ||
|
||
generate( builder, output ) { | ||
|
||
const type = this.getType( builder ); | ||
const nodeData = builder.getDataFromNode( this, builder.shaderStage ); | ||
const scope = this.scope; | ||
|
||
let localNormalNode = nodeData.localNormalNode; | ||
|
||
if ( localNormalNode === undefined ) { | ||
|
||
localNormalNode = new AttributeNode( 'normal', 'vec3' ); | ||
|
||
nodeData.localNormalNode = localNormalNode; | ||
|
||
} | ||
|
||
let outputNode = localNormalNode; | ||
|
||
if ( scope === NormalNode.VIEW ) { | ||
|
||
let viewNormalNode = nodeData.viewNormalNode; | ||
|
||
if ( viewNormalNode === undefined ) { | ||
|
||
const unnormalizedWNNode = new OperatorNode( '*', new ModelNode( ModelNode.NORMAL ), localNormalNode ); | ||
const vertexNormalNode = new MathNode( MathNode.NORMALIZE, unnormalizedWNNode ); | ||
|
||
viewNormalNode = new MathNode( MathNode.NORMALIZE, new VaryNode( vertexNormalNode ) ); | ||
|
||
nodeData.viewNormalNode = viewNormalNode; | ||
|
||
} | ||
|
||
outputNode = viewNormalNode; | ||
|
||
} else if ( scope === NormalNode.WORLD ) { | ||
|
||
let worldNormalNode = nodeData.worldNormalNode; | ||
|
||
if ( worldNormalNode === undefined ) { | ||
|
||
const vertexNormalNode = new MathNode( MathNode.INVERSE_TRANSFORM_DIRETION, new NormalNode( NormalNode.VIEW ), new CameraNode( CameraNode.VIEW ) ); | ||
|
||
worldNormalNode = new VaryNode( vertexNormalNode ); | ||
|
||
nodeData.worldNormalNode = worldNormalNode; | ||
|
||
} | ||
|
||
outputNode = worldNormalNode; | ||
|
||
} | ||
|
||
const normalSnipped = outputNode.build( builder, type ); | ||
|
||
return builder.format( normalSnipped, type, output ); | ||
|
||
} | ||
|
||
} | ||
|
||
export default NormalNode; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.