diff options
Diffstat (limited to 'src/metal.cpp')
| -rw-r--r-- | src/metal.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/metal.cpp b/src/metal.cpp new file mode 100644 index 0000000..d02a2f7 --- /dev/null +++ b/src/metal.cpp @@ -0,0 +1,14 @@ +#include "metal.hpp" +#include "hittable.hpp" +#include "vec3.hpp" + +metal::metal(const color& albedo, double f) + : albedo(albedo), fuzz(f < 1 ? f : 1) {} + +bool metal::scatter(const ray& r, const struct hit_info& info, color& attenuation, ray& scattered) const { + auto reflected = reflect(r.direction, info.normal).unit(); + + scattered = ray { info.point, reflected + fuzz * random_in_unit_sphere() }; + attenuation = albedo; + return (scattered.direction.dot(info.normal) > 0.0); +} |
