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

FunctionNode: Keywords support #23766

Merged
merged 6 commits into from
Mar 22, 2022
Merged

FunctionNode: Keywords support #23766

merged 6 commits into from
Mar 22, 2022

Conversation

sunag
Copy link
Collaborator

@sunag sunag commented Mar 22, 2022

Related issue: #23655

Description

const getWGSLTextureSample = new Nodes.FunctionNode( `

	fn getWGSLTextureSample( uv:vec2<f32> ) -> vec4<f32> {

		return textureSample( tex, tex_sampler, uv );

	}

` );

const textureNode = new Nodes.TextureNode( texture );

// set keywords
getWGSLTextureSample.keywords = { tex: textureNode, tex_sampler: sampler( textureNode ) };

This contribution is funded by Google via Igalia.

@LeviPesin
Copy link
Contributor

LeviPesin commented Mar 22, 2022

Couldn't be these keywords be passed just as arguments to the function?
I.e. just something like getWGSLTextureSample.call( { uv: new Nodes.UVNode(), tex: textureNode, tex_sampler: sampler( textureNode ) } ) and getWGSLTextureSample( uv:vec2<f32>, tex: WGSLTextureType, tex_sample: WGSLSamplerType ).

@sunag
Copy link
Collaborator Author

sunag commented Mar 22, 2022

Couldn't be these keywords be passed just as arguments to the function?

Yeah! This was my first approach, but it didn't work, I thought it was a limitation of WGSL, but now I think it is related to NodeMaterial...

@sunag
Copy link
Collaborator Author

sunag commented Mar 22, 2022

Now it worked! 😅

@sunag sunag added this to the r139 milestone Mar 22, 2022
@sunag
Copy link
Collaborator Author

sunag commented Mar 22, 2022

I think that I will keep to support to keywords in NodeMaterial system, while this don't support pointer between function calls... maybe it will be useful for other things too.

@sunag sunag merged commit 8cafdff into mrdoob:dev Mar 22, 2022
@sunag sunag deleted the dev-keywords branch March 22, 2022 23:03
@sunag
Copy link
Collaborator Author

sunag commented Mar 23, 2022

Just describing a little more...
This approach below would be the recommended use to call the functions. We also have the option to include the variables via keywords those not passed in arguments is directly replaced in the function code, so that the values can be edited globally since we still don't have inout <-> pointer.

/cc @mrdoob

const getWGSLTextureSample = new Nodes.FunctionNode( `
	fn getWGSLTextureSample( tex: texture_2d<f32>, tex_sampler: sampler, uv:vec2<f32> ) -> vec4<f32> {
		return textureSample( tex, tex_sampler, uv ) * vec4<f32>( 0.0, 1.0, 0.0, 1.0 );
	}
` );

const textureNode = new Nodes.TextureNode( texture );

material = new Nodes.MeshBasicNodeMaterial();
material.colorNode = getWGSLTextureSample.call( { tex: textureNode, tex_sampler: textureNode, uv: new Nodes.UVNode() } );

abernier pushed a commit to abernier/three.js that referenced this pull request Sep 16, 2022
* add sampler

* add FunctionNode.keywords

* update WGSL example using keywords

* improve example

* update

* fix WebGPUNodeBuilder.isReference()
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.

2 participants