Implemented depth buffering

This commit is contained in:
Lorenzo Torres 2025-08-10 14:40:23 +02:00
parent 09799eaa9b
commit 444a4586ea
6 changed files with 154 additions and 20 deletions

View file

@ -67,6 +67,14 @@ pub fn init(allocator: Allocator, instance_handle: vk.c.VkInstance, surface_hand
graphics_pipeline.point_lights[0].diffuse = .{0.5, 0.5, 0.5};
graphics_pipeline.point_lights[0].specular = .{1.0, 1.0, 1.0};
graphics_pipeline.point_lights[1].position = .{-1.0, 1.0, 0.0};
graphics_pipeline.point_lights[1].data[0] = 1.0;
graphics_pipeline.point_lights[1].data[1] = 0.9;
graphics_pipeline.point_lights[1].data[2] = 0.8;
graphics_pipeline.point_lights[1].ambient = .{0.2, 0.2, 0.2};
graphics_pipeline.point_lights[1].diffuse = .{0.5, 0.5, 0.5};
graphics_pipeline.point_lights[1].specular = .{1.0, 1.0, 1.0};
return Renderer{
.instance = instance,
.surface = surface,
@ -76,8 +84,8 @@ pub fn init(allocator: Allocator, instance_handle: vk.c.VkInstance, surface_hand
.swapchain = swapchain,
.graphics_pipeline = graphics_pipeline,
.current_frame = 0,
.transform = math.Transform.init(.{1.0, 0.0, 0.0}, .{0.5, 0.5, 0.5}, .{0.0, 0.0, 0.0}),
.transform2 = math.Transform.init(.{-1.0, 0.0, 0.0}, .{0.5, 0.5, 0.5}, .{0.0, 0.0, 0.0}),
.transform = math.Transform.init(.{0.0, 0.0, -1.0}, .{0.5, 0.5, 0.5}, .{0.0, 0.0, 0.0}),
.transform2 = math.Transform.init(.{0.0, 0.0, 0.0}, .{0.5, 0.5, 0.5}, .{0.0, 0.0, 0.0}),
.previous_time = try std.time.Instant.now(),
.mesh = mesh,
};
@ -109,11 +117,12 @@ pub fn render(pool: *ecs.Pool) anyerror!void {
view_pos[1] = camera.position[1];
view_pos[2] = camera.position[2];
renderer.transform.rotate(math.rad(15) * delta_time, .{0.0, 1.0, 0.0});
renderer.transform2.rotate(math.rad(-15) * delta_time, .{0.0, 1.0, 0.0});
_ = delta_time;
//renderer.transform.rotate(math.rad(15) * delta_time, .{0.0, 1.0, 0.0});
//renderer.transform2.rotate(math.rad(-15) * delta_time, .{0.0, 1.0, 0.0});
renderer.transform.rotate(math.rad(15) * delta_time, .{1.0, 0.0, 0.0});
renderer.transform2.rotate(math.rad(-15) * delta_time, .{1.0, 0.0, 0.0});
//renderer.transform.rotate(math.rad(15) * delta_time, .{1.0, 0.0, 0.0});
//renderer.transform2.rotate(math.rad(-15) * delta_time, .{1.0, 0.0, 0.0});
const transform_memory = renderer.graphics_pipeline.transform_buffer.mapped_memory;
transform_memory[0] = renderer.transform;
@ -128,7 +137,7 @@ pub fn render(pool: *ecs.Pool) anyerror!void {
renderer.device.bindVertexBuffer(renderer.graphics_pipeline.vertex_buffer, renderer.current_frame);
renderer.device.bindIndexBuffer(renderer.graphics_pipeline.index_buffer, renderer.current_frame);
renderer.device.bindDescriptorSets(renderer.graphics_pipeline, renderer.current_frame, 0);
var lights: u32 = 1;
var lights: u32 = 2;
renderer.device.pushConstant(renderer.graphics_pipeline, c.VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4, @ptrCast(&lights), renderer.current_frame);
var transform: u32 = 0;
renderer.device.pushConstant(renderer.graphics_pipeline, c.VK_SHADER_STAGE_VERTEX_BIT, 4, 4, @ptrCast(&transform), renderer.current_frame);