Skip to content

Instantly share code, notes, and snippets.

@ishikawash
Created January 7, 2014 16:18
Show Gist options
  • Save ishikawash/8301781 to your computer and use it in GitHub Desktop.
Save ishikawash/8301781 to your computer and use it in GitHub Desktop.
Pin-Hole like effect
// fragment shader
uniform sampler2D tex;
uniform vec2 viewport;
uniform vec2 origin;
uniform float radius;
uniform float attenuation;
uniform vec3 background_color;
void main()
{
vec2 uv = gl_FragCoord.xy / viewport;
uv.y = 1.0 - uv.y;
vec2 point = 2.0*uv - 1.0;
point.y *= viewport.y / viewport.x;
vec3 tex_color = texture2D(tex, uv).xyz;
vec3 color = background_color;
if (radius > 0.0) {
float d = distance(point, origin);
if (d <= radius) {
color = tex_color;
} else {
float k = (d - radius);
color = mix(tex_color, background_color, attenuation*k*k);
}
}
gl_FragColor = vec4(color, 1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment