latest update
This commit is contained in:
@@ -1,13 +1,30 @@
|
||||
use crate::hittable::HitRecord;
|
||||
use crate::ray::Ray;
|
||||
use crate::rtweekend::*;
|
||||
use crate::hittable_list::*;
|
||||
use crate::vec3::Color;
|
||||
use crate::ray::{Ray, self};
|
||||
use crate::vec3::{Color, random_unit_vector};
|
||||
|
||||
pub struct Material {
|
||||
|
||||
}
|
||||
|
||||
trait Scatter {
|
||||
fn scatter(r_in: &Ray, rec: HitRecord, attenuation: &Color, scattered: &Ray) -> bool;
|
||||
fn scatter(&self, r_in: &Ray, rec: HitRecord, attenuation: &mut Color, scattered: &mut Ray) -> bool;
|
||||
}
|
||||
|
||||
pub struct Lambertian {
|
||||
albedo: Color,
|
||||
}
|
||||
|
||||
impl Lambertian {
|
||||
pub fn new(a: &Color) -> Self {
|
||||
Lambertian { albedo: *a }
|
||||
}
|
||||
}
|
||||
|
||||
impl Scatter for Lambertian {
|
||||
fn scatter(&self, r_in: &Ray, rec: HitRecord, attenuation: &mut Color, scattered: &mut Ray) -> bool {
|
||||
let scatter_direction = rec.normal + random_unit_vector();
|
||||
scattered = &mut Ray::new(rec.p, scatter_direction);
|
||||
attenuation = &mut self.albedo;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user