Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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