Created
January 19, 2010 21:09
-
-
Save gamefreak/281298 to your computer and use it in GitHub Desktop.
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
uniform sampler2D tex; | |
uniform float r; //range 0 to 1.0 | |
uniform float mag; //range 0.1 to 10.0 | |
uniform vec2 target;//range -0.5 to 0.5 | |
uniform vec4 color; | |
vec3 getZ(vec2 c,float r) | |
{ | |
return vec3(c.x,c.y,sqrt(pow(r,2.0)-pow(c.x,2.0)-pow(c.y,2.0))); | |
} | |
float calcDist(float azs, float ths, float azf, float thf) | |
{ | |
//arccosine formula for great circle radius | |
return r * acos(sin(azs) * sin(azf) + cos(azs) * cos(azf) * cos(thf - ths)); | |
//ALTERNATE haversine version. About 0.24% slower. | |
//return r * 2.0 * asin(sqrt(pow(sin((azf - azs) / 2.0), 2.0) + cos(azs) * cos(azf) * pow(sin((thf - ths) / 2.0), 2.0))); | |
} | |
void main() | |
{ | |
vec2 tx = gl_TexCoord[0].xy-0.5; | |
if (length(tx) < r) { | |
vec3 p1 = getZ(tx,r); | |
vec3 p2 = getZ(target,r); | |
float azs = atan(length(p1.xy),p1.z); | |
float ths = atan(p1.y,p1.x); | |
float azf = atan(length(p2.xy),p2.z); | |
float thf = atan(p2.y,p2.x); | |
float str = mag * inversesqrt(calcDist(azs,ths,azf,thf)) / 10.0; | |
gl_FragColor = (10.0-mag) * texture2D(tex, gl_TexCoord[0].xy) / 10.0 + color*str; | |
} else { | |
gl_FragColor = texture2D(tex, gl_TexCoord[0].xy); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment