From bd5f92d38a4a7c222c51349632c063c9f2ee62dc Mon Sep 17 00:00:00 2001 From: NADAL Jean-Baptiste Date: Tue, 12 Mar 2024 22:25:57 +0100 Subject: [PATCH] [FEAT] Chapter 11 is done --- tests/11_reflection_refraction.cpp | 60 ++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/tests/11_reflection_refraction.cpp b/tests/11_reflection_refraction.cpp index 485fac2..8c01da5 100644 --- a/tests/11_reflection_refraction.cpp +++ b/tests/11_reflection_refraction.cpp @@ -783,3 +783,63 @@ SCENARIO("The Schlick approximation with a small angle and n2 > n1", "[features/ } } } + +/* ------------------------------------------------------------------------- */ + +SCENARIO("shade_hit() with a reflective, transparent material", "[features/world.feature]") +{ + GIVEN("w <- default_world()") + { + World w = World::default_world(); + AND_GIVEN("r <- ray(point(0, 0, -3), vector(0, -sqrt(2) / 2, sqrt(2) / 2))") + { + Ray r(Tuple::Point(0, 0, -3), Tuple::Vector(0, -sqrt(2) / 2, sqrt(2) / 2)); + AND_GIVEN("floor <- plane() with:") + { + // | transform | translation(0, -1, 0) | + // | material.reflective | 0.5 | + // | material.transparency | 0.5 | + // | material.refractive_index | 1.5 | + Plane floor; + floor.set_transform(Matrix::translation(0, -1, 0)); + floor.material().set_reflective(0.5); + floor.material().set_transparency(0.5); + floor.material().set_refractive_index(1.5); + AND_GIVEN("floor is added to w") + { + w.add_object(&floor); + AND_GIVEN("ball <- sphere() with:") + { + // | material.color | (1, 0, 0) | + // | material.ambient | 0.5 | + // | transform | translation(0, -3.5, -0.5) | + Sphere ball; + ball.material().set_color(Color(1, 0, 0)); + ball.material().set_ambient(0.5); + ball.set_transform(Matrix::translation(0, -3.5, -0.5)); + AND_GIVEN("ball is added to w") + { + w.add_object(&ball); + AND_GIVEN("xs <- intersections(sqrt(2):floor)") + { + Intersections xs = Intersections({Intersection(sqrt(2), &floor)}); + WHEN("comps <- prepare_computations(xs[0], r, xs)") + { + IntersectionData comps = xs[0].prepare_computations(r, &xs); + AND_WHEN("color <- shade_hit(w, comps, 5)") + { + Color color = w.shade_hit(comps, 5); + THEN("color = color(0.93391, 0.69643, 0.69243)") + { + REQUIRE(color == Color(0.93391, 0.69643, 0.69243)); + } + } + } + } + } + } + } + } + } + } +}