Note that because the shaders are designed for Shadertoy.com, they won't always be fully optimized for GameMaker. It can often be best to just design a shader yourself. This tutorial may not cover all the differences, but it should help you convert most shaders from Shadertoy.com.
Shaders on shadertoy.com
Varying Vectors
Uniforms
Texture Differences
Summary
- Change "fragColor" to "gl_FragColor"
- Change "void mainImage( out vec4 fragColor, in vec2 fragCoord )" to "void main( void)"
- Create the varying vec2 called "fragCoord"
- Remove unneeded attribute vectors
- Add the needed uniforms including the samplers
float rand(vec3 n)
{
return fract(abs(sin(dot(n,vec3(4.3357,-5.8464,6.7645))*52.47))*256.75+0.325);
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec3 p = vec3(fragCoord.xy+vec2(iGlobalTime)*64.0,0.0);
float b = (rand(floor(p/64.0))*0.5+rand(floor(p/32.0))*0.3+rand(floor(p/16.0))*0.2);
fragColor = vec4(vec3(b*0.6),1.0);
}
Here's the converted fragment code:
uniform float iGlobalTime;
varying vec2 fragCoord;
float rand(vec3 n)
{
return fract(abs(sin(dot(n,vec3(4.3357,-5.8464,6.7645))*52.47))*256.75+0.325);
}
void main(void)
{
vec3 p = vec3(fragCoord.xy+vec2(iGlobalTime)*64.0,0.0);
float b = (rand(floor(p/64.0))*0.5+rand(floor(p/32.0))*0.3+rand(floor(p/16.0))*0.2);
gl_FragColor = vec4(vec3(b*0.6),1.0);
}
Now here is the vertex code:
attribute vec3 in_Position; // (x,y,z)
//attribute vec3 in_Normal; // (x,y,z) unused in this shader.
//attribute vec4 in_Colour; // (r,g,b,a) unused in this shader.
//attribute vec2 in_TextureCoord; // (u,v) unused in this shader.
varying vec2 fragCoord;
void main()
{
vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0);
gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos;
fragCoord = in_Position.xy;
}
Here's the example file:
DOWNLOAD EXAMPLE
For a challenge you can convert my "Cool Lake"shader.