Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const float isqrt2 = 0.70710676908493042;
- vec3 cubify(const in vec3 s)
- {
- float xx2 = s.x * s.x * 2.0;
- float yy2 = s.y * s.y * 2.0;
- vec2 v = vec2(xx2 - yy2, yy2 - xx2);
- float ii = v.y - 3.0;
- ii *= ii;
- float isqrt = -sqrt(ii - 12.0 * xx2) + 3.0;
- v = sqrt(v + isqrt);
- v *= isqrt2;
- return sign(s) * vec3(v, 1.0);
- }
- vec3 sphere2cube(const in vec3 sphere)
- {
- vec3 f = abs(sphere);
- bool a = f.y >= f.x && f.y >= f.z;
- bool b = f.x >= f.z;
- return a ? cubify(sphere.xzy).xzy : b ? cubify(sphere.yzx).zxy : cubify(sphere);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement