Starting working on area lights.

This commit is contained in:
Godzil
2020-02-28 18:35:45 +00:00
parent 53f66b554b
commit c4b680789e
12 changed files with 509 additions and 32 deletions

View File

@@ -14,9 +14,13 @@
#include <renderstat.h> #include <renderstat.h>
#include <stdio.h> #include <stdio.h>
class World;
enum LightType enum LightType
{ {
POINT_LIGHT = 0, POINT_LIGHT = 0,
AREA_LIGHT,
}; };
class Light class Light
@@ -26,15 +30,34 @@ public:
Tuple position; Tuple position;
LightType type; LightType type;
/* For area light */
Tuple corner;
Tuple uVec;
Tuple vVec;
uint32_t samples;
uint32_t uSteps;
uint32_t vSteps;
public: public:
Light(LightType type = POINT_LIGHT, Tuple position=Point(0, 0, 0), Light(LightType type = POINT_LIGHT, Tuple position=Point(0, 0, 0),
Colour intensity=Colour(1, 1, 1)) : type(type), position(position), intensity(intensity) Colour intensity=Colour(1, 1, 1)) : type(type), position(position), intensity(intensity)
{ stats.addLight(); }; { stats.addLight(); };
Light(LightType type, Tuple corner, Tuple fullUVec, uint32_t uSteps, Tuple fullVVec, uint32_t vSteps,
Colour intensity, bool jitter = false): type(type), corner(corner), uVec(fullUVec / uSteps), uSteps(uSteps),
vVec(fullVVec / vSteps), vSteps(vSteps), intensity(intensity)
{
this->samples = this->vSteps * this->uSteps;
this->position = this->corner + ((fullUVec + fullVVec) / 2);
stats.addLight();
};
double intensityAt(World &w, Tuple point);
bool operator==(const Light &b) const { return this->intensity == b.intensity && bool operator==(const Light &b) const { return this->intensity == b.intensity &&
this->position == b.position && this->position == b.position &&
this->type == b.type; }; this->type == b.type; };
Tuple pointOnLight(uint32_t u, uint32_t v);
void dumpMe(FILE *fp); void dumpMe(FILE *fp);
}; };

View File

@@ -36,7 +36,8 @@ public:
Material() : colour(Colour(1, 1, 1)), ambient(0.1), diffuse(0.9), specular(0.9), shininess(200), Material() : colour(Colour(1, 1, 1)), ambient(0.1), diffuse(0.9), specular(0.9), shininess(200),
reflective(0.0), transparency(0.0), emissive(0), refractiveIndex(1.0), pattern(nullptr) {}; reflective(0.0), transparency(0.0), emissive(0), refractiveIndex(1.0), pattern(nullptr) {};
Colour lighting(Light light, Tuple point, Tuple eyeVector, Tuple normalVector, Shape *hitObject, bool inShadow = false); Colour lighting(Light light, Tuple point, Tuple eyeVector, Tuple normalVector, Shape *hitObject,
double lightIntensity = 1.0);
bool operator==(const Material &b) const { return double_equal(this->ambient, b.ambient) && bool operator==(const Material &b) const { return double_equal(this->ambient, b.ambient) &&
double_equal(this->diffuse, b.diffuse) && double_equal(this->diffuse, b.diffuse) &&

View File

@@ -45,7 +45,7 @@ public:
Tuple shadeHit(Computation comps, uint32_t depthCount = 4); Tuple shadeHit(Computation comps, uint32_t depthCount = 4);
Tuple colourAt(Ray r, uint32_t depthCount = 4); Tuple colourAt(Ray r, uint32_t depthCount = 4);
bool isShadowed(Tuple point, uint32_t light = 0); bool isShadowed(Tuple point, Tuple lightPosition);
Colour reflectColour(Computation comps, uint32_t depthCount = 4); Colour reflectColour(Computation comps, uint32_t depthCount = 4);
Colour refractedColour(Computation comps, uint32_t depthCount = 4); Colour refractedColour(Computation comps, uint32_t depthCount = 4);

View File

@@ -8,6 +8,7 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <light.h> #include <light.h>
#include <world.h>
void Light::dumpMe(FILE *fp) void Light::dumpMe(FILE *fp)
{ {
@@ -17,3 +18,34 @@ void Light::dumpMe(FILE *fp)
this->position.x, this->position.y, this->position.z); this->position.x, this->position.y, this->position.z);
fprintf(fp, "\"Type\": \"PointLight\",\n"); fprintf(fp, "\"Type\": \"PointLight\",\n");
} }
double Light::intensityAt(World &w, Tuple point)
{
switch(this->type)
{
case POINT_LIGHT:
default:
return (w.isShadowed(point, this->position))?0.0:1.0;
case AREA_LIGHT:
double total = 0.0;
uint32_t v, u;
for(v = 0; v < this->vSteps; v++)
{
for(u = 0; u < this->uSteps; u++)
{
if (!w.isShadowed(point, this->pointOnLight(u, v)))
{
total = total + 1.0;
}
}
}
return total / this->samples;
break;
}
}
Tuple Light::pointOnLight(uint32_t u, uint32_t v)
{
return this->corner + this->uVec * (u+0.5) + this->vVec * (v+0.5);
}

View File

@@ -11,7 +11,8 @@
#include <colour.h> #include <colour.h>
#include <shape.h> #include <shape.h>
Colour Material::lighting(Light light, Tuple point, Tuple eyeVector, Tuple normalVector, Shape *hitObject, bool inShadow) Colour Material::lighting(Light light, Tuple point, Tuple eyeVector, Tuple normalVector, Shape *hitObject,
double lightIntensity)
{ {
Colour pointColor = this->colour; Colour pointColor = this->colour;
@@ -36,8 +37,6 @@ Colour Material::lighting(Light light, Tuple point, Tuple eyeVector, Tuple norma
emissiveColour = pointColor * this->emissive; emissiveColour = pointColor * this->emissive;
if (!inShadow)
{
lightDotNormal = lightVector.dot(normalVector); lightDotNormal = lightVector.dot(normalVector);
if (lightDotNormal < 0) if (lightDotNormal < 0)
@@ -62,7 +61,10 @@ Colour Material::lighting(Light light, Tuple point, Tuple eyeVector, Tuple norma
specularColour = light.intensity * this->specular * factor; specularColour = light.intensity * this->specular * factor;
} }
} }
}
diffuseColour = diffuseColour * lightIntensity;
specularColour = specularColour * lightIntensity;
finalColour = emissiveColour + ambientColour + diffuseColour + specularColour; finalColour = emissiveColour + ambientColour + diffuseColour + specularColour;
return Colour(finalColour.x, finalColour.y, finalColour.z); return Colour(finalColour.x, finalColour.y, finalColour.z);

View File

@@ -102,10 +102,10 @@ Tuple World::shadeHit(Computation comps, uint32_t depthCount)
for(lightIndex = 0; lightIndex < this->lightCount; lightIndex++) for(lightIndex = 0; lightIndex < this->lightCount; lightIndex++)
{ {
bool isThereAnObstacle = this->isShadowed(comps.overHitPoint, lightIndex); double lightLevel = this->lightList[lightIndex]->intensityAt(*this, comps.overHitPoint);
surface = surface + comps.material->lighting(*this->lightList[lightIndex], comps.overHitPoint, comps.eyeVector, surface = surface + comps.material->lighting(*this->lightList[lightIndex], comps.overHitPoint, comps.eyeVector,
comps.normalVector, comps.object, isThereAnObstacle); comps.normalVector, comps.object, lightLevel);
} }
Tuple reflected = this->reflectColour(comps, depthCount); Tuple reflected = this->reflectColour(comps, depthCount);
Tuple refracted = this->refractedColour(comps, depthCount); Tuple refracted = this->refractedColour(comps, depthCount);
@@ -137,9 +137,9 @@ Tuple World::colourAt(Ray r, uint32_t depthCount)
} }
} }
bool World::isShadowed(Tuple point, uint32_t light) bool World::isShadowed(Tuple point, Tuple lightPosition)
{ {
Tuple v = this->lightList[light]->position - point; Tuple v = lightPosition - point;
double distance = v.magnitude(); double distance = v.magnitude();
Tuple direction = v.normalise(); Tuple direction = v.normalise();

View File

@@ -90,6 +90,16 @@ target_include_directories(ch14_test PUBLIC ../source/include)
target_sources(ch14_test PRIVATE ch14_test.cpp) target_sources(ch14_test PRIVATE ch14_test.cpp)
target_link_libraries(ch14_test rayonnement) target_link_libraries(ch14_test rayonnement)
add_executable(arealight_test)
target_include_directories(arealight_test PUBLIC ../source/include)
target_sources(arealight_test PRIVATE arealight_test.cpp)
target_link_libraries(arealight_test rayonnement)
add_executable(triangle_rendertest)
target_include_directories(triangle_rendertest PUBLIC ../source/include)
target_sources(triangle_rendertest PRIVATE triangle_rendertest.cpp)
target_link_libraries(triangle_rendertest rayonnement)
add_executable(christmasball_render) add_executable(christmasball_render)
target_include_directories(christmasball_render PUBLIC ../source/include) target_include_directories(christmasball_render PUBLIC ../source/include)
target_sources(christmasball_render PRIVATE christmasball_render.cpp) target_sources(christmasball_render PRIVATE christmasball_render.cpp)
@@ -107,7 +117,9 @@ add_test(NAME Chapter12_Test COMMAND $<TARGET_FILE:ch12_test>)
add_test(NAME Chapter13_Test COMMAND $<TARGET_FILE:ch13_test>) add_test(NAME Chapter13_Test COMMAND $<TARGET_FILE:ch13_test>)
add_test(NAME Chapter13_ConeBonus COMMAND $<TARGET_FILE:ch13_cone>) add_test(NAME Chapter13_ConeBonus COMMAND $<TARGET_FILE:ch13_cone>)
add_test(NAME Chapter14_Test COMMAND $<TARGET_FILE:ch14_test>) add_test(NAME Chapter14_Test COMMAND $<TARGET_FILE:ch14_test>)
add_test(NAME AreaLight_Test COMMAND $<TARGET_FILE:arealight_test>)
add_test(NAME Test_Rendering COMMAND $<TARGET_FILE:test_render>) add_test(NAME Test_Rendering COMMAND $<TARGET_FILE:test_render>)
add_test(NAME Triangle_RenderTest COMMAND $<TARGET_FILE:triangle_rendertest>)
add_test(NAME ChristmasBall_Rendering COMMAND $<TARGET_FILE:christmasball_render>) add_test(NAME ChristmasBall_Rendering COMMAND $<TARGET_FILE:christmasball_render>)
add_test(NAME Hw3Render COMMAND $<TARGET_FILE:hw3render> ${CMAKE_CURRENT_SOURCE_DIR}/test.hw3scene) add_test(NAME Hw3Render COMMAND $<TARGET_FILE:hw3render> ${CMAKE_CURRENT_SOURCE_DIR}/test.hw3scene)
add_test(NAME Hw3RenderAllCmds COMMAND $<TARGET_FILE:hw3render> ${CMAKE_CURRENT_SOURCE_DIR}/test_keys.hw3scene) add_test(NAME Hw3RenderAllCmds COMMAND $<TARGET_FILE:hw3render> ${CMAKE_CURRENT_SOURCE_DIR}/test_keys.hw3scene)

99
tests/arealight_test.cpp Normal file
View File

@@ -0,0 +1,99 @@
/*
* DoRayMe - a quick and dirty Raytracer
* Render test for reflection in chapter 13.
*
* Created by Manoël Trapier
* Copyright (c) 2020 986-Studio.
*
*/
#include <world.h>
#include <light.h>
#include <sphere.h>
#include <plane.h>
#include <cube.h>
#include <cylinder.h>
#include <material.h>
#include <colour.h>
#include <canvas.h>
#include <camera.h>
#include <group.h>
#include <cone.h>
#include <pattern.h>
#include <strippattern.h>
#include <gradientpattern.h>
#include <checkerspattern.h>
#include <ringpattern.h>
#include <transformation.h>
int main()
{
World w = World();
/* Add lights */
#if 0
Light light1 = Light(AREA_LIGHT, Point(-1, 2, 4),
Vector(2, 0, 0), 8,
Vector(0, 2, 0), 8,
//jitter,
Colour(1.5, 1.5, 1.5));
#else
Light light1 = Light(POINT_LIGHT, Point(-1, 2, 4), Colour(1.5,1.5,1.5));
#endif
w.addLight(&light1);
/* ----------------------------- */
/* Cube that pretend to be the light */
Cube c = Cube();
c.material.colour = Colour(1.5, 1.5, 1.5);
c.material.ambient = 1;
c.material.diffuse = 0;
c.material.specular = 0;
c.dropShadow = false;
c.setTransform(translation(0, 3, 4) * scaling(1, 1, 0.01));
w.addObject(&c);
Plane p = Plane();
p.material.colour = Colour(1, 1, 1);
p.material.ambient = 0.025;
p.material.diffuse = 0.67;
p.material.specular = 0;
w.addObject(&p);
Sphere s1 = Sphere();
s1.setTransform(translation(0.5, 0.5,0) * scaling(0.5, 0.5, 0.5));
s1.material.colour = Colour(1, 0, 0);
s1.material.ambient = 0.1;
s1.material.specular = 0;
s1.material.diffuse = 0.6;
s1.material.reflective = 0.3;
w.addObject(&s1);
Sphere s2 = Sphere();
s2.setTransform(translation(-0.25, 0.33,0) * scaling(0.33, 0.33, 0.33));
s2.material.colour = Colour(0.5, 0.5, 1);
s2.material.ambient = 0.1;
s2.material.specular = 0;
s2.material.diffuse = 0.6;
s2.material.reflective = 0.3;
w.addObject(&s2);
/* ----------------------------- */
/* Set the camera */
//Camera camera = Camera(400, 160, 0.7854);
Camera camera = Camera(800, 320, 0.7854);
camera.setTransform(viewTransform(Point(-3, 1, 2.5),
Point(0, 0.5, 0),
Vector(0, 1, 0)));
/* Now render it */
Canvas image = camera.render(w, 5);
image.SaveAsPNG("arealight_test.png");
return 0;
}

View File

@@ -11,6 +11,8 @@
#include <colour.h> #include <colour.h>
#include <tuple.h> #include <tuple.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <world.h>
#include <worldbuilder.h>
TEST(LightTest, A_point_lighthas_a_position_and_intensity) TEST(LightTest, A_point_lighthas_a_position_and_intensity)
{ {
@@ -22,3 +24,126 @@ TEST(LightTest, A_point_lighthas_a_position_and_intensity)
ASSERT_EQ(light.position, position); ASSERT_EQ(light.position, position);
ASSERT_EQ(light.intensity, intensity); ASSERT_EQ(light.intensity, intensity);
} }
TEST(LightTest, Point_lights_evaluate_the_lights_intensity_at_a_given_point)
{
World w = DefaultWorld();
Light *light = w.getLight(0);
Tuple testList[] = {
Point(0, 1.0001, 0),
Point(-1.0001, 0, 0),
Point(0, 0, -1.0001),
Point(0, 0, 1.0001),
Point(1.0001, 0, 0),
Point(0, -1.0001, 0),
Point(0, 0, 0),
};
double testResult[] = {
1.0,
1.0,
1.0,
0.0,
0.0,
0.0,
0.0,
};
int testCount = sizeof(testList)/sizeof((testList)[0]);
int i;
for(i = 0; i < testCount; i++)
{
ASSERT_TRUE(double_equal(light->intensityAt(w, testList[i]), testResult[i]));
}
}
TEST(LightTest, Creating_an_area_light)
{
Tuple corner = Point(0, 0, 0);
Tuple v1 = Vector(2, 0, 0);
Tuple v2 = Vector(0, 0, 1);
Light light = Light(AREA_LIGHT, corner, v1, 4, v2, 2, Colour(1, 1, 1));
/* Position is used to store the corner in area lights */
ASSERT_EQ(light.corner, corner);
ASSERT_EQ(light.uVec, Vector(0.5, 0, 0));
ASSERT_EQ(light.uSteps, 4);
ASSERT_EQ(light.vVec, Vector(0, 0, 0.5));
ASSERT_EQ(light.vSteps, 2);
ASSERT_EQ(light.samples, 8);
ASSERT_EQ(light.position, Point(1, 0, 0.5));
}
TEST(LightTest, Finding_a_single_point_on_an_area_light)
{
Tuple corner = Point(0, 0, 0);
Tuple v1 = Vector(2, 0, 0);
Tuple v2 = Vector(0, 0, 1);
Light light = Light(AREA_LIGHT, corner, v1, 4, v2, 2, Colour(1, 1, 1));
uint32_t testList[][2] = {
{0, 0},
{1, 0},
{0, 1},
{2, 0},
{3, 1},
};
Point testResults[] {
Point(0.25, 0, 0.25),
Point(0.75, 0, 0.25),
Point(0.25, 0, 0.75),
Point(1.25, 0, 0.25),
Point(1.75, 0, 0.75),
};
int testCount = sizeof(testList)/sizeof((testList)[0]);
int i;
for(i = 0; i < testCount; i++)
{
Tuple tp = light.pointOnLight(testList[i][0], testList[i][1]);
ASSERT_EQ(tp, testResults[i]);
}
}
TEST(LightTest, The_area_light_intensity_function)
{
World w = DefaultWorld();
Tuple corner = Point(-0.5, -0.5, -5);
Tuple v1 = Vector(1, 0, 0);
Tuple v2 = Vector(0, 1, 0);
Light light = Light(AREA_LIGHT, corner, v1, 2, v2, 2, Colour(1, 1, 1));
Point testList[] = {
Point(0, 0, 2),
Point(1, -1, 2),
Point(1.5, 0, 2),
Point(1.25, 1.25, 3),
Point(0, 0, -2),
};
double testResults[] {
0.0,
0.25,
0.5,
0.75,
1,
};
int testCount = sizeof(testList)/sizeof((testList)[0]);
int i;
for(i = 0; i < testCount; i++)
{
double intensity = light.intensityAt(w, testList[i]);
ASSERT_TRUE(double_equal(intensity, testResults[i]));
}
}

View File

@@ -11,6 +11,8 @@
#include <colour.h> #include <colour.h>
#include <testshape.h> #include <testshape.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <world.h>
#include <worldbuilder.h>
TEST(MaterialTest, The_default_material) TEST(MaterialTest, The_default_material)
{ {
@@ -101,9 +103,9 @@ TEST(MaterialTest, Lighting_with_the_surface_in_shadow)
Vector eyev = Vector(0, 0, -1); Vector eyev = Vector(0, 0, -1);
Vector normalv = Vector(0, 0, -1); Vector normalv = Vector(0, 0, -1);
Light light = Light(POINT_LIGHT, Point(0, 0, -10), Colour(1, 1, 1)); Light light = Light(POINT_LIGHT, Point(0, 0, -10), Colour(1, 1, 1));
bool inShadow = true; double lightLevel = 0.0;
Colour result = m.lighting(light, position, eyev, normalv, &t, inShadow); Colour result = m.lighting(light, position, eyev, normalv, &t, lightLevel);
ASSERT_EQ(result, Colour(0.1, 0.1, 0.1)); ASSERT_EQ(result, Colour(0.1, 0.1, 0.1));
} }
@@ -165,3 +167,42 @@ TEST(MaterialTest, Equality_tests)
m.colour = Colour(32, 32, 32); m.colour = Colour(32, 32, 32);
ASSERT_NE(m, m2); ASSERT_NE(m, m2);
} }
TEST(MaterialTest, lighting_uses_light_intensity_to_attenuate_colour)
{
World w = DefaultWorld();
Light *light = w.getLight(0);
Shape *shape = w.getObject(0);
light->position = Point(0, 0, -10);
light->intensity = Colour(1, 1, 1);
shape->material.ambient = 0.1;
shape->material.diffuse = 0.9;
shape->material.specular = 0;
shape->material.colour = Colour(1, 1, 1);
Tuple pt = Point(0, 0, -1);
Tuple eyev = Vector(0, 0, -1);
Tuple normalv = Vector(0, 0, -1);
double testList[] = {
1.0,
0.5,
0.0,
};
Colour testResult[] = {
Colour(1, 1, 1),
Colour(0.55, 0.55, 0.55),
Colour(0.1, 0.1, 0.1),
};
int testCount = sizeof(testList)/sizeof((testList)[0]);
int i;
for(i = 0; i < testCount; i++)
{
ASSERT_EQ(shape->material.lighting(*light, pt, eyev, normalv, shape, testList[i]), testResult[i]);
}
}

