diff --git a/assets/shaders/terrain.frag.glsl b/assets/shaders/terrain.frag.glsl index 36203be2..ed6d8273 100644 --- a/assets/shaders/terrain.frag.glsl +++ b/assets/shaders/terrain.frag.glsl @@ -96,7 +96,9 @@ void main() { // Bump strength controls how much texture detail affects lighting const float bumpStrength = 9.0; vec3 perturbation = (dLdx * cross(norm, dpdy) + dLdy * cross(dpdx, norm)) * bumpStrength; - norm = normalize(norm - perturbation); + vec3 candidate = norm - perturbation; + float len2 = dot(candidate, candidate); + norm = (len2 > 1e-8) ? candidate * inversesqrt(len2) : norm; } vec3 lightDir2 = normalize(-lightDir.xyz); diff --git a/assets/shaders/terrain.frag.spv b/assets/shaders/terrain.frag.spv index 5318d52d..b633e01b 100644 Binary files a/assets/shaders/terrain.frag.spv and b/assets/shaders/terrain.frag.spv differ diff --git a/src/pipeline/adt_loader.cpp b/src/pipeline/adt_loader.cpp index 755d0596..af3da5ce 100644 --- a/src/pipeline/adt_loader.cpp +++ b/src/pipeline/adt_loader.cpp @@ -13,25 +13,13 @@ float HeightMap::getHeight(int x, int y) const { return 0.0f; } - // WoW uses 9x9 outer + 8x8 inner vertex layout - // Outer vertices: 0-80 (9x9 grid) - // Inner vertices: 81-144 (8x8 grid between outer vertices) - - // Calculate index based on vertex type - int index; - if (x < 9 && y < 9) { - // Outer vertex - index = y * 9 + x; - } else { - // Inner vertex (between outer vertices) - int innerX = x - 1; - int innerY = y - 1; - if (innerX >= 0 && innerX < 8 && innerY >= 0 && innerY < 8) { - index = 81 + innerY * 8 + innerX; - } else { - return 0.0f; - } - } + // MCVT heights are stored in interleaved 9x17 row-major layout: + // Row 0: 9 outer (indices 0-8), then 8 inner (indices 9-16) + // Row 1: 9 outer (indices 17-25), then 8 inner (indices 26-33) + // ... + // Outer vertex (x, y) is at index: y * 17 + x + int index = y * 17 + x; + if (index < 0 || index >= 145) return 0.0f; return heights[index]; }