Fixed negative chunks invisible

This commit is contained in:
max
2025-12-14 23:54:22 +01:00
parent a1cdd6b5de
commit 35ecc36bdb
7 changed files with 118 additions and 40 deletions

View File

@@ -10,16 +10,23 @@ uniform vec3 cameraPosition;
void main()
{
float fogEnd = 512;
float fogStart = 32;
float dist = length(cameraPosition - fragPos);
float fogFactor = (fogEnd - dist) / (fogEnd - fogStart);
fogFactor = clamp(fogFactor, 0, 1);
vec4 fogColor = vec4(0.8,0.8,0.8,1);
vec4 texColor = texture(uTexture, fragUV) * lighting;
vec4 color = mix(fogColor, texColor, fogFactor);
FragColor = vec4(color.rgb, texColor.a);
// Use squared distance
vec3 delta = cameraPosition - fragPos;
float distSq = dot(delta, delta);
// Precomputed fog parameters
const float fogEndSq = 16384.0; // 128^2
const float fogStartSq = 1024.0; // 32^2
const float fogRangeInv = 1.0 / (fogEndSq - fogStartSq);
float fogFactor = (fogEndSq - distSq) * fogRangeInv;
fogFactor = clamp(fogFactor, 0.0, 1.0);
// Texture and lighting
vec4 texColor = texture(uTexture, fragUV);
texColor.rgb *= lighting;
// Fog blend
const vec3 fogColor = vec3(0.8, 0.8, 0.8);
FragColor = vec4(mix(fogColor, texColor.rgb, fogFactor), texColor.a);
}