From 6f55253ffd216449cd0a0114104c89a73253be7f Mon Sep 17 00:00:00 2001 From: NADAL Jean-Baptiste Date: Tue, 12 Mar 2024 16:15:53 +0100 Subject: [PATCH] [FEAT] refraction tips7 is now working --- raytracing/src/core/intersection.cpp | 3 ++- raytracing/src/renderer/world.cpp | 2 +- raytracing/src/shapes/sphere.cpp | 16 ++++++++++++++-- tests/07_making_scene.cpp | 6 ------ 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/raytracing/src/core/intersection.cpp b/raytracing/src/core/intersection.cpp index 4948857..9badb03 100644 --- a/raytracing/src/core/intersection.cpp +++ b/raytracing/src/core/intersection.cpp @@ -189,9 +189,10 @@ IntersectionData Intersection::prepare_computations(const Ray &a_ray, Intersecti the_data.set_point(a_ray.position(m_distance_t)); the_data.set_eyev(-a_ray.direction()); the_data.set_normalv(m_shape->normal_at(the_data.point())); + the_data.set_inside(); the_data.set_over_point(the_data.point() + the_data.normalv() * kEpsilon); the_data.set_under_point(the_data.point() - the_data.normalv() * kEpsilon); - the_data.set_inside(); + the_data.set_reflectv(a_ray.direction().reflect(the_data.normalv())); if (a_collection == nullptr) diff --git a/raytracing/src/renderer/world.cpp b/raytracing/src/renderer/world.cpp index 77b90f6..401edff 100644 --- a/raytracing/src/renderer/world.cpp +++ b/raytracing/src/renderer/world.cpp @@ -234,7 +234,7 @@ Color World::refracted_color(const IntersectionData &an_intersection_data, uint3 // Find the color of the refracted ray, making sure to multiply by the transparency value // to account for any opacity - the_color = color_at(the_refracted_ray, a_remaining - 1) * an_intersection_data.object()->material().transparency(); + the_color = color_at(the_refracted_ray, a_remaining - 1) * the_transparency; return the_color; } diff --git a/raytracing/src/shapes/sphere.cpp b/raytracing/src/shapes/sphere.cpp index 32358ee..05b601c 100644 --- a/raytracing/src/shapes/sphere.cpp +++ b/raytracing/src/shapes/sphere.cpp @@ -54,8 +54,20 @@ Intersections Sphere::local_intersect(const Ray &a_ray) if (discriminant >= 0) { double the_sqrt = std::sqrt(discriminant); - the_intersections.add(Intersection((-the_b - the_sqrt) / (2 * the_a), this)); - the_intersections.add(Intersection((-the_b + the_sqrt) / (2 * the_a), this)); + double t1, t2; + t1 = (-the_b - the_sqrt) / (2 * the_a); + t2 = (-the_b + the_sqrt) / (2 * the_a); + + if (t1 < t2) + { + the_intersections.add(Intersection(t1, this)); + the_intersections.add(Intersection(t2, this)); + } + else + { + the_intersections.add(Intersection(t2, this)); + the_intersections.add(Intersection(t1, this)); + } } return the_intersections; diff --git a/tests/07_making_scene.cpp b/tests/07_making_scene.cpp index a2c9ff9..155883a 100644 --- a/tests/07_making_scene.cpp +++ b/tests/07_making_scene.cpp @@ -296,16 +296,10 @@ SCENARIO("Shading an intersection from the inside", "[features/world.feature]") AND_WHEN("c <- shade_hit(w, comps)") { Color c = w.shade_hit(comps); -#if 0 // Not working anymore with shadow. THEN("c = color(0.90498, 0.90498, 0.90498)") { REQUIRE(c == Color(0.90498, 0.90498, 0.90498)); } -#endif - THEN("c = color(0.1, 0.1, 0.1)") - { - REQUIRE(c == Color(0.1, 0.1, 0.1)); - } } } }