Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yumcyaWiz committed Nov 21, 2021
1 parent 96d5a80 commit c5c8cbe
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 445 deletions.
144 changes: 3 additions & 141 deletions examples/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,146 +4,8 @@
#include "image.h"
#include "integrator.h"
#include "photon_map.h"
#include "primitive.h"
#include "scene.h"

// cornellbox
void cornellboxScene(Scene& scene) {
const auto white = std::make_shared<Lambert>(Vec3f(0.8));
const auto red = std::make_shared<Lambert>(Vec3f(0.8, 0.05, 0.05));
const auto green = std::make_shared<Lambert>(Vec3f(0.05, 0.8, 0.05));

const auto floor =
std::make_shared<Plane>(Vec3f(0), Vec3f(0, 0, 5.592), Vec3f(5.56, 0, 0));
const auto rightWall =
std::make_shared<Plane>(Vec3f(0), Vec3f(0, 5.488, 0), Vec3f(0, 0, 5.592));
const auto leftWall = std::make_shared<Plane>(
Vec3f(5.56, 0, 0), Vec3f(0, 0, 5.592), Vec3f(0, 5.488, 0));
const auto ceil = std::make_shared<Plane>(
Vec3f(0, 5.488, 0), Vec3f(5.56, 0, 0), Vec3f(0, 0, 5.592));
const auto backWall = std::make_shared<Plane>(
Vec3f(0, 0, 5.592), Vec3f(0, 5.488, 0), Vec3f(5.56, 0, 0));

const auto shortBox1 = std::make_shared<Plane>(
Vec3f(1.3, 1.65, 0.65), Vec3f(-0.48, 0, 1.6), Vec3f(1.6, 0, 0.49));
const auto shortBox2 = std::make_shared<Plane>(
Vec3f(2.9, 0, 1.14), Vec3f(0, 1.65, 0), Vec3f(-0.5, 0, 1.58));
const auto shortBox3 = std::make_shared<Plane>(
Vec3f(1.3, 0, 0.65), Vec3f(0, 1.65, 0), Vec3f(1.6, 0, 0.49));
const auto shortBox4 = std::make_shared<Plane>(
Vec3f(0.82, 0, 2.25), Vec3f(0, 1.65, 0), Vec3f(0.48, 0, -1.6));
const auto shortBox5 = std::make_shared<Plane>(
Vec3f(2.4, 0, 2.72), Vec3f(0, 1.65, 0), Vec3f(-1.58, 0, -0.47));

const auto tallBox1 = std::make_shared<Plane>(
Vec3f(4.23, 3.30, 2.47), Vec3f(-1.58, 0, 0.49), Vec3f(0.49, 0, 1.59));
const auto tallBox2 = std::make_shared<Plane>(
Vec3f(4.23, 0, 2.47), Vec3f(0, 3.3, 0), Vec3f(0.49, 0, 1.59));
const auto tallBox3 = std::make_shared<Plane>(
Vec3f(4.72, 0, 4.06), Vec3f(0, 3.3, 0), Vec3f(-1.58, 0, 0.5));
const auto tallBox4 = std::make_shared<Plane>(
Vec3f(3.14, 0, 4.56), Vec3f(0, 3.3, 0), Vec3f(-0.49, 0, -1.6));
const auto tallBox5 = std::make_shared<Plane>(
Vec3f(2.65, 0, 2.96), Vec3f(0, 3.3, 0), Vec3f(1.58, 0, -0.49));

const auto light_shape = std::make_shared<Plane>(
Vec3f(3.43, 5.486, 2.27), Vec3f(0, 0, 1.05), Vec3f(-1.3, 0, 0));
const auto light =
std::make_shared<AreaLight>(Vec3f(34, 19, 10), light_shape);

scene.addPrimitive(Primitive(floor, white));
scene.addPrimitive(Primitive(rightWall, red));
scene.addPrimitive(Primitive(leftWall, green));
scene.addPrimitive(Primitive(ceil, white));
scene.addPrimitive(Primitive(backWall, white));
scene.addPrimitive(Primitive(shortBox1, white));
scene.addPrimitive(Primitive(shortBox2, white));
scene.addPrimitive(Primitive(shortBox3, white));
scene.addPrimitive(Primitive(shortBox4, white));
scene.addPrimitive(Primitive(shortBox5, white));
scene.addPrimitive(Primitive(tallBox1, white));
scene.addPrimitive(Primitive(tallBox2, white));
scene.addPrimitive(Primitive(tallBox3, white));
scene.addPrimitive(Primitive(tallBox4, white));
scene.addPrimitive(Primitive(tallBox5, white));
scene.addPrimitive(Primitive(light_shape, white, light));
}