View File

@@ -0,0 +1,116 @@
/*
* DoRayMe - a quick and dirty Raytracer
* Render test for reflection in chapter 13.
*
* Created by Manoël Trapier
* Copyright (c) 2020 986-Studio.
*
*/
#include <world.h>
#include <light.h>
#include <plane.h>
#include <colour.h>
#include <canvas.h>
#include <camera.h>
#include <triangle.h>
#include <group.h>
#include <time.h>
#include <transformation.h>
double frand(double max)
{
return max * (rand() / ((double) RAND_MAX));
}
int main()
{
World w = World();
/* Add lights */
Light light1 = Light(POINT_LIGHT, Point(10000, 10000, -10000), Colour(0.25, 0.25, 0.25));
w.addLight(&light1);
Light light2 = Light(POINT_LIGHT, Point(-10000, 10000, -10000), Colour(0.25, 0.25, 0.25));
w.addLight(&light2);
Light light3 = Light(POINT_LIGHT, Point(10000, -10000, -10000), Colour(0.25, 0.25, 0.25));
w.addLight(&light3);
Light light4 = Light(POINT_LIGHT, Point(-10000, -10000, -10000), Colour(0.25, 0.25, 0.25));
w.addLight(&light4);
/* ----------------------------- */
/* White background */
Plane p = Plane();
p.setTransform(translation(0, 0, 100) * rotationX(1.5708));
p.material.colour = Colour(1, 1, 1);
p.material.ambient = 1;
p.material.diffuse = 0;
p.material.specular = 0;
w.addObject(&p);
/* ----------------------------- */
Group g = Group();
srand(10); /* Force the seed to a known value */
int i;
Point p1, p2, p3;
/* Let's add a bunche of "random" triangles */
for (i = 0; i < 10; i++)
{
p1.x = 7-frand(14);
p1.y = 7-frand(14);
p1.z = 7-frand(14);
p2.x = 7-frand(14);
p2.y = 7-frand(14);
p2.z = 7-frand(14);
p3.x = 7-frand(14);
p3.y = 7-frand(14);
p3.z = 7-frand(14);
Triangle *tri = new Triangle(p1, p2, p3);
tri->material.colour.x = frand(1); // red
tri->material.colour.y = frand(1); // green
tri->material.colour.z = frand(1); // blue
//tri->material.refractiveIndex = frand(2);
//tri->material.transparency = frand(1);
//tri->material.shininess = frand(300);
//tri->material.specular = frand(1);
//tri->material.ambient = frand(1);
tri->material.reflective = frand(1);
//tri->material.diffuse = frand(1);
g.addObject(tri);
}
g.setTransform(rotationX(3.14));
w.addObject(&g);
/* ----------------------------- */
FILE *fpOut = fopen("triangles_world.json", "wt");
if (fpOut)
{
w.dumpMe(fpOut);
fclose(fpOut);
}
/* ----------------------------- */
/* Set the camera */
Camera camera = Camera(500, 500, M_PI/1.5);
camera.setTransform(viewTransform(Point(0, 0, -9),
Point(0, 0, 0),
Vector(0, 1, 0)));
/* Now render it */
Canvas image = camera.render(w, 5);
image.SaveAsPNG("triangle_rendertest.png");
return 0;
}

