Advertisement
madfox03

Stars.cgnc

Sep 24th, 2019
855
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // Cubemap projection
  3. float3 sync(float3 dir)
  4. {
  5.     float3 v = abs(dir);
  6.     if (v.z > v.x && v.z > v.y)
  7.     {
  8.         if (dir.z > 0)
  9.             v = dir;
  10.         else
  11.             v = float3(dir.xy, -dir.z);
  12.     }
  13.     else if (v.y > v.x)
  14.     {
  15.         if (dir.y > 0)
  16.             v = dir.xzy;
  17.         else
  18.             v = float3(dir.xz, -dir.y);
  19.     }
  20.     else
  21.     {
  22.         if (dir.x > 0)
  23.             v = dir.yzx;
  24.         else
  25.             v = float3(dir.yz, -dir.x);
  26.     }
  27.  
  28.     return v;
  29. }
  30.  
  31. half2 proj(half3 p, half l)
  32. {
  33.     return half2(atan2(p.x,p.z) * l *  UNITY_INV_TWO_PI, 0.5 - asin(p.y) * UNITY_INV_PI);
  34. }
  35.  
  36. half2 shift(half2 v, half4 m, half l)
  37. {
  38.     m.z *= l;
  39.     half2 r = v * m.xy + m.zw;
  40.     return r;
  41. }
  42.  
  43.  
  44. float2 getCoordinate(float3 dir)
  45. {
  46.     return  dir.xy / dir.z;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement