Fuzzy reflection

This commit is contained in:
Armin Friedl 2022-07-30 18:28:17 +02:00
parent 3323b6e292
commit 7c2cead577
2 changed files with 6 additions and 5 deletions

View file

@ -46,9 +46,9 @@ int main() {
hittable_list world; hittable_list world;
auto material_ground = make_shared<lambertian>(color(0.8, 0.8, 0.0)); auto material_ground = make_shared<lambertian>(color(0.8, 0.8, 0.0));
auto material_center = make_shared<metal>(color(0.7, 0.3, 0.3)); auto material_center = make_shared<lambertian>(color(0.7, 0.3, 0.3));
auto material_left = make_shared<metal>(color(0.8, 0.8, 0.8)); auto material_left = make_shared<metal>(color(0.8, 0.8, 0.8), 0.3);
auto material_right = make_shared<metal>(color(0.8, 0.6, 0.2)); auto material_right = make_shared<metal>(color(0.8, 0.6, 0.2), 1.0);
world.add(make_shared<sphere>(point3( 0.0, -100.5, -1.0), 100.0, material_ground)); world.add(make_shared<sphere>(point3( 0.0, -100.5, -1.0), 100.0, material_ground));
world.add(make_shared<sphere>(point3( 0.0, 0.0, -1.0), 0.5, material_center)); world.add(make_shared<sphere>(point3( 0.0, 0.0, -1.0), 0.5, material_center));

View file

@ -39,19 +39,20 @@ public:
class metal : public material { class metal : public material {
public: public:
metal(const color& a) : albedo(a) {} metal(const color& a, double f) : albedo(a), fuzz(f<1 ? f: 1) {}
virtual bool scatter( virtual bool scatter(
const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered
) const override { ) const override {
vec3 reflected = reflect(unit_vector(r_in.direction()), rec.normal); 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; attenuation = albedo;
return true; return true;
} }
public: public:
color albedo; color albedo;
double fuzz;
}; };
#endif // MATERIAL_H_ #endif // MATERIAL_H_