toytracer/material.cpp

18 lines
737 B
C++
Raw Normal View History

#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);
2020-06-06 21:28:33 +00:00
scattered = Ray(rec.p, reflected + fuzz * random_in_unit_sphere());
attenuation = albedo;
return (dot(scattered.direction(), rec.normal) > 0);
}