"switch" keyword in GLSL shader

Can someone explain why the following

void mainImage(out vec4 fragColor, vec2 fragCoord)
switch (1) {
case 0:
fragColor = vec4(1.0,1.0,1.0,1.0);;
fragColor = vec4(0.0,0.0,0.0,1.0);;

Works fine on ShaderToy but I get a “switch” keyword error in Vuo.

switchtest.vuo (2.31 KB)

Hi Paul!
I’m not a Shader guru but I think the version of the GLSL doesn’t accept the Switch case.
But I think that a solution is to write if/else conditionals and will work ( If(condition){ else{…} )

PD: Thanks a lot for your immersive work. Much appreciated.

Oh sure, the if-then-else solution is obvious.

Just curious that Shadertoy works and the node is called “Make image with Shadertoy” … so at the every least the documentation for that node should say something about restructions. Shaders are hard enough to debug as it is. :-)

1 Like

Not a Shader Guru at all, but funny this works for you because pasting your code in Shadertoy I get an error :

'switch' : Illegal use of reserved word

'switch' : syntax error  

No way! Here’s a screen dump, it’s running and the output is white as expected.

Ok my bad, must be a browser thing, works for me in Chrome too, but getting an error in Safari


We’ve added documentation to the node:

“This node uses GLSL 1.20. Features that were added in later versions of GLSL, such as switch statements, may not be supported.”