18 lines
704 B
C++
18 lines
704 B
C++
#include "material.h"
|
|
|
|
bool Lambertian::scatter(const Ray& r_in, const hit_record& rec, Color& attenuation, Ray& scattered) const {
|
|
//Vec3 scatter_direction = rec.normal + random_in_unit_sphere();
|
|
Vec3 scatter_direction = rec.normal + random_unit_vector();
|
|
//Vec3 scatter_direction = random_in_hemisphere(rec.normal);
|
|
scattered = Ray(rec.p, scatter_direction);
|
|
attenuation = albedo;
|
|
return true;
|
|
}
|
|
|
|
bool Metal::scatter(const Ray& r_in, const hit_record& rec, Color& attenuation, Ray& scattered) const {
|
|
Vec3 reflected = reflect(unit_vector(r_in.direction()), rec.normal);
|
|
scattered = Ray(rec.p, reflected);
|
|
attenuation = albedo;
|
|
return (dot(scattered.direction(), rec.normal) > 0);
|
|
}
|