Skip to content

Commit

Permalink
rename Lens -> Camera in straggling places
Browse files Browse the repository at this point in the history
  • Loading branch information
ashpil committed Dec 8, 2024
1 parent 8be083e commit 2527340
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/bin/hydra/hydra.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/bin/offline.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
34 changes: 17 additions & 17 deletions src/bin/online.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/hrtsystem/CameraManager.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib/hrtsystem/ObjectPicker.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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 });
Expand Down
6 changes: 3 additions & 3 deletions src/lib/hrtsystem/pipeline.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
},
Expand All @@ -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,
},
Expand Down
2 changes: 1 addition & 1 deletion src/lib/tests.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2527340

Please sign in to comment.