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 5, 2012

Copy link
Copy Markdown

Rad! Man, I need to make shaders permalink.

@ofTheo

ofTheo commented Jan 5, 2012

Copy link
Copy Markdown
Author

yeah - for sure! that would be so nice to be able to share a modification.
super nice work though!!

@notlion

notlion commented Jan 9, 2012

Copy link
Copy Markdown

http://notlion.github.com/streetview-stereographic/#o=0.915,-0.058,0.096,0.388&z=1.121&mz=15&p=22.27844,114.16438&fs=5d000001006807000000000000003a9b896105e32d80d13554b9d34bbfd90bf88bb586e732cb3c72e57b832c2ec8a63cf3700f3945d75fc5ed2d2c2ed102355a97ae79325235a81737fdaf688a59a07d58a81fb2579222b45a814e5c46bc7543e798bad2317bd784693de2e459d9db7519acb606f16d3ce53a3f6ded6979f69879508972efdadf728c9fade1197f8f018f82db2c741d5ba38c8c865bd658cfcd367446fbff3733cf95fe2080c8158858b1079a84607977d5806553211e5a13e2fc35a02b3a424799b98ace46460b17e3ba0e512d393032a032114772d8638238004d8949c3e71d2af0e32819c69add5d0fd319f079e8fe5f1b03f8da6a800d584ada80066e634e34deaeab272eb7a43f3e87a80c182bc03d314d1b1b434e0866b86653eb369dd24adf59a0a05db5b818084c0ecd03828672b7a2f52d9b57522249e3882ca4dc34bd800eeb5f5fbb878afa29d58d11441ffa79b69d6535aba585f759595bdfef58685eb060c97e492533885b2ccabeca0332f1e9ff4a50a6f2d1c9c74ee7badf17aeb7f15ab14f0f6cba77e108000a90508112cb7b372d8e9a6bbb3d20cdd5503d67e0072b909668e33e6a44134b5a3f94267ecf68370e5505b1dc0c95f56b64ec783485c14bb16fd8f1f4e6b9b934d81dc2031417ea62188cfa38bbc21599fd9e442846f878c4dd1e1dfdf417af789d8948657f67b91201d7990e89a0eb88979ccbd306fd46b9718f73b7f68d701c4581fc15d3f39514d690bcd435cda549ed631e8f46d0bb899d31b0a3ce52aae8f0f5a9195160871feaceb29e248cd5c5bb8501e4d72abbef741af3f13741058991ed588136cda3a839a3a916c9d3a7972e02d7d38e43a4273ead769915b082464a0fb8861f5ebf7eb924682cbcc6535a20472b09c72a9f9ebeb638fd64f4f3529cbfbf0e0dcf610ff869790cfab9a7407a6bb697c3cd515f80ea50a931a4ac5e8cd4b2b478e68a494c5624103c734d3c1887fede98b7

God these URLs are hideous..

@ofTheo

ofTheo commented Jan 9, 2012

Copy link
Copy Markdown
Author

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

@notlion

notlion commented Jan 9, 2012

Copy link
Copy Markdown

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

@ofTheo

ofTheo commented Jan 9, 2012

Copy link
Copy Markdown
Author

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

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