// cornellbox with mirror sphere
void cornellboxMirrorScene(Scene& scene) {
const auto white = std::make_shared<Lambert>(Vec3f(0.8));
const auto red = std::make_shared<Lambert>(Vec3f(0.8, 0.05, 0.05));
const auto green = std::make_shared<Lambert>(Vec3f(0.05, 0.8, 0.05));
const auto mirror = std::make_shared<Mirror>(Vec3f(0.9));

const auto floor =
std::make_shared<Plane>(Vec3f(0), Vec3f(0, 0, 5.592), Vec3f(5.56, 0, 0));
const auto rightWall =
std::make_shared<Plane>(Vec3f(0), Vec3f(0, 5.488, 0), Vec3f(0, 0, 5.592));
const auto leftWall = std::make_shared<Plane>(
Vec3f(5.56, 0, 0), Vec3f(0, 0, 5.592), Vec3f(0, 5.488, 0));
const auto ceil = std::make_shared<Plane>(
Vec3f(0, 5.488, 0), Vec3f(5.56, 0, 0), Vec3f(0, 0, 5.592));
const auto backWall = std::make_shared<Plane>(
Vec3f(0, 0, 5.592), Vec3f(0, 5.488, 0), Vec3f(5.56, 0, 0));

const auto smallSphere =
std::make_shared<Sphere>(Vec3f(1.5f, 1.0f, 1.5), 1.0f);
const auto bigSphere =
std::make_shared<Sphere>(Vec3f(3.75f, 1.5f, 3.5f), 1.5f);

const auto light_shape = std::make_shared<Plane>(
Vec3f(3.43, 5.486, 2.27), Vec3f(0, 0, 1.05), Vec3f(-1.3, 0, 0));
const auto light =
std::make_shared<AreaLight>(Vec3f(34, 19, 10), light_shape);

scene.addPrimitive(Primitive(floor, white));
scene.addPrimitive(Primitive(rightWall, red));
scene.addPrimitive(Primitive(leftWall, green));
scene.addPrimitive(Primitive(ceil, white));
scene.addPrimitive(Primitive(backWall, white));
scene.addPrimitive(Primitive(smallSphere, mirror));
scene.addPrimitive(Primitive(bigSphere, mirror));
scene.addPrimitive(Primitive(light_shape, white, light));
}

void cornellboxGlassScene(Scene& scene) {
const auto white = std::make_shared<Lambert>(Vec3f(0.8));
const auto red = std::make_shared<Lambert>(Vec3f(0.8, 0.05, 0.05));
const auto green = std::make_shared<Lambert>(Vec3f(0.05, 0.8, 0.05));
const auto glass = std::make_shared<Glass>(Vec3f(0.99), 1.5f);

const auto floor =
std::make_shared<Plane>(Vec3f(0), Vec3f(0, 0, 5.592), Vec3f(5.56, 0, 0));
const auto rightWall =
std::make_shared<Plane>(Vec3f(0), Vec3f(0, 5.488, 0), Vec3f(0, 0, 5.592));
const auto leftWall = std::make_shared<Plane>(
Vec3f(5.56, 0, 0), Vec3f(0, 0, 5.592), Vec3f(0, 5.488, 0));
const auto ceil = std::make_shared<Plane>(
Vec3f(0, 5.488, 0), Vec3f(5.56, 0, 0), Vec3f(0, 0, 5.592));
const auto backWall = std::make_shared<Plane>(
Vec3f(0, 0, 5.592), Vec3f(0, 5.488, 0), Vec3f(5.56, 0, 0));

const auto smallSphere =
std::make_shared<Sphere>(Vec3f(1.5f, 1.0f, 1.5), 1.0f);
const auto bigSphere =
std::make_shared<Sphere>(Vec3f(3.75f, 1.5f, 3.5f), 1.5f);

const auto light_shape = std::make_shared<Plane>(
Vec3f(3.43, 5.486, 2.27), Vec3f(0, 0, 1.05), Vec3f(-1.3, 0, 0));
const auto light =
std::make_shared<AreaLight>(Vec3f(34, 19, 10), light_shape);

scene.addPrimitive(Primitive(floor, white));
scene.addPrimitive(Primitive(rightWall, red));
scene.addPrimitive(Primitive(leftWall, green));
scene.addPrimitive(Primitive(ceil, white));
scene.addPrimitive(Primitive(backWall, white));
scene.addPrimitive(Primitive(smallSphere, glass));
scene.addPrimitive(Primitive(bigSphere, glass));
scene.addPrimitive(Primitive(light_shape, white, light));
}

