Add a mitigation for tilling textures. Very usefull for terrains, etc

This commit is contained in:
samuncle 2018-04-07 04:11:11 +02:00
parent 32016f0118
commit daf4721fa9
2 changed files with 81 additions and 18 deletions

View File

@ -15,22 +15,7 @@ layout(location = 1) out vec4 o_normal_color;
void main()
{
vec4 col = sampleTextureLayer0(uv);
vec4 col2 = sampleTextureLayer0(uv * 2.0);
vec4 col3 = sampleTextureLayer0(uv * 4.0);
// From Low to medium
float factor = camdist * 0.01;
factor = pow(factor - 0.1, 1.4);
factor = clamp(factor, 0.0, 1.0);
col = mix(col2, col, factor);
// From medium to high
factor = camdist * 0.01;
factor = pow(factor - 0.1, 0.4);
factor = clamp(factor, 0.0, 1.0);
col = mix(col3, col, factor);
vec4 col = multi_sampleTextureLayer0(uv, camdist);
if (hue_change > 0.0)
{
@ -52,8 +37,8 @@ void main()
vec3 final_color = col.xyz * color.xyz;
#if defined(Advanced_Lighting_Enabled)
vec4 layer_2 = sampleTextureLayer2(uv);
vec4 layer_3 = sampleTextureLayer3(uv);
vec4 layer_2 = multi_sampleTextureLayer2(uv, camdist);
vec4 layer_3 = multi_sampleTextureLayer3(uv, camdist);
o_diffuse_color = vec4(final_color, layer_2.z);
vec3 tangent_space_normal = 2.0 * layer_3.xyz - 1.0;

View File

@ -6,11 +6,43 @@ uniform sampler2D tex_layer_3;
uniform sampler2D tex_layer_4;
uniform sampler2D tex_layer_5;
#define HIGH_SAMPLING 4.0
#define MEDIUM_SAMPLING 2.0
#define LOW_SAMPLING 1.0
vec4 sampleTextureLayer0(vec2 uv)
{
return texture(tex_layer_0, uv);
}
vec4 multi_sampleTextureLayer0(vec2 uv, float distance)
{
vec4 l_col = sampleTextureLayer0(uv * LOW_SAMPLING);
vec4 m_col = sampleTextureLayer0(uv * MEDIUM_SAMPLING);
vec4 h_col = sampleTextureLayer0(uv * HIGH_SAMPLING);
/* debug
l_col = vec4(1.0, 0.0, 0.0, 1.0);
m_col = vec4(0.0, 1.0, 0.0, 1.0);
h_col = vec4(0.0, 0.0, 1.0, 1.0);*/
// From Low to medium
float factor = distance * 0.02;
factor = pow(factor, 2.5);
factor = clamp(factor, 0.0, 1.0);
vec4 f_col = mix(m_col, l_col, factor);
// From medium to high
factor = distance * 0.1;
factor = pow(factor, 2.5);
factor = clamp(factor, 0.0, 1.0);
f_col = mix(h_col, f_col, factor);
return f_col;
}
vec4 sampleTextureLayer1(vec2 uv)
{
return texture(tex_layer_1, uv);
@ -21,11 +53,57 @@ vec4 sampleTextureLayer2(vec2 uv)
return texture(tex_layer_2, uv);
}
vec4 multi_sampleTextureLayer2(vec2 uv, float distance)
{
vec4 l_col = sampleTextureLayer2(uv * LOW_SAMPLING);
vec4 m_col = sampleTextureLayer2(uv * MEDIUM_SAMPLING);
vec4 h_col = sampleTextureLayer2(uv * HIGH_SAMPLING);
// From Low to medium
float factor = distance * 0.02;
factor = pow(factor, 2.5);
factor = clamp(factor, 0.0, 1.0);
vec4 f_col = mix(m_col, l_col, factor);
// From medium to high
factor = distance * 0.1;
factor = pow(factor, 2.5);
factor = clamp(factor, 0.0, 1.0);
f_col = mix(h_col, f_col, factor);
return f_col;
}
vec4 sampleTextureLayer3(vec2 uv)
{
return texture(tex_layer_3, uv);
}
vec4 multi_sampleTextureLayer3(vec2 uv, float distance)
{
vec4 l_col = sampleTextureLayer3(uv * LOW_SAMPLING);
vec4 m_col = sampleTextureLayer3(uv * MEDIUM_SAMPLING);
vec4 h_col = sampleTextureLayer3(uv * HIGH_SAMPLING);
// From Low to medium
float factor = distance * 0.02;
factor = pow(factor, 2.5);
factor = clamp(factor, 0.0, 1.0);
vec4 f_col = mix(m_col, l_col, factor);
// From medium to high
factor = distance * 0.1;
factor = pow(factor, 2.5);
factor = clamp(factor, 0.0, 1.0);
f_col = mix(h_col, f_col, factor);
return f_col;
}
vec4 sampleTextureLayer4(vec2 uv)
{
return texture(tex_layer_4, uv);