Skip to content

Instantly share code, notes, and snippets.

@ofTheo
Created January 5, 2012 20:04
Show Gist options
  • Select an option

  • Save ofTheo/1566967 to your computer and use it in GitHub Desktop.

Select an option

Save ofTheo/1566967 to your computer and use it in GitHub Desktop.
uniform sampler2D texture;
uniform float scale, aspect, time;
uniform mat3 transform;
varying vec2 v_texcoord;
#define PI 3.141592653589793
#define PI_2 1.570796326794897
vec2 tc_offset[9];
void main(){
int doEdge = 1;
vec2 rads = vec2(PI * 2., PI);
float x = (v_texcoord.x - .5) * scale;
float y = (v_texcoord.y - .5) * scale * aspect;
// Project to Sphere
vec3 sphere_pnt = vec3(
(2. * x) / (1. + x*x + y*y),
(2. * y) / (1. + x*x + y*y),
(x*x + y*y - 1.) / (1. + x*x + y*y)
);
sphere_pnt *= transform;
// Convert to Spherical Coordinates
float r = length(sphere_pnt);
float lon = atan(sphere_pnt.y, sphere_pnt.x);
float lat = acos(sphere_pnt.z / r);
if( doEdge == 1 ){
vec4 sample[9];
tc_offset[0] = vec2(-1.0, -1.0);
tc_offset[1] = vec2(0.0, -1.0);
tc_offset[2] = vec2(1.0, -1.0);
tc_offset[3] = vec2(-1.0, 0.0);
tc_offset[4] = vec2(0.0, 0.0);
tc_offset[5] = vec2(1.0, 0.0);
tc_offset[6] = vec2(-1.0, 1.0);
tc_offset[7] = vec2(0.0, 1.0);
tc_offset[8] = vec2(1.0, 1.0);
//color2 = texture2D(texture, vec2(lon, lat) / rads);
for(int i = 0; i < 9; i++){
sample[i] = texture2D(texture, (vec2(lon, lat) / rads) + tc_offset[i] * 0.001);
}
vec4 horizEdge = sample[2] + (2.0*sample[5]) + sample[8] -
(sample[0] + (2.0*sample[3]) + sample[6]);
vec4 vertEdge = sample[0] + (2.0*sample[1]) + sample[2] -
(sample[6] + (2.0*sample[7]) + sample[8]);
vec3 s3 = sqrt((horizEdge.rgb * horizEdge.rgb) + (vertEdge.rgb * vertEdge.rgb));
float brightness = (s3.r + s3.g + s3.b) / 3.0;
if( brightness > 0.35 ){
brightness = 0.0;
}else{
brightness = 1.0;
}
vec4 color = texture2D(texture, vec2(lon, lat) / rads);
color.rgb *= brightness;
gl_FragColor = color;
}
}
@notlion

notlion commented Jan 9, 2012

Copy link
Copy Markdown

Haha no problem. I had thought about that but wasn't sure if it would be confusing to arrive at the page fullscreen. I suppose it's a good thing to save, though.

@notlion

notlion commented Jan 9, 2012

Copy link
Copy Markdown

Made an issue so I don't forget later..
notlion/streetview-stereographic#1

@ofTheo

ofTheo commented Jan 9, 2012 via email

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment