diff --git a/include/material.h b/include/material.h index b7a63dd..03c44ba 100644 --- a/include/material.h +++ b/include/material.h @@ -23,7 +23,7 @@ class lambertian : public material { bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered) const override { auto scatter_direction = rec.normal + random_unit_vector(); - // Catch degenerate scatter direction + if (scatter_direction.near_zero()) scatter_direction = rec.normal; @@ -81,11 +81,10 @@ class dielectric : public material { } private: - // Refractive index in vacuum or air, or the ratio of the material's refractive index over - // the refractive index of the enclosing media + double refraction_index; static double reflectance(double cosine, double refraction_index) { - // Use Schlick's approximation for reflectance. + auto r0 = (1 - refraction_index) / (1 + refraction_index); r0 = r0*r0; return r0 + (1-r0)*std::pow((1 - cosine),5);