Add material support

This commit is contained in:
Phireh 2021-08-22 17:24:33 +02:00
commit 58ffcff459
7 changed files with 112 additions and 36 deletions

View file

@ -8,12 +8,14 @@ struct sphere : hittable {
/* Attributes */
point3 center;
double radius;
std::shared_ptr<material> mat_ptr;
/* Contructor */
sphere(point3 c, double r)
sphere(point3 c, double r, std::shared_ptr<material> m)
{
center = c;
radius = r;
mat_ptr = m;
}
/* Virtual methods declaration */
@ -46,6 +48,7 @@ bool sphere::hit(const ray& r, double t_min, double t_max, hit_record& rec) cons
rec.p = r.at(rec.t);
vec3 outward_normal = (rec.p - center) / radius;
rec.set_face_normal(r, outward_normal);
rec.mat_ptr = mat_ptr;
return true;
}