Skip to content

Instantly share code, notes, and snippets.

@nicoptere
Created August 11, 2020 09:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicoptere/b7875031c511f81c58ea3e7729fb4bc8 to your computer and use it in GitHub Desktop.
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
/**
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