Advertisement
Ajes

Untitled

Jul 26th, 2015
486
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. const float isqrt2 = 0.70710676908493042;
  2.  
  3. vec3 cubify(const in vec3 s)
  4. {
  5. float xx2 = s.x * s.x * 2.0;
  6. float yy2 = s.y * s.y * 2.0;
  7.  
  8. vec2 v = vec2(xx2 - yy2, yy2 - xx2);
  9.  
  10. float ii = v.y - 3.0;
  11. ii *= ii;
  12.  
  13. float isqrt = -sqrt(ii - 12.0 * xx2) + 3.0;
  14.  
  15. v = sqrt(v + isqrt);
  16. v *= isqrt2;
  17.  
  18. return sign(s) * vec3(v, 1.0);
  19. }
  20.  
  21. vec3 sphere2cube(const in vec3 sphere)
  22. {
  23. vec3 f = abs(sphere);
  24.  
  25. bool a = f.y >= f.x && f.y >= f.z;
  26. bool b = f.x >= f.z;
  27.  
  28. return a ? cubify(sphere.xzy).xzy : b ? cubify(sphere.yzx).zxy : cubify(sphere);
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement