Skip to content

Instantly share code, notes, and snippets.

@stevenlr
Created March 25, 2012 13:29
Show Gist options
  • Save stevenlr/2193815 to your computer and use it in GitHub Desktop.
Save stevenlr/2193815 to your computer and use it in GitHub Desktop.
Shaders
uniform sampler2D framebuffer;
float contrast(float c)
{
float a = 0.3;
return clamp((c - a) / (1 - a), 0, 1);
}
void main(void)
{
float radius = 0.005;
vec2 pos = gl_TexCoord[0].xy;
float color = 0;
float sum = 0;
for(int x = -3; x < 4; x++)
{
for(int y = -3; y < 4; y++)
{
vec2 offset = vec2(x * radius, y * radius);
float dist = exp(- sqrt(x * x + y * y) / 2);
vec4 t = texture2D(framebuffer, pos + offset);
color += contrast((t.r + t.g + t.b) / 3) * dist;
sum += dist;
}
}
color /= sum;
vec4 tc = texture2D(framebuffer, pos) + vec4(color, color, color, 1) * 0.5;
gl_FragColor = tc;
}
uniform sampler2D framebuffer;
void main(void)
{
vec4 c = texture2D(framebuffer, gl_TexCoord[0].xy);
float val1 = c.r + 2 * c.g - 2 * c.b;
float val2 = (c.r + c.g + c.b) / 3;
float val = 0.8 * val1 + 0.2 * val2;
float sum = (1.005 * (1 + c.g) + 1.005 * (1 + c.r) + 1) / 3;
gl_FragColor = vec4(val * 1.005 * (1 + c.g) / sum, val * 1.005 * (1 + c.r) / sum, val / sum, 1);
}
uniform sampler2D framebuffer;
float contrast(float c)
{
float a = 0.09;
return (c - a) / (1 - 2 * a);
}
void main(void)
{
vec4 pixel = texture2D(framebuffer, gl_TexCoord[0].xy);
pixel.r = contrast(pixel.r * 1.3);
pixel.g = contrast(pixel.g + 0.05);
pixel.b = contrast(pixel.b * 0.4 + 0.3);
gl_FragColor = pixel;
}
uniform sampler2D framebuffer;
uniform float t;
void main(void)
{
vec2 pos = gl_TexCoord[0].xy;
vec2 offset = vec2(sin(t + pos.x * 31), cos(t + pos.y * 37)) * 0.006;
gl_FragColor = texture2D(framebuffer, offset + gl_TexCoord[0].xy) * vec4(0.5, 0.7, 1, 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment