[FEAT] until test3 of schlick implementation
This commit is contained in:
@@ -633,3 +633,153 @@ SCENARIO("The refracted color with a refracted ray", "[features/world.feature]")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
SCENARIO("shade_hit() with a transparent material", "[features/world.feature]")
|
||||
{
|
||||
GIVEN("w <- default_world()")
|
||||
{
|
||||
World w = World::default_world();
|
||||
AND_GIVEN("floor <- plane() with:")
|
||||
{
|
||||
// | transform | translation(0, -1, 0) |
|
||||
// | material.transparency | 0.5 |
|
||||
// | material.refractive_index | 1.5 |
|
||||
Plane floor;
|
||||
floor.set_transform(Matrix::translation(0, -1, 0));
|
||||
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("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("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.93642, 0.68642, 0.68642)")
|
||||
{
|
||||
REQUIRE(color == Color(0.93642, 0.68642, 0.68642));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
SCENARIO("The Schlick approximation under total internal reflection", "[features/intersections.feature]")
|
||||
{
|
||||
GIVEN("shape <- glass_sphere()")
|
||||
{
|
||||
Sphere shape = Sphere::Glass();
|
||||
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)});
|
||||
WHEN("comps <- prepare_computations(xs[1], r, xs)")
|
||||
{
|
||||
IntersectionData comps = xs[1].prepare_computations(r, &xs);
|
||||
AND_WHEN("reflectance <- schlick(comps)")
|
||||
{
|
||||
double reflectance = comps.schlick();
|
||||
THEN("reflectance = 1.0")
|
||||
{
|
||||
REQUIRE(reflectance == 1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
SCENARIO("The Schlick approximation with a perpendicular viewing angle", "[features/intersections.feature]")
|
||||
{
|
||||
GIVEN("shape <- glass_sphere()")
|
||||
{
|
||||
Sphere shape = Sphere::Glass();
|
||||
AND_GIVEN("r <- ray(point(0, 0, 0), vector(0, 1, 0)")
|
||||
{
|
||||
Ray r(Tuple::Point(0, 0, 0), Tuple::Vector(0, 1, 0));
|
||||
AND_GIVEN("xs <- intersections(-1:shape, 1:shape)")
|
||||
{
|
||||
Intersections xs = Intersections({Intersection(-1, &shape),
|
||||
Intersection(1, &shape)});
|
||||
WHEN("comps <- prepare_computations(xs[1], r, xs)")
|
||||
{
|
||||
IntersectionData comps = xs[1].prepare_computations(r, &xs);
|
||||
AND_WHEN("reflectance <- schlick(comps)")
|
||||
{
|
||||
double reflectance = comps.schlick();
|
||||
THEN("reflectance = 0.04")
|
||||
{
|
||||
REQUIRE(double_equal(reflectance, 0.04));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
SCENARIO("The Schlick approximation with a small angle and n2 > n1", "[features/intersections.feature]")
|
||||
{
|
||||
GIVEN("shape <- glass_sphere()")
|
||||
{
|
||||
Sphere shape = Sphere::Glass();
|
||||
AND_GIVEN("r <- ray(point(0, 0.99, -2), vector(0, 0, 1)")
|
||||
{
|
||||
Ray r(Tuple::Point(0, 0.99, -2), Tuple::Vector(0, 0, 1));
|
||||
AND_GIVEN("xs <- intersections(1.8589:shape)")
|
||||
{
|
||||
Intersections xs = Intersections({Intersection(1.8589, &shape)});
|
||||
WHEN("comps <- prepare_computations(xs[0], r, xs)")
|
||||
{
|
||||
IntersectionData comps = xs[0].prepare_computations(r, &xs);
|
||||
AND_WHEN("reflectance <- schlick(comps)")
|
||||
{
|
||||
double reflectance = comps.schlick();
|
||||
THEN("reflectance = 0.48873")
|
||||
{
|
||||
REQUIRE(double_equal(reflectance, 0.48873));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user