Skip to content

Instantly share code, notes, and snippets.

@nicoptere
Created August 11, 2020 09:28
Show Gist options
  • Save nicoptere/b7875031c511f81c58ea3e7729fb4bc8 to your computer and use it in GitHub Desktop.
Save nicoptere/b7875031c511f81c58ea3e7729fb4bc8 to your computer and use it in GitHub Desktop.

Revisions

  1. nicoptere revised this gist Aug 11, 2020. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions moebius 3D GLSL (for three.js)
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,3 @@


    /**
    original code https://gist.github.com/Dan-Piker/f7d790b3967d41bff8b0291f4cf7bd9e

  2. nicoptere created this gist Aug 11, 2020.
    38 changes: 38 additions & 0 deletions moebius 3D GLSL (for three.js)
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@


    /**
    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);