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);
}

View File

@@ -82,7 +82,7 @@ void main()
uint faceIndex = gl_VertexID / 6u;
uint vertIndex = gl_VertexID % 6u;
uint start = faceIndex * 2u; // 2 byte per face
uint start = faceIndex * 2u; // 2 uint per face
uint u0 = faces[start]; // data in uint 0
uint u1 = faces[start + 1]; // data in uint 1
@@ -95,7 +95,8 @@ void main()
uint texture = u1 & 0xFFu;
uint lightLevel = (u1 >> 8) & 0xFFu;
vec3 basePos = vec3(x + chunkX * 16, y, z + chunkY * 16);
vec3 basePos = vec3(x, y, z) + vec3(chunkX, 0, chunkY) * 16.0;
vec4 worldPos = vec4(basePos + offsets[facing][vertIndex], 1.0);
float light = float(lightLevel) / 255.0; // use later for caves and stuff