Introduce depth buffer finally

This commit is contained in:
2025-11-28 01:09:31 +01:00
parent d1f6679f42
commit 652e5e82bd
3 changed files with 109 additions and 10 deletions

View File

@@ -441,6 +441,17 @@ pub fn init(allocator: std.mem.Allocator, engine: *Engine, swapchain: *Swapchain
.alpha_to_coverage_enable = .false,
.alpha_to_one_enable = .false,
},
.depth_stencil_state = .{
.depth_test_enable = .true,
.depth_write_enable = .true,
.depth_compare_op = .greater,
.depth_bounds_test_enable = .false,
.stencil_test_enable = .false,
.front = undefined,
.back = undefined,
.min_depth_bounds = 0,
.max_depth_bounds = 1,
},
.color_blend_state = .{
.logic_op_enable = .false,
.logic_op = .copy,
@@ -639,10 +650,10 @@ pub fn init(allocator: std.mem.Allocator, engine: *Engine, swapchain: *Swapchain
});
const object_count: u32 = blk: {
var objects: std.ArrayList(ObjectUniforms) = try .initCapacity(allocator, 289);
var objects: std.ArrayList(ObjectUniforms) = try .initCapacity(allocator, 578);
defer objects.deinit(allocator);
var it = Iterator3.init(.init(-8, -8, 0), .init(8, 8, 0), .one);
var it = Iterator3.init(.init(-8, -8, 0), .init(8, 8, 2), .init(1, 1, 2));
while (it.next()) |pos| {
const material: Materials.Id = @enumFromInt(engine.random.uintLessThan(u16, @intFromEnum(materials.next_id)));
const matrix_os_to_ws = Matrix4x4.initTranslation(pos);
@@ -750,9 +761,9 @@ pub fn update(self: *Game, dt: f32) void {
// zig fmt: off
const matrix_vs_to_cs = Matrix4x4.init(
camera_xscale, 0, 0, 0,
0, 0, camera_near_plane, 1,
0, 0, 0, 1,
0, -camera_yscale, 0, 0,
0, 0, 0, 0,
0, 0, camera_near_plane, 0,
);
// zig fmt: on
@@ -863,7 +874,17 @@ fn render(self: *Game) !void {
try command_buffer.beginCommandBuffer(&.{ .flags = .{ .one_time_submit_bit = true } });
{
const clear_values = [_]vk.ClearValue{
.{ .color = .{ .float_32 = .{ 0, 0, 0, 1 } } },
.{
.color = .{
.float_32 = .{ 0, 0, 0, 0 },
},
},
.{
.depth_stencil = .{
.depth = 0,
.stencil = 0,
},
},
};
command_buffer.beginRenderPass(&.{