HoloCP.cginc 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include "UnityCG.cginc"
  2. #ifndef HOLOCP_INCLUDED
  3. #define HOLOCP_INCLUDED
  4. #pragma target 5.0
  5. #pragma only_renderers d3d11
  6. fixed3 mod(fixed3 x, fixed3 y)
  7. {
  8. return x - y * floor(x / y);
  9. }
  10. fixed r(fixed n)
  11. {
  12. return frac(abs(sin(n*55.753)*367.34));
  13. }
  14. fixed r(fixed2 n)
  15. {
  16. return r(dot(n, fixed2(2.46, -1.21)));
  17. }
  18. fixed hash1(fixed2 p)
  19. {
  20. fixed n = dot(p, fixed2(127.1, 311.7));
  21. return frac(sin(n)*43758.5453);
  22. }
  23. half cubicPulse(fixed c, fixed w, fixed x)
  24. {
  25. x = abs(x - c);
  26. if (x > w)
  27. return 0;
  28. x /= w;
  29. return 1 - x * x * (3 - 2 * x);
  30. }
  31. half2 cubicPulse(half c, half2 w, half x)
  32. {
  33. x = abs(x - c);
  34. if (x > w.x)
  35. return 0;
  36. half2 x2 = x / w;
  37. if (x > w.y)
  38. return half2(1 - x2.x * x2.x * (3 - 2 * x2.x), 0.);
  39. return max(1 - x2 * x2 * (3 - 2 * x2), 0.);
  40. }
  41. fixed4 _NearPlaneTransitionDistance;
  42. inline fixed ComputeNearPlaneTransition(fixed4 vertex, fixed fadeEnd, fixed fadeRange)
  43. {
  44. fixed distToCamera = -UnityObjectToViewPos(vertex).z;
  45. return smoothstep(fadeEnd, fadeEnd + fadeRange, distToCamera);
  46. }
  47. fixed4 getTransition(fixed3 world, fixed3 center, fixed3 direction, fixed transitionOffset, fixed transitionWidth, fixed detailedTransitionWidth)
  48. {
  49. fixed4 transition = 1;
  50. #if SPHERICAL_PULSE
  51. transition.xy = cubicPulse(transitionOffset, fixed2(transitionWidth, transitionWidth * detailedTransitionWidth), distance(center, world));
  52. #endif
  53. #if LINEAR_PULSE
  54. transition.xy = cubicPulse(transitionOffset, fixed2(transitionWidth, transitionWidth * detailedTransitionWidth), dot(world, normalize(direction.xyz)));
  55. #endif
  56. #if SPHERICAL_WIPE
  57. transition.xy = smoothstep(transitionOffset + fixed2(transitionWidth, transitionWidth * detailedTransitionWidth) + 0.001, transitionOffset - fixed2(transitionWidth, transitionWidth * detailedTransitionWidth), distance(center, world));
  58. #endif
  59. #if LINEAR_WIPE
  60. transition.xy = smoothstep(transitionOffset + fixed2(transitionWidth, transitionWidth * detailedTransitionWidth) + 0.001, transitionOffset - fixed2(transitionWidth, transitionWidth * detailedTransitionWidth), dot(world, normalize(direction.xyz)));
  61. #endif
  62. return transition;
  63. }
  64. fixed4 getPulse(fixed3 world, fixed3 center, fixed transitionOffset, fixed transitionWidth, fixed detailedTransitionWidth)
  65. {
  66. fixed4 transition = 1;
  67. transition.xy = cubicPulse(transitionOffset, fixed2(transitionWidth, transitionWidth * detailedTransitionWidth), distance(center, world));
  68. return transition;
  69. }
  70. #endif // HOLOCP_INCLUDED