View File

@@ -120,7 +120,7 @@ TEST(WorldTest, There_is_no_shadow_when_nothing_is_collinear_with_point_and_ligh
World w = DefaultWorld(); World w = DefaultWorld();
Tuple p = Point(0, 10, 0); Tuple p = Point(0, 10, 0);
ASSERT_FALSE(w.isShadowed(p)); ASSERT_FALSE(w.isShadowed(p, w.getLight(0)->position));
} }
TEST(WorldTest, The_shadow_when_an_object_is_between_the_point_and_the_light) TEST(WorldTest, The_shadow_when_an_object_is_between_the_point_and_the_light)
@@ -128,7 +128,7 @@ TEST(WorldTest, The_shadow_when_an_object_is_between_the_point_and_the_light)
World w = DefaultWorld(); World w = DefaultWorld();
Tuple p = Point(10, -10, 10); Tuple p = Point(10, -10, 10);
ASSERT_TRUE(w.isShadowed(p)); ASSERT_TRUE(w.isShadowed(p, w.getLight(0)->position));
} }
TEST(WorldTest, There_is_no_shadow_whne_an_object_is_behing_the_light) TEST(WorldTest, There_is_no_shadow_whne_an_object_is_behing_the_light)
@@ -136,7 +136,7 @@ TEST(WorldTest, There_is_no_shadow_whne_an_object_is_behing_the_light)
World w = DefaultWorld(); World w = DefaultWorld();
Tuple p = Point(-20, 20, -20); Tuple p = Point(-20, 20, -20);
ASSERT_FALSE(w.isShadowed(p)); ASSERT_FALSE(w.isShadowed(p, w.getLight(0)->position));
} }
TEST(WorldTest, There_is_no_shadow_when_an_object_is_behing_the_point) TEST(WorldTest, There_is_no_shadow_when_an_object_is_behing_the_point)
@@ -144,7 +144,7 @@ TEST(WorldTest, There_is_no_shadow_when_an_object_is_behing_the_point)
World w = DefaultWorld(); World w = DefaultWorld();
Tuple p = Point(-2, 2, -2); Tuple p = Point(-2, 2, -2);
ASSERT_FALSE(w.isShadowed(p)); ASSERT_FALSE(w.isShadowed(p, w.getLight(0)->position));
} }
TEST(WorldTest, Shade_hit_is_given_an_intersection_in_shadow) TEST(WorldTest, Shade_hit_is_given_an_intersection_in_shadow)
@@ -427,3 +427,29 @@ TEST(WorldTest, Shade_hit_with_a_reflective_transparent_material)
set_equal_precision(FLT_EPSILON); set_equal_precision(FLT_EPSILON);
} }
TEST(WorldTest, Is_shadow_test_for_occlusion_between_two_points)
{
World w = DefaultWorld();
Tuple lightPosition = Point(-10, -10, -10);
Point testList[] = {
Point(-10, -10, 10),
Point(10, 10, 10),
Point(-20, -20, 20),
Point(-5, -5, 5),
};
bool testResult[] = {
false,
true,
false,
false,
};
int testCount = sizeof(testList)/sizeof((testList)[0]);
int i;
for(i = 0; i < testCount; i++)
{
ASSERT_EQ(w.isShadowed(lightPosition, testList[i]), testResult[i]);
}
}