1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| inline float Unity_SimpleNoise_RandomValue_float (float2 uv) { float angle = dot(uv, float2(12.9898, 78.233)); #if defined(SHADER_API_MOBILE) && (defined(SHADER_API_GLES) || defined(SHADER_API_GLES3) || defined(SHADER_API_VULKAN)) angle = fmod(angle, TWO_PI); #endif return frac(sin(angle)*43758.5453); }
inline float Unity_SimpleNnoise_Interpolate_float (float a, float b, float t) { return (1.0-t)*a + (t*b); }
inline float Unity_SimpleNoise_ValueNoise_float (float2 uv) { float2 i = floor(uv); float2 f = frac(uv); f = f * f * (3.0 - 2.0 * f);
uv = abs(frac(uv) - 0.5); float2 c0 = i + float2(0.0, 0.0); float2 c1 = i + float2(1.0, 0.0); float2 c2 = i + float2(0.0, 1.0); float2 c3 = i + float2(1.0, 1.0); float r0 = Unity_SimpleNoise_RandomValue_float(c0); float r1 = Unity_SimpleNoise_RandomValue_float(c1); float r2 = Unity_SimpleNoise_RandomValue_float(c2); float r3 = Unity_SimpleNoise_RandomValue_float(c3);
float bottomOfGrid = Unity_SimpleNnoise_Interpolate_float(r0, r1, f.x); float topOfGrid = Unity_SimpleNnoise_Interpolate_float(r2, r3, f.x); float t = Unity_SimpleNnoise_Interpolate_float(bottomOfGrid, topOfGrid, f.y); return t; }
float Unity_SimpleNoise(float2 UV, float Scale) { float t = 0.0;
float freq = pow(2.0, float(0)); float amp = pow(0.5, float(3-0)); t += Unity_SimpleNoise_ValueNoise_float(float2(UV.x*Scale/freq, UV.y*Scale/freq))*amp;
freq = pow(2.0, float(1)); amp = pow(0.5, float(3-1)); t += Unity_SimpleNoise_ValueNoise_float(float2(UV.x*Scale/freq, UV.y*Scale/freq))*amp;
freq = pow(2.0, float(2)); amp = pow(0.5, float(3-2)); t += Unity_SimpleNoise_ValueNoise_float(float2(UV.x*Scale/freq, UV.y*Scale/freq))*amp;
return t; }
|