[WIP] Test 7 of refraction is in wip
This commit is contained in:
@@ -232,7 +232,7 @@ SCENARIO("An intersection encapsulates t and object", "[features/intersections.f
|
||||
GIVEN("s <- sphere()")
|
||||
{
|
||||
Sphere s;
|
||||
WHEN("intersection(3.5,s)")
|
||||
WHEN("intersection(3.5, s)")
|
||||
{
|
||||
Intersection i(3.5, &s);
|
||||
|
||||
@@ -284,7 +284,7 @@ SCENARIO("Intersection could be compared", "[features/intersections.feature]")
|
||||
GIVEN("s <- sphere()")
|
||||
{
|
||||
Sphere s;
|
||||
AND_GIVEN("i1 <- intersection(3,s) and i2 <- intersection(4,s)")
|
||||
AND_GIVEN("i1 <- intersection(3, s) and i2 <- intersection(4, s)")
|
||||
{
|
||||
Intersection i1(3.0, &s);
|
||||
Intersection i2(4.0, &s);
|
||||
@@ -324,13 +324,13 @@ SCENARIO("Aggregating intersections", "[features/intersections.feature]")
|
||||
GIVEN("s <- sphere()")
|
||||
{
|
||||
Sphere s;
|
||||
AND_GIVEN("i1 <- intersection(1,s)")
|
||||
AND_GIVEN("i1 <- intersection(1, s)")
|
||||
{
|
||||
Intersection i1(1, &s);
|
||||
AND_GIVEN("i2 <- intersection(2,s)")
|
||||
AND_GIVEN("i2 <- intersection(2, s)")
|
||||
{
|
||||
Intersection i2(2, &s);
|
||||
WHEN("xs <- intersections(i1,i2)")
|
||||
WHEN("xs <- intersections(i1, i2)")
|
||||
{
|
||||
Intersections xs = Intersections({i1, i2});
|
||||
THEN("xs.count = 2")
|
||||
@@ -394,7 +394,7 @@ SCENARIO("Intersect sets the object on the intersection", "[features/spheres.fea
|
||||
AND_GIVEN("s <- sphere()")
|
||||
{
|
||||
Sphere s;
|
||||
WHEN("xs <- intersect(s,r)")
|
||||
WHEN("xs <- intersect(s, r)")
|
||||
{
|
||||
Intersections xs = s.intersect(r);
|
||||
THEN("xs.count = 2")
|
||||
@@ -421,13 +421,13 @@ SCENARIO("The hit, when all intersections have positive t", "[features/intersect
|
||||
GIVEN("s <- sphere()")
|
||||
{
|
||||
Sphere s;
|
||||
AND_GIVEN("i1 <- intersection(1,s)")
|
||||
AND_GIVEN("i1 <- intersection(1, s)")
|
||||
{
|
||||
Intersection i1(1, &s);
|
||||
AND_GIVEN("i2 <- intersection(2,s)")
|
||||
AND_GIVEN("i2 <- intersection(2, s)")
|
||||
{
|
||||
Intersection i2(2, &s);
|
||||
AND_GIVEN("xs <- intersections(i1,i2)")
|
||||
AND_GIVEN("xs <- intersections(i1, i2)")
|
||||
{
|
||||
Intersections xs = Intersections({i2, i1});
|
||||
WHEN("i <- hit(xs)")
|
||||
@@ -451,13 +451,13 @@ SCENARIO("The hit, when some intersections have negative t", "[features/intersec
|
||||
GIVEN("s <- sphere()")
|
||||
{
|
||||
Sphere s;
|
||||
AND_GIVEN("i1 <- intersection(-1,s)")
|
||||
AND_GIVEN("i1 <- intersection(-1, s)")
|
||||
{
|
||||
Intersection i1(-1, &s);
|
||||
AND_GIVEN("i2 <- intersection(2,s)")
|
||||
AND_GIVEN("i2 <- intersection(2, s)")
|
||||
{
|
||||
Intersection i2(1, &s);
|
||||
AND_GIVEN("xs <- intersections(i1,i2)")
|
||||
AND_GIVEN("xs <- intersections(i1, i2)")
|
||||
{
|
||||
Intersections xs = Intersections({i2, i1});
|
||||
WHEN("i <- hit(xs)")
|
||||
@@ -481,13 +481,13 @@ SCENARIO("The hit, when all intersections have negative t", "[features/intersect
|
||||
GIVEN("s <- sphere()")
|
||||
{
|
||||
Sphere s;
|
||||
AND_GIVEN("i1 <- intersection(-2,s)")
|
||||
AND_GIVEN("i1 <- intersection(-2, s)")
|
||||
{
|
||||
Intersection i1(-2, &s);
|
||||
AND_GIVEN("i2 <- intersection(-1,s)")
|
||||
AND_GIVEN("i2 <- intersection(-1, s)")
|
||||
{
|
||||
Intersection i2(-1, &s);
|
||||
AND_GIVEN("xs <- intersections(i1,i2)")
|
||||
AND_GIVEN("xs <- intersections(i1, i2)")
|
||||
{
|
||||
Intersections xs = Intersections({i1, i2});
|
||||
WHEN("i <- hit(xs)")
|
||||
@@ -512,16 +512,16 @@ SCENARIO("The hit is always the lowest nonnegative intersection", "[features/int
|
||||
GIVEN("s <- sphere()")
|
||||
{
|
||||
Sphere s;
|
||||
AND_GIVEN("i1 <- intersection(5,s)")
|
||||
AND_GIVEN("i1 <- intersection(5, s)")
|
||||
{
|
||||
Intersection i1(5, &s);
|
||||
AND_GIVEN("i2 <- intersection(7,s)")
|
||||
AND_GIVEN("i2 <- intersection(7, s)")
|
||||
{
|
||||
Intersection i2(7, &s);
|
||||
AND_GIVEN("i3 <- intersection(-3,s)")
|
||||
AND_GIVEN("i3 <- intersection(-3, s)")
|
||||
{
|
||||
Intersection i3(-3, &s);
|
||||
AND_GIVEN("i4 <- intersection(2,s)")
|
||||
AND_GIVEN("i4 <- intersection(2, s)")
|
||||
{
|
||||
Intersection i4(2, &s);
|
||||
AND_GIVEN("xs <- intersections(i1, i2, i3, i4)")
|
||||
@@ -645,7 +645,7 @@ SCENARIO("Intersecting a scaled sphere with a ray", "[features/spheres.feature]"
|
||||
AND_GIVEN("s <- Sphere()")
|
||||
{
|
||||
Sphere s;
|
||||
WHEN("set_transform(s,scaling(2,2,2))")
|
||||
WHEN("set_transform(s,scaling(2, 2, 2))")
|
||||
{
|
||||
s.set_transform(Matrix::scaling(2, 2, 2));
|
||||
AND_WHEN("xs <- intersect(s,r)")
|
||||
|
||||
@@ -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