I’m migrating a GLSL shader to TSL where I need a Switch statement to select a texture from an array. Playing around I think the Switch function is broken.
This is the code:
Looks like it might be related to how the index is computed. Since min(uv0.x.mul(5).toInt(), 5) can return 5, but you only define cases 0–4, the switch might be hitting the default path or generating odd code in the transpiled shader.
You could try clamping it to 4 instead:
const index = min(uv0.x.mul(5).toInt(), 4);
Also worth checking the generated shader code to see how TSL expands the Switch. Sometimes these constructs end up being translated into chained conditionals rather than an actual switch, which can expose edge cases.
If the goal is selecting a texture from an array, another workaround might be using chained select or mix operations based on comparisons, since those tend to compile more predictably in node systems.
Thanks, that gives something to look at. And… okey looking more comments and debugging the example, as you mention, they works fine, but only if they are inside a Fn. Not sure if this is a mandatory constraint but okey.