diff --git a/material.cpp b/material.cpp index f9ee044..8e8edce 100644 --- a/material.cpp +++ b/material.cpp @@ -11,7 +11,7 @@ bool Lambertian::scatter(const Ray& r_in, const hit_record& rec, Color& attenuat 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); + scattered = Ray(rec.p, reflected + fuzz * random_in_unit_sphere()); attenuation = albedo; return (dot(scattered.direction(), rec.normal) > 0); } diff --git a/material.h b/material.h index 109c12e..5b7c2d4 100644 --- a/material.h +++ b/material.h @@ -23,11 +23,12 @@ private: class Metal : public Material { public: - Metal(const Color& a) : albedo(a) {} + Metal(const Color& a, double f) : albedo(a), fuzz(f < 1 ? f : 1) {} virtual bool scatter(const Ray& r_in, const hit_record& rec, Color& attenuation, Ray& scattered) const; private: Color albedo; + double fuzz; }; #endif // MATERIAL_H diff --git a/wtracer.cpp b/wtracer.cpp index 47c72ba..dadeca2 100644 --- a/wtracer.cpp +++ b/wtracer.cpp @@ -45,10 +45,10 @@ int main() { world.add(std::make_shared(Point3(0, -100.5, -1), 100));*/ world.add(std::make_shared(Point3(0, 0, -1), 0.5, std::make_shared(Color(0.7, 0.3, 0.3)))); - world.add(std::make_shared(Point3(0, -100.5, -1), 100, std::make_shared(Color(0.8, 0.8, 0.8)))); + world.add(std::make_shared(Point3(0, -100.5, -1), 100, std::make_shared(Color(0.8, 0.8, 0.0)))); - world.add(std::make_shared(Point3(1, 0, -1), 0.5, std::make_shared(Color(0.8, 0.6, 0.2)))); - world.add(std::make_shared(Point3(-1, 0, -1), 0.5, std::make_shared(Color(0.8, 0.8, 0.8)))); + world.add(std::make_shared(Point3(1, 0, -1), 0.5, std::make_shared(Color(0.8, 0.6, 0.2), 0.3))); + world.add(std::make_shared(Point3(-1, 0, -1), 0.5, std::make_shared(Color(0.8, 0.8, 0.8), 1.0))); Camera cam;