ft: 10: metals
This commit is contained in:
@@ -20,10 +20,7 @@ pub struct Camera {
|
||||
}
|
||||
|
||||
impl Camera {
|
||||
pub fn new(aspect_ratio: f32, image_width: u32) -> Camera {
|
||||
Camera::new_aa(aspect_ratio, image_width, 1)
|
||||
}
|
||||
pub fn new_aa(aspect_ratio: f32, image_width: u32, anti_alias_rate: u32) -> Camera {
|
||||
pub fn new(aspect_ratio: f32, image_width: u32, anti_alias_rate: u32, max_depth: u32) -> Self {
|
||||
let image_height = max(1, (image_width as f32 / aspect_ratio) as u32);
|
||||
|
||||
//camera
|
||||
@@ -42,11 +39,11 @@ impl Camera {
|
||||
let pixel00_loc =
|
||||
camera_center - Vec3::new(0., 0., focal_length) - viewport_u / 2 - viewport_v / 2;
|
||||
|
||||
Camera {
|
||||
Self {
|
||||
image_width: image_width,
|
||||
image_height: image_height,
|
||||
anti_alias_rate: anti_alias_rate,
|
||||
max_depth: 50,
|
||||
max_depth: max_depth,
|
||||
center: camera_center,
|
||||
pixel00_loc: pixel00_loc,
|
||||
pixel_delta_u: pixel_delta_u,
|
||||
@@ -93,8 +90,10 @@ impl Camera {
|
||||
|
||||
let closest = Hit::hit_list(hittables, r);
|
||||
if let Some(hit) = closest {
|
||||
let dir = *hit.n() + Vec3::random_unit_hemisphere(hit.n());
|
||||
return 0.5 * self.ray_colour(hittables, &Ray::new(*hit.p(), dir), depth - 1);
|
||||
if let Some((scattered, att)) = hit.mat().scatter(&hit, r) {
|
||||
return att * self.ray_colour(hittables, &scattered, depth - 1);
|
||||
}
|
||||
return Colour::nil();
|
||||
}
|
||||
|
||||
// background
|
||||
|
||||
Reference in New Issue
Block a user