From 7c2cead577f82c0c088d44c99082851fdaff3d18 Mon Sep 17 00:00:00 2001 From: Armin Friedl Date: Sat, 30 Jul 2022 18:28:17 +0200 Subject: [PATCH] Fuzzy reflection --- rtiww/src/main.cpp | 6 +++--- rtiww/src/material.h | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/rtiww/src/main.cpp b/rtiww/src/main.cpp index 11e8e85..4c3cd4b 100644 --- a/rtiww/src/main.cpp +++ b/rtiww/src/main.cpp @@ -46,9 +46,9 @@ int main() { hittable_list world; auto material_ground = make_shared(color(0.8, 0.8, 0.0)); - auto material_center = make_shared(color(0.7, 0.3, 0.3)); - auto material_left = make_shared(color(0.8, 0.8, 0.8)); - auto material_right = make_shared(color(0.8, 0.6, 0.2)); + auto material_center = make_shared(color(0.7, 0.3, 0.3)); + auto material_left = make_shared(color(0.8, 0.8, 0.8), 0.3); + auto material_right = make_shared(color(0.8, 0.6, 0.2), 1.0); world.add(make_shared(point3( 0.0, -100.5, -1.0), 100.0, material_ground)); world.add(make_shared(point3( 0.0, 0.0, -1.0), 0.5, material_center)); diff --git a/rtiww/src/material.h b/rtiww/src/material.h index 34a92c5..7735998 100644 --- a/rtiww/src/material.h +++ b/rtiww/src/material.h @@ -39,19 +39,20 @@ public: 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 override { 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 true; } public: color albedo; + double fuzz; }; #endif // MATERIAL_H_