Skip to content
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

Merged
merged 3 commits into from
May 28, 2024
Merged

TSL: UVNode - Move to TSL approach #28511

merged 3 commits into from
May 28, 2024

Conversation

sunag
Copy link
Collaborator

@sunag sunag commented May 28, 2024

Related issue: #28408

Improved too: Normal/Tangent/Bitangent revisions

@sunag sunag added this to the r165 milestone May 28, 2024
@sunag sunag marked this pull request as ready for review May 28, 2024 03:05
@sunag sunag merged commit e811420 into mrdoob:dev May 28, 2024
11 checks passed
@sunag sunag deleted the dev-uv-rev branch May 28, 2024 03:05
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' );
Copy link
Owner

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()?

Copy link
Collaborator Author

@sunag sunag May 28, 2024

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.

Copy link
Owner

@mrdoob mrdoob May 28, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants