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: Avoid naming collision when using label() or toVar(). #29813

Open
Mugen87 opened this issue Nov 5, 2024 · 1 comment
Open

TSL: Avoid naming collision when using label() or toVar(). #29813

Mugen87 opened this issue Nov 5, 2024 · 1 comment
Labels
TSL Three.js Shading Language

Comments

@Mugen87
Copy link
Collaborator

Mugen87 commented Nov 5, 2024

Description

When using label() or toVar() to give variables a name, collisions can occur when the name is already reserved for internal entities like uniforms or varyings.

If you now redefine a variable on app level, a shader error occurs. In WGSL for example:

Error while parsing WGSL: :40:2 error: redefinition of 'cameraNear'

Solution

It would be nice if the node material could automatically detect such name collisions and modify the custom names e.g. with a suffix.

Alternatives

Leave it as it is and ask developers to pick unique names.

Additional context

#29810

@Mugen87 Mugen87 added the TSL Three.js Shading Language label Nov 5, 2024
@ligaofeng0901
Copy link
Contributor

I have the following thoughts/ideas:

  1. .label() is used for uniforms, the names should be detected in shader level. Any uniform generated from a unique node should have a unique name
  2. toVar() is used for variables in shader. any variable in a Fn should be visible only in this Fn. Becasue all vars are defined on the top of main function, the name of any variable in a Fn should not collide with any other variables in any other Fns. So far, one situation I meet is
const fn1 = Fn(([param1]) => {
     const var1 = vec3().toVar('var1');
     .....
     return var1;
});

this.colorNode = Fn(() => {
     const var1 = vec3().toVar('var1');
     const a = fn1(1);
     const b = fn1(2);
     .....
     return mix(a, b,  var1);
});

After shader building, the logic of the shader is totally different from what I want. The builder thinks all var1 is the same variable, the value of different var1 will be affected by others.

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

No branches or pull requests

2 participants