/* ---------------------------------------------------------- Terrain Tessellation sample from NVIDIA's DirectX 11 SDK: http://developer.nvidia.com/nvidia-graphics-sdk-11-direct3d ---------------------------------------------------------- */ #include "TerrainTessellationCommon.hlsl" float2 fade(float2 t) { return t * t * t * (t * (t * 6 - 15) + 10); // new curve (quintic) } Texture2D g_NoiseTexture; #define FIXED_FN_INTERPOLATION 0 #if FIXED_FN_INTERPOLATION // just use normal 2D texture lookup // note - artifacts are visible at low frequencies due to interpolation precision float inoise(float2 p) { const float mipLevel = 0; return 2 * (g_NoiseTexture.SampleLevel(SamplerRepeatLinear, p, mipLevel).x - 0.5); // [-1,1] } #else // interpolate 2D texture float inoise(float2 p) { float2 i = floor(p*256); float2 f = 256*p - i; f = fade(f); i /= 256; const float mipLevel = 0; float4 n; n.x = g_NoiseTexture.SampleLevel(SamplerRepeatPoint, i, mipLevel).x; n.y = g_NoiseTexture.SampleLevel(SamplerRepeatPoint, i, mipLevel, int2(1,0)).x; n.z = g_NoiseTexture.SampleLevel(SamplerRepeatPoint, i, mipLevel, int2(0,1)).x; n.w = g_NoiseTexture.SampleLevel(SamplerRepeatPoint, i, mipLevel, int2(1,1)).x; const float interpolated = lerp(lerp( n.x, n.y, f.x), lerp( n.z, n.w, f.x), f.y); // [0,1] return 2.0 * interpolated - 1.0; } #endif // FIXED_FN_INTERPOLATION // calculate gradient of noise (expensive!) float2 inoiseGradient(float2 p, float d) { float f0 = inoise(p); float fx = inoise(p + float2(d, 0)); float fy = inoise(p + float2(0, d)); return float2(fx - f0, fy - f0) / d; } // fractal sum float fBm(float2 p, int octaves, float lacunarity = 2.0, float gain = 0.5) { float freq = 1.0, amp = 1.0; float sum = 0; for(int i=0; i 0) return h + f*saturate(h); else return f; }