diff --git a/Makefile b/Makefile index 1f42d88..b5e5e50 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -raytracer: main.cpp vec3.hpp color.hpp ray.hpp hittable.hpp sphere.hpp hittable_list.hpp rtweekend.hpp +raytracer: camera.hpp color.hpp hittable.hpp hittable_list.hpp material.hpp ray.hpp rtweekend.hpp sphere.hpp vec3.hpp @g++ -g -O2 -Wall -Wextra -Wpedantic main.cpp -o raytracer image: raytracer diff --git a/main.cpp b/main.cpp index 4d3e218..c7ca4f0 100644 --- a/main.cpp +++ b/main.cpp @@ -75,8 +75,8 @@ int main() std::shared_ptr material_ground = make_shared(color(0.8, 0.8, 0.0)); std::shared_ptr material_center = make_shared(color(0.7, 0.3, 0.3)); - std::shared_ptr material_left = make_shared(color(0.8, 0.8, 0.8)); - std::shared_ptr material_right = make_shared(color(0.8, 0.6, 0.2)); + std::shared_ptr material_left = make_shared(color(0.8, 0.8, 0.8), 0.3); + std::shared_ptr 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/material.hpp b/material.hpp index 2ff657e..b8f93e8 100644 --- a/material.hpp +++ b/material.hpp @@ -37,13 +37,18 @@ struct lambertian : material { struct metal : material { /* Attributes */ color albedo; + double fuzz; // Constructor - metal(const color& c) { albedo = c; }; + metal(const color& c, double f) + { + albedo = c; + fuzz = f; + }; virtual bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered) const override { vec3 reflected = reflect(normalize(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); }