Last active
May 7, 2024 16:09
-
-
Save eladg/2cdda165ab6a327d1b24a095abc966fd to your computer and use it in GitHub Desktop.
WebGL: stereoscopic projection transformation (Fragment Shader)
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
// credits to: https://github.com/notlion/streetview-stereographic | |
precision mediump float; | |
uniform sampler2D texture; | |
uniform float scale, aspect, time; | |
uniform mat3 transform; | |
varying vec2 v_texcoord; | |
#define PI 3.141592653589793 | |
void main(){ | |
vec2 rads = vec2(PI * 2., PI); | |
vec2 pnt = (v_texcoord - .5) * vec2(scale, scale * aspect); | |
// Project to Sphere | |
float x2y2 = pnt.x * pnt.x + pnt.y * pnt.y; | |
vec3 sphere_pnt = vec3(2. * pnt, x2y2 - 1.) / (x2y2 + 1.); | |
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); | |
gl_FragColor = texture2D(texture, vec2(lon, lat) / rads); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment