Nav apraksta
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using Unity.IL2CPP.CompilerServices;
  2. using static Unity.Mathematics.math;
  3. namespace Unity.Mathematics
  4. {
  5. /// <summary>
  6. /// A static class containing noise functions.
  7. /// </summary>
  8. [Il2CppEagerStaticClassConstruction]
  9. public static partial class noise
  10. {
  11. // Modulo 289 without a division (only multiplications)
  12. static float mod289(float x) { return x - floor(x * (1.0f / 289.0f)) * 289.0f; }
  13. static float2 mod289(float2 x) { return x - floor(x * (1.0f / 289.0f)) * 289.0f; }
  14. static float3 mod289(float3 x) { return x - floor(x * (1.0f / 289.0f)) * 289.0f; }
  15. static float4 mod289(float4 x) { return x - floor(x * (1.0f / 289.0f)) * 289.0f; }
  16. // Modulo 7 without a division
  17. static float3 mod7(float3 x) { return x - floor(x * (1.0f / 7.0f)) * 7.0f; }
  18. static float4 mod7(float4 x) { return x - floor(x * (1.0f / 7.0f)) * 7.0f; }
  19. // Permutation polynomial: (34x^2 + x) math.mod 289
  20. static float permute(float x) { return mod289((34.0f * x + 1.0f) * x); }
  21. static float3 permute(float3 x) { return mod289((34.0f * x + 1.0f) * x); }
  22. static float4 permute(float4 x) { return mod289((34.0f * x + 1.0f) * x); }
  23. static float taylorInvSqrt(float r) { return 1.79284291400159f - 0.85373472095314f * r; }
  24. static float4 taylorInvSqrt(float4 r) { return 1.79284291400159f - 0.85373472095314f * r; }
  25. static float2 fade(float2 t) { return t*t*t*(t*(t*6.0f-15.0f)+10.0f); }
  26. static float3 fade(float3 t) { return t*t*t*(t*(t*6.0f-15.0f)+10.0f); }
  27. static float4 fade(float4 t) { return t*t*t*(t*(t*6.0f-15.0f)+10.0f); }
  28. static float4 grad4(float j, float4 ip)
  29. {
  30. float4 ones = float4(1.0f, 1.0f, 1.0f, -1.0f);
  31. float3 pxyz = floor(frac(float3(j) * ip.xyz) * 7.0f) * ip.z - 1.0f;
  32. float pw = 1.5f - dot(abs(pxyz), ones.xyz);
  33. float4 p = float4(pxyz, pw);
  34. float4 s = float4(p < 0.0f);
  35. p.xyz = p.xyz + (s.xyz*2.0f - 1.0f) * s.www;
  36. return p;
  37. }
  38. // Hashed 2-D gradients with an extra rotation.
  39. // (The constant 0.0243902439 is 1/41)
  40. static float2 rgrad2(float2 p, float rot)
  41. {
  42. // For more isotropic gradients, math.sin/math.cos can be used instead.
  43. float u = permute(permute(p.x) + p.y) * 0.0243902439f + rot; // Rotate by shift
  44. u = frac(u) * 6.28318530718f; // 2*pi
  45. return float2(cos(u), sin(u));
  46. }
  47. }
  48. }