int main() {
const int width = 512;
const int height = 512;
Expand All @@ -154,15 +16,15 @@ int main() {
const int n_estimation_caustics = 100;
const bool final_gathering = true;
const int max_depth = 100;
const Vec3f camPos(2.78, 2.73, -9);
const Vec3f lookAt(2.78, 2.73, 2.796);
const Vec3f camPos(0, 1, 7);
const Vec3f lookAt(0, 1, 0);

Image image(width, height);

const Camera camera(camPos, normalize(lookAt - camPos), 0.25 * PI);

Scene scene;
cornellboxGlassScene(scene);
scene.loadModel("CornellBox-Original.obj");
scene.build();

// photon tracing and build photon map
Expand Down
6 changes: 0 additions & 6 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ target_link_libraries(test_image PRIVATE pm)
add_executable(test_camera "test_camera.cpp")
target_link_libraries(test_camera PRIVATE pm)

add_executable(test_sphere "test_sphere.cpp")
target_link_libraries(test_sphere PRIVATE pm)

add_executable(test_plane "test_plane.cpp")
target_link_libraries(test_plane PRIVATE pm)

add_executable(test_intersector "test_intersector.cpp")
target_link_libraries(test_intersector PRIVATE pm)

Expand Down
19 changes: 2 additions & 17 deletions tests/test_intersector.cpp
Original file line number Diff line number Diff line change
@@ -1,31 +1,16 @@
#include "camera.h"
#include "image.h"
#include "primitive.h"
#include "scene.h"

int main() {
const int width = 512;
const int height = 512;

const auto sphere_shape = std::make_shared<Sphere>(Vec3f(0, 1, 0), 1.0f);
const auto sphere2_shape = std::make_shared<Sphere>(Vec3f(-1, 1, -1), 1.0f);
const auto sphere3_shape = std::make_shared<Sphere>(Vec3f(1, 1, 1), 1.0f);
const auto floor_shape = std::make_shared<Plane>(
Vec3f(5, 0, -5), Vec3f(-10, 0, 0), Vec3f(0, 0, 10));

const Primitive floor(floor_shape, nullptr);
const Primitive sphere(sphere_shape, nullptr);
const Primitive sphere2(sphere2_shape, nullptr);
const Primitive sphere3(sphere3_shape, nullptr);

Scene scene;
scene.addPrimitive(floor);
scene.addPrimitive(sphere);
scene.addPrimitive(sphere2);
scene.addPrimitive(sphere3);
scene.loadModel("CornellBox-Original.obj");
scene.build();

Camera camera(Vec3f(0, 1, 5), Vec3f(0, 0, -1));
Camera camera(Vec3f(0, 1, 7), Vec3f(0, 0, -1), 0.25f * PI);

Image image(width, height);
for (int i = 0; i < height; ++i) {
Expand Down
147 changes: 3 additions & 144 deletions tests/test_path_tracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,160 +4,19 @@
#include "image.h"
#include "integrator.h"
#include "photon_map.h"
#include "primitive.h"
#include "scene.h"

// cornellbox
void cornellboxScene(Scene& scene) {
const auto white = std::make_shared<Lambert>(Vec3f(0.8));
const auto red = std::make_shared<Lambert>(Vec3f(0.8, 0.05, 0.05));
const auto green = std::make_shared<Lambert>(Vec3f(0.05, 0.8, 0.05));

const auto floor =
std::make_shared<Plane>(Vec3f(0), Vec3f(0, 0, 5.592), Vec3f(5.56, 0, 0));
const auto rightWall =
std::make_shared<Plane>(Vec3f(0), Vec3f(0, 5.488, 0), Vec3f(0, 0, 5.592));
const auto leftWall = std::make_shared<Plane>(
Vec3f(5.56, 0, 0), Vec3f(0, 0, 5.592), Vec3f(0, 5.488, 0));
const auto ceil = std::make_shared<Plane>(
Vec3f(0, 5.488, 0), Vec3f(5.56, 0, 0), Vec3f(0, 0, 5.592));
const auto backWall = std::make_shared<Plane>(
Vec3f(0, 0, 5.592), Vec3f(0, 5.488, 0), Vec3f(5.56, 0, 0));

const auto shortBox1 = std::make_shared<Plane>(
Vec3f(1.3, 1.65, 0.65), Vec3f(-0.48, 0, 1.6), Vec3f(1.6, 0, 0.49));
const auto shortBox2 = std::make_shared<Plane>(
Vec3f(2.9, 0, 1.14), Vec3f(0, 1.65, 0), Vec3f(-0.5, 0, 1.58));
const auto shortBox3 = std::make_shared<Plane>(
Vec3f(1.3, 0, 0.65), Vec3f(0, 1.65, 0), Vec3f(1.6, 0, 0.49));
const auto shortBox4 = std::make_shared<Plane>(
Vec3f(0.82, 0, 2.25), Vec3f(0, 1.65, 0), Vec3f(0.48, 0, -1.6));
const auto shortBox5 = std::make_shared<Plane>(
Vec3f(2.4, 0, 2.72), Vec3f(0, 1.65, 0), Vec3f(-1.58, 0, -0.47));

const auto tallBox1 = std::make_shared<Plane>(
Vec3f(4.23, 3.30, 2.47), Vec3f(-1.58, 0, 0.49), Vec3f(0.49, 0, 1.59));
const auto tallBox2 = std::make_shared<Plane>(
Vec3f(4.23, 0, 2.47), Vec3f(0, 3.3, 0), Vec3f(0.49, 0, 1.59));
const auto tallBox3 = std::make_shared<Plane>(
Vec3f(4.72, 0, 4.06), Vec3f(0, 3.3, 0), Vec3f(-1.58, 0, 0.5));
const auto tallBox4 = std::make_shared<Plane>(
Vec3f(3.14, 0, 4.56), Vec3f(0, 3.3, 0), Vec3f(-0.49, 0, -1.6));
const auto tallBox5 = std::make_shared<Plane>(
Vec3f(2.65, 0, 2.96), Vec3f(0, 3.3, 0), Vec3f(1.58, 0, -0.49));

const auto light_shape = std::make_shared<Plane>(
Vec3f(3.43, 5.486, 2.27), Vec3f(0, 0, 1.05), Vec3f(-1.3, 0, 0));
const auto light =
std::make_shared<AreaLight>(Vec3f(34, 19, 10), light_shape);

scene.addPrimitive(Primitive(floor, white));
scene.addPrimitive(Primitive(rightWall, red));
scene.addPrimitive(Primitive(leftWall, green));
scene.addPrimitive(Primitive(ceil, white));
scene.addPrimitive(Primitive(backWall, white));
scene.addPrimitive(Primitive(shortBox1, white));
scene.addPrimitive(Primitive(shortBox2, white));
scene.addPrimitive(Primitive(shortBox3, white));
scene.addPrimitive(Primitive(shortBox4, white));
scene.addPrimitive(Primitive(shortBox5, white));
scene.addPrimitive(Primitive(tallBox1, white));
scene.addPrimitive(Primitive(tallBox2, white));
scene.addPrimitive(Primitive(tallBox3, white));
scene.addPrimitive(Primitive(tallBox4, white));
scene.addPrimitive(Primitive(tallBox5, white));
scene.addPrimitive(Primitive(light_shape, white, light));
}

// cornellbox with mirror sphere
void cornellboxMirrorScene(Scene& scene) {
const auto white = std::make_shared<Lambert>(Vec3f(0.8));
const auto red = std::make_shared<Lambert>(Vec3f(0.8, 0.05, 0.05));
const auto green = std::make_shared<Lambert>(Vec3f(0.05, 0.8, 0.05));
const auto mirror = std::make_shared<Mirror>(Vec3f(0.9));

const auto floor =
std::make_shared<Plane>(Vec3f(0), Vec3f(0, 0, 5.592), Vec3f(5.56, 0, 0));
const auto rightWall =
std::make_shared<Plane>(Vec3f(0), Vec3f(0, 5.488, 0), Vec3f(0, 0, 5.592));
const auto leftWall = std::make_shared<Plane>(
Vec3f(5.56, 0, 0), Vec3f(0, 0, 5.592), Vec3f(0, 5.488, 0));
const auto ceil = std::make_shared<Plane>(
Vec3f(0, 5.488, 0), Vec3f(5.56, 0, 0), Vec3f(0, 0, 5.592));
const auto backWall = std::make_shared<Plane>(
Vec3f(0, 0, 5.592), Vec3f(0, 5.488, 0), Vec3f(5.56, 0, 0));

const auto smallSphere =
std::make_shared<Sphere>(Vec3f(1.5f, 1.0f, 1.5), 1.0f);
const auto bigSphere =
std::make_shared<Sphere>(Vec3f(3.75f, 1.5f, 3.5f), 1.5f);

const auto light_shape = std::make_shared<Plane>(
Vec3f(3.43, 5.486, 2.27), Vec3f(0, 0, 1.05), Vec3f(-1.3, 0, 0));
const auto light =
std::make_shared<AreaLight>(Vec3f(34, 19, 10), light_shape);

scene.addPrimitive(Primitive(floor, white));
scene.addPrimitive(Primitive(rightWall, red));
scene.addPrimitive(Primitive(leftWall, green));
scene.addPrimitive(Primitive(ceil, white));
scene.addPrimitive(Primitive(backWall, white));
scene.addPrimitive(Primitive(smallSphere, mirror));
scene.addPrimitive(Primitive(bigSphere, mirror));
scene.addPrimitive(Primitive(light_shape, white, light));
}

void cornellboxGlassScene(Scene& scene) {
const auto white = std::make_shared<Lambert>(Vec3f(0.8));
const auto red = std::make_shared<Lambert>(Vec3f(0.8, 0.05, 0.05));
const auto green = std::make_shared<Lambert>(Vec3f(0.05, 0.8, 0.05));
const auto glass = std::make_shared<Glass>(Vec3f(0.99), 1.5f);

const auto floor =
std::make_shared<Plane>(Vec3f(0), Vec3f(0, 0, 5.592), Vec3f(5.56, 0, 0));
const auto rightWall =
std::make_shared<Plane>(Vec3f(0), Vec3f(0, 5.488, 0), Vec3f(0, 0, 5.592));
const auto leftWall = std::make_shared<Plane>(
Vec3f(5.56, 0, 0), Vec3f(0, 0, 5.592), Vec3f(0, 5.488, 0));
const auto ceil = std::make_shared<Plane>(
Vec3f(0, 5.488, 0), Vec3f(5.56, 0, 0), Vec3f(0, 0, 5.592));
const auto backWall = std::make_shared<Plane>(
Vec3f(0, 0, 5.592), Vec3f(0, 5.488, 0), Vec3f(5.56, 0, 0));

const auto smallSphere =
std::make_shared<Sphere>(Vec3f(1.5f, 1.0f, 1.5), 1.0f);
const auto bigSphere =
std::make_shared<Sphere>(Vec3f(3.75f, 1.5f, 3.5f), 1.5f);

const auto light_shape = std::make_shared<Plane>(
Vec3f(3.43, 5.486, 2.27), Vec3f(0, 0, 1.05), Vec3f(-1.3, 0, 0));
const auto light =
std::make_shared<AreaLight>(Vec3f(34, 19, 10), light_shape);

scene.addPrimitive(Primitive(floor, white));
scene.addPrimitive(Primitive(rightWall, red));
scene.addPrimitive(Primitive(leftWall, green));
scene.addPrimitive(Primitive(ceil, white));
scene.addPrimitive(Primitive(backWall, white));
scene.addPrimitive(Primitive(smallSphere, glass));
scene.addPrimitive(Primitive(bigSphere, glass));
scene.addPrimitive(Primitive(light_shape, white, light));
}

int main() {
const int width = 512;
const int height = 512;
const int n_samples = 10000;
const int n_samples = 100;
const int max_depth = 100;
const Vec3f camPos(2.78, 2.73, -9);
const Vec3f lookAt(2.78, 2.73, 2.796);

Image image(width, height);

const Camera camera(camPos, normalize(lookAt - camPos), 0.25 * PI);
Camera camera(Vec3f(0, 1, 7), Vec3f(0, 0, -1), 0.25 * PI);

Scene scene;
cornellboxGlassScene(scene);
scene.loadModel("CornellBox-Original.obj");
scene.build();

// photon tracing and build photon map
Expand Down
Loading

0 comments on commit c5c8cbe

Please sign in to comment.