From 252734060cdb3f005a8f0471b769b7d401fc95e9 Mon Sep 17 00:00:00 2001 From: ashpil Date: Sun, 8 Dec 2024 13:45:59 -0800 Subject: [PATCH] rename Lens -> Camera in straggling places --- src/bin/hydra/hydra.zig | 4 ++-- src/bin/offline.zig | 2 +- src/bin/online.zig | 34 ++++++++++++++--------------- src/lib/hrtsystem/CameraManager.zig | 4 ++-- src/lib/hrtsystem/ObjectPicker.zig | 4 ++-- src/lib/hrtsystem/pipeline.zig | 6 ++--- src/lib/tests.zig | 2 +- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/src/bin/hydra/hydra.zig b/src/bin/hydra/hydra.zig index f3d463c..568394b 100644 --- a/src/bin/hydra/hydra.zig +++ b/src/bin/hydra/hydra.zig @@ -151,7 +151,7 @@ pub const HdMoonshine = struct { return self; } - pub export fn HdMoonshineRender(self: *HdMoonshine, sensor: Camera.SensorHandle, lens: Camera.CameraHandle) bool { + pub export fn HdMoonshineRender(self: *HdMoonshine, sensor: Camera.SensorHandle, camera: Camera.CameraHandle) bool { self.mutex.lock(); defer self.mutex.unlock(); self.encoder.begin() catch return false; @@ -347,7 +347,7 @@ pub const HdMoonshine = struct { self.pipeline.recordPushDescriptors(self.encoder.buffer, (Scene { .background = self.background, .camera = self.camera, .world = self.world }).pushDescriptors(sensor, 0)); // push our stuff - self.pipeline.recordPushConstants(self.encoder.buffer, .{ .lens = self.camera.cameras.items[lens][1], .aspect_ratio = self.camera.sensors.items[sensor].aspectRatio(), .sample_count = self.camera.sensors.items[sensor].sample_count }); + self.pipeline.recordPushConstants(self.encoder.buffer, .{ .camera = self.camera.cameras.items[camera][1], .aspect_ratio = self.camera.sensors.items[sensor].aspectRatio(), .sample_count = self.camera.sensors.items[sensor].sample_count }); // trace our stuff self.pipeline.recordTraceRays(self.encoder.buffer, self.camera.sensors.items[sensor].extent); diff --git a/src/bin/offline.zig b/src/bin/offline.zig index b767ec1..0808d2a 100644 --- a/src/bin/offline.zig +++ b/src/bin/offline.zig @@ -129,7 +129,7 @@ pub fn main() !void { for (0..config.spp) |sample_count| { // push our stuff - pipeline.recordPushConstants(encoder.buffer, .{ .lens = scene.camera.cameras.items[0][1], .aspect_ratio = scene.camera.sensors.items[0].aspectRatio(), .sample_count = scene.camera.sensors.items[0].sample_count }); + pipeline.recordPushConstants(encoder.buffer, .{ .camera = scene.camera.cameras.items[0][1], .aspect_ratio = scene.camera.sensors.items[0].aspectRatio(), .sample_count = scene.camera.sensors.items[0].sample_count }); // trace our stuff pipeline.recordTraceRays(encoder.buffer, scene.camera.sensors.items[0].extent); diff --git a/src/bin/online.zig b/src/bin/online.zig index 27ae817..054537b 100644 --- a/src/bin/online.zig +++ b/src/bin/online.zig @@ -137,7 +137,7 @@ const Integrator = struct { // push some stuff integrator.recordPushDescriptors(encoder.buffer, scene.pushDescriptors(active_sensor, 0)); - integrator.recordPushConstants(encoder.buffer, .{ .lens = scene.camera.cameras.items[active_camera][1], .aspect_ratio = scene.camera.sensors.items[active_sensor].aspectRatio(), .sample_count = scene.camera.sensors.items[active_sensor].sample_count }); + integrator.recordPushConstants(encoder.buffer, .{ .camera = scene.camera.cameras.items[active_camera][1], .aspect_ratio = scene.camera.sensors.items[active_sensor].aspectRatio(), .sample_count = scene.camera.sensors.items[active_sensor].sample_count }); // trace some stuff integrator.recordTraceRays(encoder.buffer, scene.camera.sensors.items[active_sensor].extent); @@ -412,26 +412,26 @@ pub fn main() !void { } } if (!imgui.getIO().WantCaptureKeyboard) { - const old_lens = scene.camera.cameras.items[active_camera][1]; - var new_lens = scene.camera.cameras.items[active_camera][1]; + const old_camera = scene.camera.cameras.items[active_camera][1]; + var new_camera = scene.camera.cameras.items[active_camera][1]; - const left = old_lens.transform.mulVector(F32x3.new(0, -1, 0)); - const forward = old_lens.transform.mulVector(F32x3.new(1, 0, 0)); - const origin = old_lens.transform.extractTranslation(); + const left = old_camera.transform.mulVector(F32x3.new(0, -1, 0)); + const forward = old_camera.transform.mulVector(F32x3.new(1, 0, 0)); + const origin = old_camera.transform.extractTranslation(); const speed = imgui.getIO().DeltaTime; - if (imgui.isKeyDown(.w)) new_lens.transform = new_lens.transform.withTranslation(origin.add(forward.scale(speed * 30))); - if (imgui.isKeyDown(.s)) new_lens.transform = new_lens.transform.withTranslation(origin.sub(forward.scale(speed * 30))); - if (imgui.isKeyDown(.a)) new_lens.transform = new_lens.transform.withTranslation(origin.add(left.scale(speed * 30))); - if (imgui.isKeyDown(.d)) new_lens.transform = new_lens.transform.withTranslation(origin.sub(left.scale(speed * 30))); - if (imgui.isKeyDown(.f) and new_lens.thin_lens.aperture > 0.0) new_lens.thin_lens.aperture -= speed / 10; - if (imgui.isKeyDown(.r)) new_lens.thin_lens.aperture += speed / 10; - if (imgui.isKeyDown(.q)) new_lens.thin_lens.focus_distance -= speed * 10; - if (imgui.isKeyDown(.e)) new_lens.thin_lens.focus_distance += speed * 10; - - if (!std.meta.eql(new_lens, old_lens)) { - scene.camera.cameras.items[active_camera][1] = new_lens; + if (imgui.isKeyDown(.w)) new_camera.transform = new_camera.transform.withTranslation(origin.add(forward.scale(speed * 30))); + if (imgui.isKeyDown(.s)) new_camera.transform = new_camera.transform.withTranslation(origin.sub(forward.scale(speed * 30))); + if (imgui.isKeyDown(.a)) new_camera.transform = new_camera.transform.withTranslation(origin.add(left.scale(speed * 30))); + if (imgui.isKeyDown(.d)) new_camera.transform = new_camera.transform.withTranslation(origin.sub(left.scale(speed * 30))); + if (imgui.isKeyDown(.f) and new_camera.thin_lens.aperture > 0.0) new_camera.thin_lens.aperture -= speed / 10; + if (imgui.isKeyDown(.r)) new_camera.thin_lens.aperture += speed / 10; + if (imgui.isKeyDown(.q)) new_camera.thin_lens.focus_distance -= speed * 10; + if (imgui.isKeyDown(.e)) new_camera.thin_lens.focus_distance += speed * 10; + + if (!std.meta.eql(new_camera, old_camera)) { + scene.camera.cameras.items[active_camera][1] = new_camera; scene.camera.sensors.items[active_sensor].clear(); } } diff --git a/src/lib/hrtsystem/CameraManager.zig b/src/lib/hrtsystem/CameraManager.zig index 12b159d..2489a99 100644 --- a/src/lib/hrtsystem/CameraManager.zig +++ b/src/lib/hrtsystem/CameraManager.zig @@ -51,8 +51,8 @@ pub fn appendSensor(self: *Self, vc: *const VulkanContext, allocator: std.mem.Al } pub const CameraHandle = u32; -pub fn appendCamera(self: *Self, allocator: std.mem.Allocator, lens: Camera, name: [:0]const u8) !CameraHandle { - try self.cameras.append(allocator, .{name, lens}); +pub fn appendCamera(self: *Self, allocator: std.mem.Allocator, camera: Camera, name: [:0]const u8) !CameraHandle { + try self.cameras.append(allocator, .{name, camera}); return @intCast(self.cameras.items.len - 1); } diff --git a/src/lib/hrtsystem/ObjectPicker.zig b/src/lib/hrtsystem/ObjectPicker.zig index ad5878c..6bdb361 100644 --- a/src/lib/hrtsystem/ObjectPicker.zig +++ b/src/lib/hrtsystem/ObjectPicker.zig @@ -73,7 +73,7 @@ pub fn create(vc: *const VulkanContext, allocator: std.mem.Allocator, transfer_e }; } -pub fn getClickedObject(self: *Self, vc: *const VulkanContext, accel: vk.AccelerationStructureKHR, normalized_coords: F32x2, lens: Camera.Camera, sensor: Sensor) !?ClickedObject { +pub fn getClickedObject(self: *Self, vc: *const VulkanContext, accel: vk.AccelerationStructureKHR, normalized_coords: F32x2, camera: Camera.Camera, sensor: Sensor) !?ClickedObject { // begin try self.encoder.begin(); @@ -85,7 +85,7 @@ pub fn getClickedObject(self: *Self, vc: *const VulkanContext, accel: vk.Acceler .click_data = self.buffer.handle, }); - self.pipeline.recordPushConstants(self.encoder.buffer, .{ .lens = lens, .aspect_ratio = sensor.aspectRatio(), .click_position = normalized_coords }); + self.pipeline.recordPushConstants(self.encoder.buffer, .{ .camera = camera, .aspect_ratio = sensor.aspectRatio(), .click_position = normalized_coords }); // trace rays self.pipeline.recordTraceRays(self.encoder.buffer, vk.Extent2D { .width = 1, .height = 1 }); diff --git a/src/lib/hrtsystem/pipeline.zig b/src/lib/hrtsystem/pipeline.zig index b7f6837..0323006 100644 --- a/src/lib/hrtsystem/pipeline.zig +++ b/src/lib/hrtsystem/pipeline.zig @@ -255,7 +255,7 @@ pub fn Pipeline(comptime options: struct { pub const ObjectPickPipeline = Pipeline(.{ .shader_path = "hrtsystem/input.hlsl", .PushConstants = extern struct { - lens: Camera.Camera, + camera: Camera.Camera, aspect_ratio: f32, click_position: F32x2, }, @@ -295,7 +295,7 @@ pub const PathTracing = Pipeline(.{ mesh_samples_per_bounce: u32 = 1, }, .PushConstants = extern struct { - lens: Camera.Camera, + camera: Camera.Camera, aspect_ratio: f32, sample_count: u32, }, @@ -317,7 +317,7 @@ pub const DirectLighting = Pipeline(.{ brdf_samples: u32 = 1, }, .PushConstants = extern struct { - lens: Camera.Camera, + camera: Camera.Camera, aspect_ratio: f32, sample_count: u32, }, diff --git a/src/lib/tests.zig b/src/lib/tests.zig index 470848a..b9f5f99 100644 --- a/src/lib/tests.zig +++ b/src/lib/tests.zig @@ -64,7 +64,7 @@ const TestingContext = struct { for (0..spp) |sample_count| { // push our stuff - pipeline.recordPushConstants(self.encoder.buffer, .{ .lens = scene.camera.cameras.items[0][1], .aspect_ratio = scene.camera.sensors.items[0].aspectRatio(), .sample_count = scene.camera.sensors.items[0].sample_count }); + pipeline.recordPushConstants(self.encoder.buffer, .{ .camera = scene.camera.cameras.items[0][1], .aspect_ratio = scene.camera.sensors.items[0].aspectRatio(), .sample_count = scene.camera.sensors.items[0].sample_count }); // trace our stuff pipeline.recordTraceRays(self.encoder.buffer, scene.camera.sensors.items[0].extent);