Adding support for pattern.

Still a bit more work to be done there.
This commit is contained in:
Godzil
2020-02-21 09:36:34 +00:00
parent 9d0db6a635
commit 75cf59cc1a
14 changed files with 491 additions and 17 deletions

View File

@@ -9,6 +9,7 @@
#include <material.h>
#include <math.h>
#include <colour.h>
#include <testshape.h>
#include <gtest/gtest.h>
TEST(MaterialTest, The_default_material)
@@ -28,33 +29,36 @@ static Point position = Point(0, 0, 0);
TEST(MaterialTest, Lighting_with_the_eye_between_the_light_and_the_surface)
{
TestShape t = TestShape();
Vector eyev = Vector(0, 0, -1);
Vector normalv = Vector(0, 0, -1);
Light light = Light(POINT_LIGHT, Point(0, 0, -10), Colour(1, 1, 1));
Colour result = m.lighting(light, position, eyev, normalv);
Colour result = m.lighting(light, position, eyev, normalv, &t);
ASSERT_EQ(result, Colour(1.9, 1.9, 1.9));
}
TEST(MaterialTest, Lighting_with_the_eye_between_the_light_and_the_surface_eye_offset_by_45)
{
TestShape t = TestShape();
Vector eyev = Vector(0, -sqrt(2)/2, -sqrt(2)/2);
Vector normalv = Vector(0, 0, -1);
Light light = Light(POINT_LIGHT, Point(0, 0, -10), Colour(1, 1, 1));
Colour result = m.lighting(light, position, eyev, normalv);
Colour result = m.lighting(light, position, eyev, normalv, &t);
ASSERT_EQ(result, Colour(1.0, 1.0, 1.0));
}
TEST(MaterialTest, Lighting_with_the_eye_opposite_surface_light_offset_45)
{
TestShape t = TestShape();
Vector eyev = Vector(0, 0, -1);
Vector normalv = Vector(0, 0, -1);
Light light = Light(POINT_LIGHT, Point(0, 10, -10), Colour(1, 1, 1));
Colour result = m.lighting(light, position, eyev, normalv);
Colour result = m.lighting(light, position, eyev, normalv, &t);
set_equal_precision(0.0001);
@@ -65,11 +69,12 @@ TEST(MaterialTest, Lighting_with_the_eye_opposite_surface_light_offset_45)
TEST(MaterialTest, Lighting_with_the_eye_in_the_path_of_the_reflection_vector)
{
TestShape t = TestShape();
Vector eyev = Vector(0, -sqrt(2)/2, -sqrt(2)/2);
Vector normalv = Vector(0, 0, -1);
Light light = Light(POINT_LIGHT, Point(0, 10, -10), Colour(1, 1, 1));
Colour result = m.lighting(light, position, eyev, normalv);
Colour result = m.lighting(light, position, eyev, normalv, &t);
set_equal_precision(0.0001);
@@ -80,23 +85,25 @@ TEST(MaterialTest, Lighting_with_the_eye_in_the_path_of_the_reflection_vector)
TEST(MaterialTest, Lighting_with_the_light_behind_the_surface)
{
TestShape t = TestShape();
Vector eyev = Vector(0, 0, -1);
Vector normalv = Vector(0, 0, -1);
Light light = Light(POINT_LIGHT, Point(0, 0, 10), Colour(1, 1, 1));
Colour result = m.lighting(light, position, eyev, normalv);
Colour result = m.lighting(light, position, eyev, normalv, &t);
ASSERT_EQ(result, Colour(0.1, 0.1, 0.1));
}
TEST(MaterialTest, Lighting_with_the_surface_in_shadow)
{
TestShape t = TestShape();
Vector eyev = Vector(0, 0, -1);
Vector normalv = Vector(0, 0, -1);
Light light = Light(POINT_LIGHT, Point(0, 0, -10), Colour(1, 1, 1));
bool inShadow = true;
Colour result = m.lighting(light, position, eyev, normalv, inShadow);
Colour result = m.lighting(light, position, eyev, normalv, &t, inShadow);
ASSERT_EQ(result, Colour(0.1, 0.1, 0.1));
}