#ifndef NOISE_INCLUDE #define NOISE_INCLUDE uniform float _Frequency; uniform float _Strength; uniform float _Scale; float3 mod2D(float3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; } float2 mod2D(float2 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; } float3 permute(float3 x) { return mod2D(((x * 34.0) + 1.0) * x); } inline float Noise(float2 v) { const float4 C = float4(0.211324865, 0.366025403, -0.577350269, 0.024390243); float2 i = floor(v + dot(v, C.yy)); float2 x0 = v - i + dot(i, C.xx); float2 i1; i1 = (x0.x > x0.y) ? float2(1.0, 0.0) : float2(0.0, 1.0); float4 x12 = x0.xyxy + C.xxzz; x12.xy -= i1; i = mod2D(i); float3 p = permute(permute(i.y + float3(0.0, i1.y, 1.0)) + i.x + float3(0.0, i1.x, 1.0)); float3 m = max(0.5 - float3(dot(x0, x0), dot(x12.xy, x12.xy), dot(x12.zw, x12.zw)), 0.0); m = m * m; m = m * m; float3 x = 2.0 * frac(p * C.www) - 1.0; float3 h = abs(x) - 0.5; float3 ox = floor(x + 0.5); float3 a0 = x - ox; m *= 1.79284291 - 0.85373472 * (a0 * a0 + h * h); float3 g; g.x = a0.x * x0.x + h.x * x0.y; g.yz = a0.yz * x12.xz + h.yz * x12.yw; return 130.0 * dot(m, g); } inline float3 FinalPerlin(float3 worldPos,float4 color,float _time) { float simplePerlin = Noise((_time * _Frequency + _Scale * worldPos.xz)) - 0.3; float3 finalPerlin = simplePerlin * (1 - color.xxx) * _Strength; return finalPerlin; } #endif