Skip to content

Instantly share code, notes, and snippets.

@ofTheo
Created January 5, 2012 20:04
Show Gist options
  • Save ofTheo/1566967 to your computer and use it in GitHub Desktop.
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;
}
}
@ofTheo
Copy link
Author

ofTheo commented Jan 9, 2012

oh nice. will you add a permalink button to the project to generate the url?

@notlion
Copy link

notlion commented Jan 9, 2012

The URL actually changes every time the shader successfully compiles, so you should be able to just copy it.

@ofTheo
Copy link
Author

ofTheo commented Jan 9, 2012

oh I didn't notice thats awesome!

btw is it possible to include fullscreen in the url? ( currently if I have a fullscreen view it doesn't save the fullscreen into the url )
sorry for putting the feature requests here :-)

@notlion
Copy link

notlion commented Jan 9, 2012

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
Copy link

notlion commented Jan 9, 2012

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

@ofTheo
Copy link
Author

ofTheo commented Jan 9, 2012 via email

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