Created
January 7, 2014 16:18
-
-
Save ishikawash/8301781 to your computer and use it in GitHub Desktop.
Pin-Hole like effect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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