but in tsl there is no such way. I found one way from the official docs but there it’s saying just use javascript, like if else condition like we do in js or we can use any orther way that’s vaild in js.
but I don’t know when i update that defined value how can i update the Fn() code block.
I tried doing material.needsUpdate = true but that’s not working.
WGSL does not support preprocessor directives so there is no support for this in TSL. There are cleaner solutions since during setup time you can branch TSL with classic JavaScript if/else statements. Do you mind demonstrating with a live example what you are doing?
It is not the idea to have multiple materials. Instead, you can check in JavaScript conditions that were previously embedded in the shader as a define. Let me give you one concrete example:
In WebGLRenderer , the shader chunk for normals maps uses defines like USE_NORMALMAP_TANGENTSPACE to create branches with different GLSL code. In TSL, we can check these conditions directly in JavaScript and then create different TSL.
If you would change the normal map type and then notify the node material system to rebuild the material, setup() is called again and different TSL is generated. This works for all nodes, even the ones used for post processing.
If you change the value of a define in WebGLRenderer, a recompile is required. That also true when the TSL source changes in WebGPURenderer. In both cases, you end up with a different shader.