Terrain ground tiling fix
- Ashwani Shahrawat
- Jun 5, 2024
- 1 min read
Will cover different techniques to fix terrain texture tiling
///// Tiling Fix using Noise Texture /////
// The MIT License
// Copyright © 2017 Inigo Quilez
// Ref : https://www.shadertoy.com/view/Xtl3zf
TEXTURE2D(_NoiseTex);
SAMPLER(sampler_NoiseTex);
inline float4 TilingFix(Texture2D a_Tex, sampler a_Sampler, float2 uv)
{
float k = SAMPLE_TEXTURE2D(_NoiseTex, sampler_NoiseTex, 0.005 * uv).x; // cheap (cache friendly) lookup
float2 duvdx = ddx(uv);
float2 duvdy = ddy(uv);
float l = k * 8.0;
float f = frac(l);
float ia = floor(l);
float ib = ia + 1.0;
float2 offa = sin(float2(3.0, 7.0) * ia); // can replace with any other hash
float2 offb = sin(float2(3.0, 7.0) * ib); // can replace with any other hash
float4 cola = SAMPLE_TEXTURE2D_GRAD(a_Tex, a_Sampler, uv + offa, duvdx, duvdy);
float4 colb = SAMPLE_TEXTURE2D_GRAD(a_Tex, a_Sampler, uv + offb, duvdx, duvdy);
return lerp(cola, colb, smoothstep(0.2, 0.8, f - 0.1 * sum(cola.rgb - colb.rgb)));
}



Comments