Grass, debugger, noise height gen

This commit is contained in:
2025-11-30 00:06:04 +01:00
parent b4b4c69ec3
commit 0fbc7f32f2
11 changed files with 131 additions and 18 deletions

View File

@@ -613,6 +613,11 @@ pub fn init(allocator: std.mem.Allocator, engine: *Engine, swapchain: *Swapchain
}
var it = Interator3(i16).init(-10, -10, 0, 9, 9, 0);
const block_grass = blocks.getFilename("Grass.json").?;
const block_dirt = blocks.getFilename("Dirt.json").?;
const block_bedrock = blocks.getFilename("Bedrock.json").?;
while (it.next()) |chunk_coords| {
const origin = Vector3.init(
@floatFromInt(chunk_coords[0]),
@@ -630,9 +635,24 @@ pub fn init(allocator: std.mem.Allocator, engine: *Engine, swapchain: *Swapchain
var it2 = Interator3(usize).init(0, 0, 0, 15, 15, 0);
while (it2.next()) |pos| {
const x, const y, const z = pos;
const block: Blocks.Id = @enumFromInt(engine.random.intRangeLessThan(u12, 1, @intCast(blocks.blocks.items.len)));
chunk.blocks[z][y][x] = block;
const x, const y, _ = pos;
const fpos = Vector3.init(
@floatFromInt(pos[0]),
@floatFromInt(pos[1]),
@floatFromInt(pos[2]),
).add(origin);
const noise = std.math.clamp(math.noise2(fpos.asVector2().divScalar(30)), -1, 1);
const fheight = (0.5 * noise + 0.5) * 4 + 1;
const iheight: u32 = @intFromFloat(@round(fheight));
chunk.blocks[0][y][x] = block_bedrock;
var i: u32 = 0;
while (i < iheight) : (i += 1) {
const iz = i + 1;
const block = if (i + 1 == iheight) block_grass else block_dirt;
chunk.blocks[iz][y][x] = block;
}
}
}
@@ -772,7 +792,7 @@ pub fn update(self: *Game, dt: f32) void {
);
// zig fmt: on
const ambient_light = Vector3.init(0.001, 0.001, 0.001);
const ambient_light = Vector3.init(0.01, 0.01, 0.01);
const global_uniforms_data: GlobalUniforms = .{
.matrixWStoVS = matrix_ws_to_vs.asArray(),