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: Move ShaderNode to tslFn() #26311

Merged
merged 8 commits into from
Jun 22, 2023
Merged

TSL: Move ShaderNode to tslFn() #26311

merged 8 commits into from
Jun 22, 2023

Conversation

sunag
Copy link
Collaborator

@sunag sunag commented Jun 21, 2023

Description

This is a big revision, it's a simplification of how TSL work with functions, this was based in some studies and conversations with users of three.js.

Removing .call() from TSL design

Creating a ShaderNode function using tslFn.

const D_BlinnPhong = tslFn( ( { dotNH } ) => {

	return shininess.mul( 0.5 / Math.PI ).add( 1.0 ).mul( dotNH.pow( shininess ) );

} );

//...

const D = D_BlinnPhong( { dotNH } );

Using native functions wgslFn() or glslFn()

const desaturateFn = wgslFn( `
	fn desaturate( color:vec3<f32> ) -> vec3<f32> {

		let lum = vec3<f32>( 0.299, 0.587, 0.114 );

		return vec3<f32>( dot( lum, color ) );

	}
` );

//...

material.colorNode = desaturateFn( { color: texture( uvTexture ) } );

/cc @mrdoob @LeviPesin @Mugen87

Move `func()` -> `wgslFn()`
Move `shader()` -> `fn()`
@sunag sunag added the TSL Three.js Shading Language label Jun 21, 2023
@sunag sunag added this to the r154 milestone Jun 21, 2023
@sunag sunag marked this pull request as ready for review June 21, 2023 19:57
@LeviPesin
Copy link
Contributor

LeviPesin commented Jun 21, 2023

I think I'm fine with such a rename 👍 And the removal of calls is nice.

@mrdoob
Copy link
Owner

mrdoob commented Jun 22, 2023

How about tslFn instead of just fn?

@sunag sunag changed the title TSL: Move ShaderNode to fn() TSL: Move ShaderNode to tslFn() Jun 22, 2023
@sunag sunag merged commit d8e6aa3 into mrdoob:dev Jun 22, 2023
@sunag sunag deleted the dev-shadernode branch June 22, 2023 23:01
@sunag
Copy link
Collaborator Author

sunag commented Jul 23, 2024

Sometimes I think fn is more congruent with the rest of the functions like loop, If... since they are TSL by nature and we don't have prefixes, the only exceptions in TSL are wgslFn and glslFn.

I was thinking about making fn the default and leaving tslFn as an alias.

@mrdoob
Copy link
Owner

mrdoob commented Jul 23, 2024

const desaturateFn = fn( `
	fn desaturate( color:vec3<f32> ) -> vec3<f32> {
	}
` );

That double fn is a bit weird though 🤔

@mrdoob
Copy link
Owner

mrdoob commented Jul 23, 2024

Hmm, maybe capitalizing them...?

Fn, If, Loop, ...

@sunag
Copy link
Collaborator Author

sunag commented Jul 23, 2024

That double fn is a bit weird though 🤔

I was thinking of this change as just tslFn. wgslFn would remain the same.

const desaturateFn = fn( ( [ color ] ) => {

} );

Hmm, maybe capitalizing them...?

It looks interesting flow control nodes will have a pattern.

const desaturateFn = Fn( ( [ color ] ) => {

	Loop( count, => {

		Break();

	} );

} );

@mrdoob
Copy link
Owner

mrdoob commented Jul 23, 2024

It looks interesting flow control nodes will have a pattern.

Yeah, easier to read I think 🤔

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

Successfully merging this pull request may close these issues.

3 participants