Skip to content

Instantly share code, notes, and snippets.

@darknoon
Created June 17, 2011 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darknoon/1032000 to your computer and use it in GitHub Desktop.
Save darknoon/1032000 to your computer and use it in GitHub Desktop.
Antialiased burst from color stripes
//Declare a 2D texture as a uniform variable
uniform sampler2D texture;
uniform float samples;
void main()
{
vec2 poissonDisk[8];
poissonDisk[0] = vec2(-0.613392, 0.617481);
poissonDisk[1] = vec2(0.170019, -0.040254);
poissonDisk[2] = vec2(-0.299417, 0.791925);
poissonDisk[3] = vec2(0.645680, 0.493210);
poissonDisk[4] = vec2(-0.651784, 0.717887);
poissonDisk[5] = vec2(0.421003, 0.027070);
poissonDisk[6] = vec2(-0.817194, -0.271096);
poissonDisk[7] = vec2(-0.705374, -0.668203);
const float PI2 = 3.1415926535 * 2.0;
float dist = length(gl_TexCoord[0].xy * 2.0 - 1.0);
int iterations = dist > 0.2 ? 1 : (dist > 0.05 ? 2 : 10);
float iterations_inv = 1.0 / float(iterations);
vec4 avg = vec4(0.0);
if (iterations > 1) {
for (int i=0; i<iterations; i++) {
vec2 tc = gl_TexCoord[0].xy;
tc += + 0.001*poissonDisk[i];
tc *= 2.0;
tc -= 1.0;
tc = vec2(atan(tc.y, tc.x) / PI2, sqrt(tc.x * tc.x + tc.y * tc.y));
avg += iterations_inv * texture2D(texture, tc );
}
gl_FragColor = gl_Color * avg;
} else {
vec2 tc = gl_TexCoord[0].xy;
tc *= 2.0;
tc -= 1.0;
tc = vec2(atan(tc.y, tc.x) / PI2, sqrt(tc.x * tc.x + tc.y * tc.y));
gl_FragColor = gl_Color * texture2D(texture, tc);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment