diff options
| author | ladevieq <ladevie.quentin@gmail.com> | 2020-12-22 22:22:04 +0100 |
|---|---|---|
| committer | ladevieq <ladevie.quentin@gmail.com> | 2020-12-22 22:22:04 +0100 |
| commit | 6b6ef77808585713ab1d04f03e970865b7e7ddb8 (patch) | |
| tree | 9b0da6471291ba85d688fbb92a052a96dd85a814 | |
| parent | 8da53c5f262b09756e1a93257cdcd5be25807839 (diff) | |
Fix dielectric materials refraction
| -rw-r--r-- | include/hittable.hpp | 2 | ||||
| -rw-r--r-- | src/main.cpp | 4 | ||||
| -rw-r--r-- | src/sphere.cpp | 2 |
3 files changed, 4 insertions, 4 deletions
diff --git a/include/hittable.hpp b/include/hittable.hpp index aa55034..074de55 100644 --- a/include/hittable.hpp +++ b/include/hittable.hpp @@ -16,7 +16,7 @@ struct hit_info { inline void set_face_normal(const ray& r, const vec3& outward_normal) { front_face = r.direction.dot(outward_normal) < 0.0; - normal = front_face ? outward_normal : -outward_normal; + normal = front_face ? outward_normal : (-outward_normal); } }; diff --git a/src/main.cpp b/src/main.cpp index 92dc01f..41f1280 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -35,7 +35,7 @@ int main() { const uint32_t samples_per_pixel = 100; const uint32_t max_depth = 100; - camera camera { { /*-2.0, 2.0, 1.0*/ }, { 0.0, 0.0, -1.0 }, 90.0, aspect_ratio }; + camera camera { { -2.0, 2.0, 1.0 }, { 0.0, 0.0, -1.0 }, 20.0, aspect_ratio }; // World hittable objects hittable_list world {}; @@ -48,7 +48,7 @@ int main() { world.add(std::make_shared<sphere>(point3( 0.0, -100.5, -1.0), 100.0, material_ground)); world.add(std::make_shared<sphere>(point3( 0.0, 0.0, -1.0), 0.5, material_center)); world.add(std::make_shared<sphere>(point3(-1.0, 0.0, -1.0), 0.5, material_left)); - world.add(std::make_shared<sphere>(point3(-1.0, 0.0, -1.0), -0.4, material_left)); + world.add(std::make_shared<sphere>(point3(-1.0, 0.0, -1.0), -0.49, material_left)); world.add(std::make_shared<sphere>(point3( 1.0, 0.0, -1.0), 0.5, material_right)); // PPM format header diff --git a/src/sphere.cpp b/src/sphere.cpp index 611dc34..e7be715 100644 --- a/src/sphere.cpp +++ b/src/sphere.cpp @@ -32,7 +32,7 @@ bool sphere::hit(const ray& r, double t_min, double t_max, struct hit_info& info info.point = r.at(t); info.mat_ptr = mat_ptr; - vec3 out_normal = (info.point - center).unit(); + vec3 out_normal = (info.point - center) / radius; info.set_face_normal(r, out_normal); return true; |
