From 12c0a2e3878d72f8cad8487eb0904d8e60cccd5c Mon Sep 17 00:00:00 2001 From: Wander_lust Date: Tue, 17 Feb 2026 02:13:20 +0530 Subject: [PATCH] Refactor scatter method --- include/material.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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);