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 uniform
s 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.