ft: tri support

This commit is contained in:
2026-04-30 16:28:16 +02:00
parent 388fbcbb8a
commit 27bdce5882
7 changed files with 204 additions and 12 deletions

View File

@@ -112,7 +112,7 @@ impl Camera {
self.v = self.w.cross(&self.u);
// viewport
let viewport_height = 2. * h * self.focus_dist;
let viewport_height = 2. * h * self.focus_dist;
let viewport_width = viewport_height * (self.image_width as f32 / self.image_height as f32);
let viewport_u = viewport_width * self.u;
let viewport_v = viewport_height * -self.v;
@@ -125,7 +125,7 @@ impl Camera {
self.dirty = false;
if self.defocus_angle != 0. {
let defocus_radius = self.focus_dist * deg_to_rad(self.defocus_angle/2.).tan();
let defocus_radius = self.focus_dist * deg_to_rad(self.defocus_angle / 2.).tan();
self.defocus_disk_u = self.u * defocus_radius;
self.defocus_disk_v = self.v * defocus_radius;
}
@@ -180,7 +180,7 @@ impl Camera {
self.dirty = true;
}
}
fn defocus_disk_sample(&self) -> Vec3 {
let p = Vec3::random_in_unit_disk();
self.look_from + (p.x() * self.defocus_disk_u) + (p.y() * self.defocus_disk_v)
@@ -206,7 +206,11 @@ impl Camera {
let pixel_loc = pixel_tl
+ (x * self.pixel_delta_u / (self.anti_alias_rate + 1) as f32)
+ (y * self.pixel_delta_v / (self.anti_alias_rate + 1) as f32);
let ray_orig = if self.defocus_angle > 0. { self.defocus_disk_sample() } else {self.look_from};
let ray_orig = if self.defocus_angle > 0. {
self.defocus_disk_sample()
} else {
self.look_from
};
let ray_dir = pixel_loc - ray_orig;
let r = Ray::new(ray_orig, ray_dir);
pixel_colour += self.ray_colour(hittables, &r, self.max_depth);
@@ -220,7 +224,7 @@ impl Camera {
}
info!("Writing image file...");
imgbuf.save("output2.png").unwrap();
imgbuf.save("output.png").unwrap();
}
fn ray_colour(&self, hittables: &Vec<Arc<dyn Hittable>>, r: &Ray, depth: u32) -> Colour {