[WIP] Test 7 of refraction is in wip
This commit is contained in:
@@ -33,6 +33,19 @@ using namespace Raytracer;
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class TestPattern : public Pattern
|
||||
{
|
||||
public:
|
||||
TestPattern(void) = default;
|
||||
|
||||
const Color pattern_at(const Tuple &a_point) const override
|
||||
{
|
||||
return Color(a_point.x(), a_point.y(), a_point.z());
|
||||
}
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
SCENARIO("Reflectivity for the default material", "[features/materials.feature]")
|
||||
{
|
||||
GIVEN("m <- material()")
|
||||
@@ -349,7 +362,7 @@ SCENARIO("Finding n1 and n2 at various intersections", "[features/intersections.
|
||||
B.material().set_refractive_index(2.0);
|
||||
GIVEN("C <- glass_sphere() with:")
|
||||
// | transform | translation(0, 0, 0.25) |
|
||||
// | material.refractive_index | 2.5 |
|
||||
// | material.refractive_index | 2.5 |
|
||||
{
|
||||
Sphere C = Sphere::Glass();
|
||||
C.set_transform(Matrix::translation(0, 0, 0.25));
|
||||
@@ -405,3 +418,218 @@ SCENARIO("Finding n1 and n2 at various intersections", "[features/intersections.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
SCENARIO("The under point is offset below the surface", "[features/intersections.feature]")
|
||||
{
|
||||
GIVEN("r <- ray(point(0, 0, -5), vector(0, 0, 1)")
|
||||
{
|
||||
Ray r(Tuple::Point(0, 0, -5), Tuple::Vector(0, 0, 1));
|
||||
AND_GIVEN("shape <- glass_sphere() with:")
|
||||
// | transform | translation(0, 0, 1) |
|
||||
{
|
||||
Sphere shape = Sphere::Glass();
|
||||
shape.set_transform(Matrix::translation(0, 0, 1));
|
||||
AND_GIVEN("i <- intersection(5, shape)")
|
||||
{
|
||||
Intersection i(5, &shape);
|
||||
AND_GIVEN("xs <- intersections(i)")
|
||||
{
|
||||
Intersections xs = Intersections({i});
|
||||
WHEN("comps <- prepare_computations(i, r, xs)")
|
||||
{
|
||||
IntersectionData comps = i.prepare_computations(r, &xs);
|
||||
THEN("comps.under_point.z > EPSILON / 2")
|
||||
{
|
||||
REQUIRE(comps.under_point().z() > kEpsilon / 2);
|
||||
}
|
||||
AND_THEN("comps.point.z < comps.under_point.z")
|
||||
{
|
||||
REQUIRE(comps.point().z() < comps.under_point().z());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
SCENARIO("The refracted color with a, opaque surface", "[features/world.feature]")
|
||||
{
|
||||
GIVEN("w <- default_world()")
|
||||
{
|
||||
World w = World::default_world();
|
||||
AND_GIVEN("shape <- first object of w")
|
||||
{
|
||||
Shape *shape = w.objects(0);
|
||||
AND_GIVEN("r <- ray(point(0, 0, -5), vector(0, 0, 1))")
|
||||
{
|
||||
Ray r(Tuple::Point(0, 0, -5), Tuple::Vector(0, 0, 1));
|
||||
AND_GIVEN("xs <- intersections(4:shape, 6:shape)")
|
||||
{
|
||||
Intersections xs = Intersections({Intersection(4.0, shape),
|
||||
Intersection(6.0, shape)});
|
||||
WHEN("comps <- prepare_computations(xs[0], r, xs)")
|
||||
{
|
||||
IntersectionData comps = xs[0].prepare_computations(r, &xs);
|
||||
AND_WHEN("c <- refracted_color(w, comps, 5)")
|
||||
{
|
||||
Color c = w.refracted_color(comps, 5);
|
||||
THEN("c = color(0, 0, 0)")
|
||||
{
|
||||
REQUIRE(c == Color(0, 0, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
SCENARIO("The refracted color at the maximum recursive depth", "[features/world.feature]")
|
||||
{
|
||||
GIVEN("w <- default_world()")
|
||||
{
|
||||
World w = World::default_world();
|
||||
AND_GIVEN("shape <- first object of w")
|
||||
{
|
||||
Shape *shape = w.objects(0);
|
||||
AND_GIVEN("shape has:")
|
||||
{
|
||||
// | material.transparency | 1.0 |
|
||||
// | material.refractive_index | 1.5 |
|
||||
shape->material().set_transparency(1.0);
|
||||
shape->material().set_refractive_index(1.5);
|
||||
AND_GIVEN("r <- ray(point(0, 0, -5), vector(0, 0, 1))")
|
||||
{
|
||||
Ray r(Tuple::Point(0, 0, -5), Tuple::Vector(0, 0, 1));
|
||||
AND_GIVEN("xs <- intersections(4:shape, 6:shape)")
|
||||
{
|
||||
Intersections xs = Intersections({Intersection(4.0, shape),
|
||||
Intersection(6.0, shape)});
|
||||
WHEN("comps <- prepare_computations(xs[0], r, xs)")
|
||||
{
|
||||
IntersectionData comps = xs[0].prepare_computations(r, &xs);
|
||||
AND_WHEN("c <- refracted_color(w, comps, 0)")
|
||||
{
|
||||
Color c = w.refracted_color(comps, 0);
|
||||
THEN("c = color(0, 0, 0)")
|
||||
{
|
||||
REQUIRE(c == Color(0, 0, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
SCENARIO("The refracted color under total internal reflection", "[features/world.feature]")
|
||||
{
|
||||
GIVEN("w <- default_world()")
|
||||
{
|
||||
World w = World::default_world();
|
||||
AND_GIVEN("shape <- first object of w")
|
||||
{
|
||||
Shape *shape = w.objects(0);
|
||||
AND_GIVEN("shape has:")
|
||||
{
|
||||
// | material.transparency | 1.0 |
|
||||
// | material.refractive_index | 1.5 |
|
||||
shape->material().set_transparency(1.0);
|
||||
shape->material().set_refractive_index(1.5);
|
||||
AND_GIVEN("r <- ray(point(0, 0, sqrt(2) / 2), vector(0, 1, 0))")
|
||||
{
|
||||
Ray r(Tuple::Point(0, 0, sqrt(2) / 2), Tuple::Vector(0, 1, 0));
|
||||
AND_GIVEN("xs <- intersections(-(sqrt(2) / 2):shape, sqrt(2) / 2:shape)")
|
||||
{
|
||||
Intersections xs = Intersections({Intersection(-(sqrt(2) / 2), shape),
|
||||
Intersection(sqrt(2) / 2, shape)});
|
||||
// NOTE: this time you're inside the sphere, so you need to look at the
|
||||
// second intersection, xs[1] and not xs[0]
|
||||
WHEN("comps <- prepare_computations(xs[1], r, xs)")
|
||||
{
|
||||
IntersectionData comps = xs[1].prepare_computations(r, &xs);
|
||||
AND_WHEN("c <- refracted_color(w, comps, 5)")
|
||||
{
|
||||
Color c = w.refracted_color(comps, 5);
|
||||
THEN("c = color(0, 0, 0)")
|
||||
{
|
||||
REQUIRE(c == Color(0, 0, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
SCENARIO("The refracted color with a refracted ray", "[features/world.feature]")
|
||||
{
|
||||
GIVEN("w <- default_world()")
|
||||
{
|
||||
World w = World::default_world();
|
||||
AND_GIVEN("A <- first object of w")
|
||||
{
|
||||
Shape *A = w.objects(0);
|
||||
AND_GIVEN("A has:")
|
||||
{
|
||||
// | material.ambient | 1.0 |
|
||||
// | material.pattern | test_pattern() |
|
||||
A->material().set_ambient(1.0);
|
||||
TestPattern the_pattern;
|
||||
A->material().set_pattern(&the_pattern);
|
||||
AND_GIVEN("B <- second object of w")
|
||||
{
|
||||
Shape *B = w.objects(1);
|
||||
AND_GIVEN("shape has:")
|
||||
{
|
||||
// | material.transparency | 1.0 |
|
||||
// | material.refractive_index | 1.5 |
|
||||
B->material().set_transparency(1.0);
|
||||
B->material().set_refractive_index(1.5);
|
||||
AND_GIVEN("r <- ray(point(0, 0, 0.1, vector(0, 1, 0))")
|
||||
{
|
||||
Ray r(Tuple::Point(0, 0, 0.1), Tuple::Vector(0, 1, 0));
|
||||
AND_GIVEN("xs <- intersections(-0.9899:A, -0.4899:B, 0.4899:B, 0.9899:A)")
|
||||
{
|
||||
Intersections xs = Intersections({
|
||||
Intersection(-0.9899, A),
|
||||
Intersection(-0.4899, B),
|
||||
Intersection(0.4899, B),
|
||||
Intersection(0.9899, A),
|
||||
});
|
||||
WHEN("comps <- prepare_computations(xs[2], r, xs)")
|
||||
{
|
||||
IntersectionData comps = xs[2].prepare_computations(r, &xs);
|
||||
AND_WHEN("c <- refracted_color(w, comps, 5)")
|
||||
{
|
||||
Color c = w.refracted_color(comps, 5);
|
||||
THEN("c = color(0, 0.99888, 0.04725)")
|
||||
{
|
||||
REQUIRE(c == Color(0, 0.99888, 0.04725));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user