Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #version 120
- #ifdef GL_ES
- precision mediump float;
- #endif
- varying vec2 vTexCoord;
- uniform sampler2D uImage0;
- uniform float blackHoleX;
- uniform float blackHoleY;
- uniform float apply;
- void main(void)
- {
- vec2 uv = vTexCoord;
- // Calculate line equation between point and black hole
- vec3 dirP = vec3(uv.y - blackHoleY, -(uv.x - blackHoleX), 0);
- dirP.z = -dirP.x * blackHoleX - dirP.y * blackHoleY;
- // Calculate closest point belonging to both any edge of the screen and said line
- vec2 inter = vec2(0.);
- vec2 p1 = vec2(0.);
- vec2 p2 = vec2(0.);
- if(dirP.x == 0.0)
- inter = vec2(uv.x > 0.5 ? 1.0 : 0.0, blackHoleY);
- else if(dirP.y == 0.0)
- inter = vec2(blackHoleX, uv.y > 0.5 ? 1.0 : 0.0);
- else
- {
- if(uv.x > blackHoleX)
- {
- if(uv.y > blackHoleY)
- {
- p1 = vec2(1.0, (-dirP.z - dirP.x) / dirP.y);
- p2 = vec2((-dirP.z - dirP.y) / dirP.x, 1.0);
- }
- else
- {
- p1 = vec2(1.0, (-dirP.z - dirP.x) / dirP.y);
- p2 = vec2(-dirP.z / dirP.x, 0.);
- }
- }
- else
- {
- if(uv.y > blackHoleY)
- {
- p1 = vec2(0., -dirP.z / dirP.y);
- p2 = vec2((-dirP.z - dirP.y) / dirP.x, 1.0);
- }
- else
- {
- p1 = vec2(0., -dirP.z / dirP.y);
- p2 = vec2(-dirP.z / dirP.x, 0.);
- }
- }
- inter = distance(uv, p1) < distance(uv, p2) ? p1 : p2;
- }
- float d = distance(uv, inter) * distance(inter, vec2(0.5, 0.5)) / distance(inter, vec2(blackHoleX, blackHoleY));
- gl_FragColor = texture2D(uImage0, d * normalize(vec2(blackHoleX, blackHoleY) - inter) + inter);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement