Created
August 11, 2020 09:28
-
-
Save nicoptere/b7875031c511f81c58ea3e7729fb4bc8 to your computer and use it in GitHub Desktop.
port of Daniel Piker's transform to GLSL port of https://gist.github.com/Dan-Piker/f7d790b3967d41bff8b0291f4cf7bd9e
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
/** | |
original code https://gist.github.com/Dan-Piker/f7d790b3967d41bff8b0291f4cf7bd9e | |
need to declare the following: | |
uniform vec3 origin; | |
uniform float p; | |
uniform float q; | |
uniform float t; | |
*/ | |
vec3 pos = position - origin; | |
float xa = pos.x; | |
float ya = pos.y; | |
float za = pos.z; | |
//reverse stereographic projection to hypersphere | |
float pLength = (1. + xa * xa + ya * ya + za * za); | |
float xb = 2. * xa / pLength; | |
float yb = 2. * ya / pLength; | |
float zb = 2. * za / pLength; | |
float wb = (-1. + xa * xa + ya * ya + za * za) / pLength; | |
//rotate hypersphere by amount t | |
float xc = xb * cos(p * t) + yb * sin(p * t); | |
float yc = -xb * sin(p * t) + yb * cos(p * t); | |
float zc = zb * cos(q * t) - wb * sin(q * t); | |
float wc = zb * sin(q * t) + wb * cos(q * t); | |
//project stereographically back to flat 3D | |
float xd = xc / (1. - wc); | |
float yd = yc / (1. - wc); | |
float zd = zc / (1. - wc); | |
//the transformed point | |
vec3 transformed = vec3(xd, yd, zd); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment