vec2 pos; uniform float time; uniform vec2 resolution; uniform vec2 mouse; float sdCircle( vec2 p, float r ) { return length(p) - r; } vec2 path(float time, vec2 pos, float radius, float vel) { return vec2(sin(time * vel), cos(time * vel)) * radius - pos; } void main(void) { vec2 pos = gl_FragCoord.xy / resolution.xy; float AR = resolution.x / resolution.y; pos = gl_FragCoord.xy - resolution.xy * 0.25; pos /= resolution.y; pos *= 1.5; float mask1 = smoothstep(0.0, 0.3, sdCircle(pos - path(time, vec2(0.), 0.4, 0.5), 0.05)); float mask2 = smoothstep(0.0, 0.3, sdCircle(pos - path(time, vec2(0.), 0.3, -0.3), 0.05)); float mask3 = smoothstep(0.0, 0.3, sdCircle(pos - path(time, vec2(0.1), 0.15, -0.43), 0.05)); float mask4 = smoothstep(0.0, 0.3, sdCircle(pos - path(time, vec2(0.), 0.1, 0.62), 0.05)); float mask5 = smoothstep(0.0, 0.3, sdCircle(pos - vec2(mouse.x, -mouse.y) - vec2(-0.5, 0.5), 0.1)); float maskTotal = (mask1 + mask2 + mask3 + mask4 + mask5*2.) / 6.; float finalMask = 1. - smoothstep(0.7, 0.71, maskTotal); vec3 col = 0.5 + 0.5*cos(time+pos.xyx+vec3(0,2,4)); gl_FragColor = vec4(col, 1.) * finalMask; }
<- backGLSL
GLSL was my starting point in shader programming. My initial experience was short, but extremely informative. With the parallel processing GPU principles I acquired from these studies, I was able to implement shaders into my game development pipeline.
Below are a couple of playful shaders I have written on the web:
The shader being used as a background for this page!
Simplex noise patterns
Feel free to browse around the rest of this website to find in the background some other shaders I have written :)
For fun, I'll display below the code for whatever shader is in the background of this page:
vec2 pos;
uniform float time;
uniform vec2 resolution;
uniform vec2 mouse;
float sdCircle( vec2 p, float r )
{
return length(p) - r;
}
vec2 path(float time, vec2 pos, float radius, float vel)
{
return vec2(sin(time * vel), cos(time * vel)) * radius - pos;
}
void main(void)
{
vec2 pos = gl_FragCoord.xy / resolution.xy;
float AR = resolution.x / resolution.y;
pos = gl_FragCoord.xy - resolution.xy * 0.25;
pos /= resolution.y;
pos *= 1.5;
float mask1 = smoothstep(0.0, 0.3, sdCircle(pos - path(time, vec2(0.), 0.4, 0.5), 0.05));
float mask2 = smoothstep(0.0, 0.3, sdCircle(pos - path(time, vec2(0.), 0.3, -0.3), 0.05));
float mask3 = smoothstep(0.0, 0.3, sdCircle(pos - path(time, vec2(0.1), 0.15, -0.43), 0.05));
float mask4 = smoothstep(0.0, 0.3, sdCircle(pos - path(time, vec2(0.), 0.1, 0.62), 0.05));
float mask5 = smoothstep(0.0, 0.3, sdCircle(pos - vec2(mouse.x, -mouse.y) - vec2(-0.5, 0.5), 0.1));
float maskTotal = (mask1 + mask2 + mask3 + mask4 + mask5*2.) / 6.;
float finalMask = 1. - smoothstep(0.7, 0.71, maskTotal);
vec3 col = 0.5 + 0.5*cos(time+pos.xyx+vec3(0,2,4));
gl_FragColor = vec4(col, 1.) * finalMask;
}