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