1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use crate::{
    HitData,
    random,
    Material,
    Ray, ray,
    Vec3
};



/// Lambertian (diffuse) [`Material`].
///
/// Used for solid shapes that scatter rays in random directions and thus can't reflect their
/// surroundings.
///
/// [`Material`]: trait.Material.html
pub struct Matte {
    /// Defines how much red, green and blue light this material reflects.
    albedo: Vec3
}

impl Matte {
    pub fn new(albedo: Vec3) -> Matte {
        Matte {albedo}
    }
}

impl Material for Matte {
    fn scatter(&self, _: &Ray, hit_data: &HitData) -> (Vec3, Ray) {
        let target = hit_data.point + hit_data.normal + random::point_in_sphere();

        let attenuation = self.albedo;
        let scattered = ray!(hit_data.point, target - hit_data.point);

        (attenuation, scattered)
    }
}