-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TSL: PositionNode/ReflectVectorNode - Move to TSL approach (#28510)
* PositionNode: Move to TSL approach * ReflectVectorNode: Move to TSL approach
- Loading branch information
Showing
3 changed files
with
10 additions
and
133 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,10 @@ | ||
import Node, { addNodeClass } from '../core/Node.js'; | ||
import { attribute } from '../core/AttributeNode.js'; | ||
import { varying } from '../core/VaryingNode.js'; | ||
import { normalize } from '../math/MathNode.js'; | ||
import { modelWorldMatrix, modelViewMatrix } from './ModelNode.js'; | ||
import { nodeImmutable } from '../shadernode/ShaderNode.js'; | ||
|
||
class PositionNode extends Node { | ||
|
||
constructor( scope = PositionNode.LOCAL ) { | ||
|
||
super( 'vec3' ); | ||
|
||
this.scope = scope; | ||
|
||
} | ||
|
||
isGlobal() { | ||
|
||
return true; | ||
|
||
} | ||
|
||
getHash( /*builder*/ ) { | ||
|
||
return `position-${this.scope}`; | ||
|
||
} | ||
|
||
generate( builder ) { | ||
|
||
const scope = this.scope; | ||
|
||
let outputNode = null; | ||
|
||
if ( scope === PositionNode.GEOMETRY ) { | ||
|
||
outputNode = attribute( 'position', 'vec3' ); | ||
|
||
} else if ( scope === PositionNode.LOCAL ) { | ||
|
||
outputNode = varying( positionGeometry ); | ||
|
||
} else if ( scope === PositionNode.WORLD ) { | ||
|
||
const vertexPositionNode = modelWorldMatrix.mul( positionLocal ); | ||
outputNode = varying( vertexPositionNode ); | ||
|
||
} else if ( scope === PositionNode.VIEW ) { | ||
|
||
const vertexPositionNode = modelViewMatrix.mul( positionLocal ); | ||
outputNode = varying( vertexPositionNode ); | ||
|
||
} else if ( scope === PositionNode.VIEW_DIRECTION ) { | ||
|
||
const vertexPositionNode = positionView.negate(); | ||
outputNode = normalize( varying( vertexPositionNode ) ); | ||
|
||
} else if ( scope === PositionNode.WORLD_DIRECTION ) { | ||
|
||
const vertexPositionNode = positionLocal.transformDirection( modelWorldMatrix ); | ||
outputNode = normalize( varying( vertexPositionNode ) ); | ||
|
||
} | ||
|
||
return outputNode.build( builder, this.getNodeType( builder ) ); | ||
|
||
} | ||
|
||
serialize( data ) { | ||
|
||
super.serialize( data ); | ||
|
||
data.scope = this.scope; | ||
|
||
} | ||
|
||
deserialize( data ) { | ||
|
||
super.deserialize( data ); | ||
|
||
this.scope = data.scope; | ||
|
||
} | ||
|
||
} | ||
|
||
PositionNode.GEOMETRY = 'geometry'; | ||
PositionNode.LOCAL = 'local'; | ||
PositionNode.WORLD = 'world'; | ||
PositionNode.WORLD_DIRECTION = 'worldDirection'; | ||
PositionNode.VIEW = 'view'; | ||
PositionNode.VIEW_DIRECTION = 'viewDirection'; | ||
|
||
export default PositionNode; | ||
|
||
export const positionGeometry = nodeImmutable( PositionNode, PositionNode.GEOMETRY ); | ||
export const positionLocal = nodeImmutable( PositionNode, PositionNode.LOCAL ).temp( 'Position' ); | ||
export const positionWorld = nodeImmutable( PositionNode, PositionNode.WORLD ); | ||
export const positionWorldDirection = nodeImmutable( PositionNode, PositionNode.WORLD_DIRECTION ); | ||
export const positionView = nodeImmutable( PositionNode, PositionNode.VIEW ); | ||
export const positionViewDirection = nodeImmutable( PositionNode, PositionNode.VIEW_DIRECTION ); | ||
|
||
addNodeClass( 'PositionNode', PositionNode ); | ||
export const positionGeometry = /*#__PURE__*/ attribute( 'position', 'vec3' ); | ||
export const positionLocal = /*#__PURE__*/ positionGeometry.toVar( 'positionLocal' ); | ||
export const positionWorld = /*#__PURE__*/ varying( modelWorldMatrix.mul( positionLocal ).xyz, 'v_positionWorld' ); | ||
export const positionWorldDirection = /*#__PURE__*/ varying( positionLocal.transformDirection( modelWorldMatrix ), 'v_positionWorldDirection' ).normalize().toVar( 'positionWorldDirection' ); | ||
export const positionView = /*#__PURE__*/ varying( modelViewMatrix.mul( positionLocal ).xyz, 'v_positionView' ); | ||
export const positionViewDirection = /*#__PURE__*/ varying( positionView.negate(), 'v_positionViewDirection' ).normalize().toVar( 'positionViewDirection' ); |
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 |
---|---|---|
@@ -1,35 +1,6 @@ | ||
import Node, { addNodeClass } from '../core/Node.js'; | ||
import { cameraViewMatrix } from './CameraNode.js'; | ||
import { transformedNormalView } from './NormalNode.js'; | ||
import { positionViewDirection } from './PositionNode.js'; | ||
import { nodeImmutable } from '../shadernode/ShaderNode.js'; | ||
|
||
class ReflectVectorNode extends Node { | ||
|
||
constructor() { | ||
|
||
super( 'vec3' ); | ||
|
||
} | ||
|
||
getHash( /*builder*/ ) { | ||
|
||
return 'reflectVector'; | ||
|
||
} | ||
|
||
setup() { | ||
|
||
const reflectView = positionViewDirection.negate().reflect( transformedNormalView ); | ||
|
||
return reflectView.transformDirection( cameraViewMatrix ); | ||
|
||
} | ||
|
||
} | ||
|
||
export default ReflectVectorNode; | ||
|
||
export const reflectVector = nodeImmutable( ReflectVectorNode ); | ||
|
||
addNodeClass( 'ReflectVectorNode', ReflectVectorNode ); | ||
export const reflectView = /*#__PURE__*/ positionViewDirection.negate().reflect( transformedNormalView ); | ||
export const reflectVector = /*#__PURE__*/ reflectView.transformDirection( cameraViewMatrix ).toVar( 'reflectVector' ); |