I am learning OpenGL and GLSL. I was taught that the in/out variables should be formatted like this:

in vec3 something;
out vec3 somethingElse;

int main()
    // etc...

However, I ran across code like this online (ShaderToy):

int main(in vec3 something, out vec3 somethingElse)
    Is there a difference?

Is there any difference?


1 Answer 1


Shadertoy code is used as part of a GLSL program for WebGL. There is additional code to make the GLSL program work that is not part of the Shadertoy code we write.

In Shadertoy, you will use:

void mainImage( out vec4 fragColor, in vec2 fragCoord );

To output the image. Please notice it is mainImage not main. You can write a fragment shader in GLSL that has a main that simply calls into mainImage copied from Shadertoy passing the correct values.

For the code to work you will also need to define some uniforms to match whatever Shadertoy inputs you are using (iResolution, iTime, etc...), and actually passing them to the shade program.

To replicate the output of shadertoy you will also need a simple vertex shader, and in fact pass geometry that cover the whole view. There is also the chance you do not want to replicate the output, but use the code in some other way.

If you read the Shadertoy documentation, you will find there is also mainSound and mainVR. Of couse, simply adding to a fragment shader won't work. They will need their own additional setup to be useful.

  • \$\begingroup\$ If I am not mistaken that is an architecture choice of Shadertoy as they support also sound coded in GLSL. \$\endgroup\$ Sep 25, 2019 at 23:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .