From 31e5526b1476e096fc44bfb576ebf1a59784ea8f Mon Sep 17 00:00:00 2001 From: IntegratedQuantum Date: Tue, 12 Sep 2023 18:36:13 +0200 Subject: [PATCH] Fix fog when the world isn't fully loaded. --- src/chunk.zig | 2 +- src/renderer.zig | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/chunk.zig b/src/chunk.zig index 2c0a5151..2be4b7b2 100644 --- a/src/chunk.zig +++ b/src/chunk.zig @@ -876,7 +876,7 @@ pub const meshing = struct { }; } - pub fn uploadDataAndFinishNeighbors(self: *ChunkMesh) !void { // TODO: The way neighboring chunks are handled doesn't work well with transparency. + pub fn uploadDataAndFinishNeighbors(self: *ChunkMesh) !void { std.debug.assert(!self.mutex.tryLock()); // The mutex should be locked when calling this function. const chunk = self.chunk.load(.Monotonic) orelse return; // In the mean-time the mesh was discarded and recreated and all the data was lost. self.opaqueMesh.resetToCore(); diff --git a/src/renderer.zig b/src/renderer.zig index 0de51e63..c5953201 100644 --- a/src/renderer.zig +++ b/src/renderer.zig @@ -215,7 +215,7 @@ pub fn renderWorld(world: *World, ambientLight: Vec3f, skyColor: Vec3f, playerPo // Meshes.emissionTextureArray.bind(); // } - const playerBlock = RenderStructure.getBlock(@intFromFloat(@floor(playerPos[0])), @intFromFloat(@floor(playerPos[1])), @intFromFloat(@floor(playerPos[2]))) orelse blocks.Block{.typ = 0, .data = 0}; + const playerBlock = RenderStructure.getBlockFromAnyLod(@intFromFloat(@floor(playerPos[0])), @intFromFloat(@floor(playerPos[1])), @intFromFloat(@floor(playerPos[2]))); if(settings.bloom) { Bloom.render(lastWidth, lastHeight, playerBlock); @@ -915,6 +915,16 @@ pub const RenderStructure = struct { return block; } + pub fn getBlockFromAnyLod(x: i32, y: i32, z: i32) blocks.Block { + var lod: u5 = 0; + while(lod < settings.highestLOD) : (lod += 1) { + const node = RenderStructure._getNode(.{.wx = x, .wy = y, .wz = z, .voxelSize=@as(u31, 1) << lod}) orelse continue; + const block = (node.mesh.chunk.load(.Monotonic) orelse continue).getBlock(x & chunk.chunkMask<