diff options
| author | ladevieq <ladevie.quentin@gmail.com> | 2020-12-21 13:51:18 +0100 |
|---|---|---|
| committer | ladevieq <ladevie.quentin@gmail.com> | 2020-12-21 13:51:18 +0100 |
| commit | 56bed8e38f5b6d9effd77371ad781ae71601205b (patch) | |
| tree | 1f57155b8f5b15fd2b33ac7e926e3e5d0ce1754c /src/metal.cpp | |
| parent | 92d66138f53645f3400f633c9821a6fa36f589e0 (diff) | |
Add lambertian and metallic materials
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); +} |
