48 lines
No EOL
1.1 KiB
GLSL
48 lines
No EOL
1.1 KiB
GLSL
#version 330
|
|
|
|
out vec4 outputColor;
|
|
|
|
uniform vec3 viewPos;
|
|
uniform sampler2D texture0;
|
|
|
|
in vec4 FarColor;
|
|
in vec3 FragPos;
|
|
in vec2 TexCoord;
|
|
in vec4 TexType;
|
|
in float RealType;
|
|
|
|
void main()
|
|
{
|
|
float tileSize = 64.0 / 512.0;
|
|
|
|
float baseWeight = 0.2;
|
|
float dominantWeight = 0.4;
|
|
|
|
vec4 weights = vec4(baseWeight);
|
|
vec2 uvOffsets[4];
|
|
for (int i = 0; i < 4; i++) {
|
|
float type = TexType[i];
|
|
uvOffsets[i] = vec2(mod(type, 8.0), floor(type / 8.0)) * tileSize;
|
|
if (type == RealType) {
|
|
weights[i] = dominantWeight;
|
|
}
|
|
}
|
|
|
|
vec4 blendedColor[4];
|
|
for (int i = 0; i < 4; i++) {
|
|
vec2 uv = TexCoord * tileSize + uvOffsets[i];
|
|
blendedColor[i] = texture(texture0, uv);
|
|
}
|
|
|
|
float weightX = TexCoord.x;
|
|
float weightY = TexCoord.y;
|
|
|
|
vec4 mix1 = mix(blendedColor[0], blendedColor[2], weightX);
|
|
vec4 mix2 = mix(blendedColor[1], blendedColor[3], weightX);
|
|
vec4 finalColor = mix(mix1, mix2, weightY);
|
|
|
|
|
|
float distance = length(viewPos - FragPos);
|
|
float interpolationFactor = clamp(distance / 1000.0, 0.0, 1.0);
|
|
outputColor = mix(finalColor, FarColor, interpolationFactor);
|
|
} |