157 lines
5.0 KiB
C
157 lines
5.0 KiB
C
#include <stdbool.h>
|
|
#include <stdio.h>
|
|
|
|
#include "materials.h"
|
|
#include "lighting.h"
|
|
#include "runner.h"
|
|
#include "shapes.h"
|
|
|
|
static bool materials_test_0(const char ** scenario)
|
|
{
|
|
*scenario = "The default material";
|
|
|
|
struct material m = material();
|
|
return
|
|
tuple_equal(m.color, color(1.0f, 1.0f, 1.0f)) &&
|
|
float_equal(m.ambient, 0.1f) &&
|
|
float_equal(m.diffuse, 0.9f) &&
|
|
float_equal(m.specular, 0.9f) &&
|
|
float_equal(m.shininess, 200.0f);
|
|
}
|
|
|
|
static bool materials_test_1(const char ** scenario)
|
|
{
|
|
*scenario = "Lighting with the eye between the light and the surface";
|
|
|
|
struct material m = material();
|
|
struct tuple position = point(0.0f, 0.0f, 0.0f);
|
|
|
|
struct tuple eyev = vector(0.0f, 0.0f, -1.0f);
|
|
struct tuple normalv = vector(0.0f, 0.0f, -1.0f);
|
|
struct light light = point_light(point(0.0f, 0.0f, -10.0f), color(1.0f, 1.0f, 1.0f));
|
|
struct shape object = shape();
|
|
struct tuple result = lighting(m, &object, light, position, eyev, normalv, false);
|
|
|
|
return tuple_equal(result, color(1.9f, 1.9f, 1.9f));
|
|
}
|
|
|
|
static bool materials_test_2(const char ** scenario)
|
|
{
|
|
*scenario = "Lighting with the eye between the light and surface, eye offset 45 degrees";
|
|
|
|
struct material m = material();
|
|
struct tuple position = point(0.0f, 0.0f, 0.0f);
|
|
|
|
struct tuple eyev = vector(0.0f, 0.7071067811865476, -0.7071067811865476);
|
|
struct tuple normalv = vector(0.0f, 0.0f, -1.0f);
|
|
struct light light = point_light(point(0.0f, 0.0f, -10.0f), color(1.0f, 1.0f, 1.0f));
|
|
struct shape object = shape();
|
|
struct tuple result = lighting(m, &object, light, position, eyev, normalv, false);
|
|
|
|
return tuple_equal(result, color(1.0f, 1.0f, 1.0f));
|
|
}
|
|
|
|
static bool materials_test_3(const char ** scenario)
|
|
{
|
|
*scenario = "Lighting with eye opposite surface, light offset 45 degress";
|
|
|
|
struct material m = material();
|
|
struct tuple position = point(0.0f, 0.0f, 0.0f);
|
|
|
|
struct tuple eyev = vector(0.0f, 0.0f, -1.0f);
|
|
struct tuple normalv = vector(0.0f, 0.0f, -1.0f);
|
|
struct light light = point_light(point(0.0f, 10.0f, -10.0f), color(1.0f, 1.0f, 1.0f));
|
|
struct shape object = shape();
|
|
struct tuple result = lighting(m, &object, light, position, eyev, normalv, false);
|
|
|
|
return tuple_equal(result, color(0.7364f, 0.7364f, 0.7364f));
|
|
}
|
|
|
|
static bool materials_test_4(const char ** scenario)
|
|
{
|
|
*scenario = "Lighting with eye in the path of the reflection vector";
|
|
|
|
struct material m = material();
|
|
struct tuple position = point(0.0f, 0.0f, 0.0f);
|
|
|
|
struct tuple eyev = vector(0.0f, -0.7071067811865476, -0.7071067811865476);
|
|
struct tuple normalv = vector(0.0f, 0.0f, -1.0f);
|
|
struct light light = point_light(point(0.0f, 10.0f, -10.0f), color(1.0f, 1.0f, 1.0f));
|
|
struct shape object = shape();
|
|
struct tuple result = lighting(m, &object, light, position, eyev, normalv, false);
|
|
|
|
return tuple_equal(result, color(1.63639, 1.63639, 1.63639));
|
|
}
|
|
|
|
static bool materials_test_5(const char ** scenario)
|
|
{
|
|
*scenario = "Lighting with the light behind the surface";
|
|
|
|
struct material m = material();
|
|
struct tuple position = point(0.0f, 0.0f, 0.0f);
|
|
|
|
struct tuple eyev = vector(0.0f, 0.0f, -1.0f);
|
|
struct tuple normalv = vector(0.0f, 0.0f, -1.0f);
|
|
struct light light = point_light(point(0.0f, 0.0f, 10.0f), color(1.0f, 1.0f, 1.0f));
|
|
struct shape object = shape();
|
|
struct tuple result = lighting(m, &object, light, position, eyev, normalv, false);
|
|
|
|
return tuple_equal(result, color(0.1f, 0.1f, 0.1f));
|
|
}
|
|
|
|
static bool materials_test_6(const char ** scenario)
|
|
{
|
|
*scenario = "Lighting with the surface in shadow";
|
|
|
|
struct material m = material();
|
|
struct tuple position = point(0.0f, 0.0f, 0.0f);
|
|
|
|
struct tuple eyev = vector(0.0f, 0.0f, -1.0f);
|
|
struct tuple normalv = vector(0.0f, 0.0f, -1.0f);
|
|
struct light light = point_light(point(0.0f, 0.0f, -10.0f), color(1.0f, 1.0f, 1.0f));
|
|
bool in_shadow = true;
|
|
|
|
struct shape object = shape();
|
|
struct tuple result = lighting(m, &object, light, position, eyev, normalv, in_shadow);
|
|
|
|
return tuple_equal(result, color(0.1f, 0.1f, 0.1f));
|
|
}
|
|
|
|
static bool materials_test_7(const char ** scenario)
|
|
{
|
|
*scenario = "Lighting with a pattern applied";
|
|
|
|
struct material m = material();
|
|
|
|
struct pattern pattern = stripe_pattern(color(1.0f, 1.0f, 1.0f), color(0.0f, 0.0f, 0.0f));
|
|
m.has_pattern = true;
|
|
m.pattern = pattern;
|
|
m.ambient = 1.0f;
|
|
m.diffuse = 0.0f;
|
|
m.specular = 0.0f;
|
|
struct tuple eyev = vector(0.0f, 0.0f, -1.0f);
|
|
struct tuple normalv = vector(0.0f, 0.0f, -1.0f);
|
|
struct light light = point_light(point(0.0f, 0.0f, -10.0f), color(1.0f, 1.0f, 1.0f));
|
|
|
|
struct shape object = shape();
|
|
struct tuple c1 = lighting(m, &object, light, point(0.9f, 0.0f, 0.0f), eyev, normalv, false);
|
|
struct tuple c2 = lighting(m, &object, light, point(1.1f, 0.0f, 0.0f), eyev, normalv, false);
|
|
|
|
return
|
|
tuple_equal(c1, color(1.0f, 1.0f, 1.0f)) &&
|
|
tuple_equal(c2, color(0.0f, 0.0f, 0.0f));
|
|
}
|
|
|
|
test_t materials_tests[] = {
|
|
materials_test_0,
|
|
materials_test_1,
|
|
materials_test_2,
|
|
materials_test_3,
|
|
materials_test_4,
|
|
materials_test_5,
|
|
materials_test_6,
|
|
materials_test_7,
|
|
};
|
|
|
|
RUNNER(materials_tests)
|