-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TSL: UVNode - Move to TSL approach #28511
Conversation
export const bitangentWorld = varying( getBitangent( normalWorld.cross( tangentWorld ) ) ).normalize(); | ||
export const transformedBitangentView = getBitangent( transformedNormalView.cross( transformedTangentView ) ).normalize(); | ||
export const transformedBitangentWorld = transformedBitangentView.transformDirection( cameraViewMatrix ).normalize(); | ||
export const bitangentGeometry = /*#__PURE__*/ varying( getBitangent( normalGeometry.cross( tangentGeometry ) ), 'v_bitangentGeometry' ).normalize().toVar( 'bitangentGeometry' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the difference between varying()
and toVar()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toVar( name = null )
will create a variable, the first parameter is used to add a name to it, otherwise the node system will name it automatically, it can be useful in debugging or access using wgslFn
.
varying( node, name = null )
this node is very interesting, let's suppose you want to optimize some calculation in the vertex stage
but are using it in a slot like material.colorNode
, with varying
this is possible. For example:
// multiplication will be executed in vertex stage
const inVertexStage = varying( modelNormalMatrix.mul( normalLocal ) ); // normalView
// normalize will be executed in fragment stage
// because .colorNode is a fragment stage slot as default
material.colorNode = inVertexStage.normalize();
The first parameter of varying( modelNormalMatrix.mul( normalLocal ) )
will be executed in vertex stage
, and the return from varying()
will be a varying
as we are used in WGSL/GLSL, this can optimize extra calculations in the fragment stage
. The second parameter allows you to add a custom name to varying
.
If varying()
is added only to .positionNode
, it will only return a simple variable and varying will not be created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good! Thanks for explaining 🙏
I've started a wiki page for TSL.
Any chance you can spend some time completing it?
Related issue: #28408
Improved too: Normal/Tangent/Bitangent revisions