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

ShaderNode: Improve syntax (Fluent interface) #25074

Merged
merged 9 commits into from
Dec 7, 2022

Conversation

sunag
Copy link
Collaborator

@sunag sunag commented Dec 4, 2022

Description

This PR adds Fluent interface for ShaderNode
Now is possible to use method chaining between all NodeElements.

I think this can simplify the code reading, besides being common among Three.js users.

/ping @mrdoob

Examples

One line of DFGApprox:

// previous
const r = add( mul( roughness, c0 ), c1 );

// using method chaining
const r = roughness.mul( c0 ).add( c1 );

Simple negate

// previous
reflectVec = negate( positionViewDirection );

// using method chaining
reflectVec = positionViewDirection.negate();

Others examples

//  reflectVec  = transformDirection( reflectVec, cameraViewMatrix );
reflectVec = reflectVec.transformDirection( cameraViewMatrix );

// invert( radianceTextureUVNode.y );
radianceTextureUVNode.y.invert();

This contribution is funded by Google

@sunag
Copy link
Collaborator Author

sunag commented Dec 5, 2022

How it works:

  1. Checks that no variable with the element name has been created on the target Node.
  2. Returns a closure function, where the function's first argument is the node itself applied to the new element.
// api
myNode.add( 100 );

// shader node (e.g.)
return ( ...params ) => add( myNode, ...params );

@mrdoob
Copy link
Owner

mrdoob commented Dec 6, 2022

The new syntax feels much more familiar! 👍👍

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.

3 participants