aboutsummaryrefslogtreecommitdiffstats
path: root/src/lambertian.cpp
diff options
context:
space:
mode:
authorladevieq <ladevie.quentin@gmail.com>2020-12-21 13:51:18 +0100
committerladevieq <ladevie.quentin@gmail.com>2020-12-21 13:51:18 +0100
commit56bed8e38f5b6d9effd77371ad781ae71601205b (patch)
tree1f57155b8f5b15fd2b33ac7e926e3e5d0ce1754c /src/lambertian.cpp
parent92d66138f53645f3400f633c9821a6fa36f589e0 (diff)
Add lambertian and metallic materials
Diffstat (limited to 'src/lambertian.cpp')
-rw-r--r--src/lambertian.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/lambertian.cpp b/src/lambertian.cpp
new file mode 100644
index 0000000..16ab146
--- /dev/null
+++ b/src/lambertian.cpp
@@ -0,0 +1,18 @@
+#include "lambertian.hpp"
+#include "hittable.hpp"
+
+lambertian::lambertian(const color& albedo) : albedo(albedo) {}
+
+bool lambertian::scatter(const ray& r, const struct hit_info& info, color& attenuation, ray& scattered) const {
+ // auto scatter_direction = info.normal + random_in_unit_sphere();
+ // auto scatter_direction = info.normal + random_unit_vector();
+ auto scatter_direction = info.normal + random_in_hemisphere(info.normal);
+
+ if (scatter_direction.near_zero()) {
+ scatter_direction = info.normal;
+ }
+
+ scattered = ray { info.point, scatter_direction };
+ attenuation = albedo;
+ return true;
+}