From af86494d89e0fbfb06b78e378d6f413296f24ce1 Mon Sep 17 00:00:00 2001 From: Faerbit Date: Sat, 13 Jun 2020 22:02:57 +0200 Subject: [PATCH] Add cornell box; move camera creation to scene setup. --- main.cpp | 81 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 67 insertions(+), 14 deletions(-) diff --git a/main.cpp b/main.cpp index e2cda12..a5bc288 100644 --- a/main.cpp +++ b/main.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #define LODEPNG_NO_COMPILE_DECODER #include "lodepng.h" @@ -17,6 +18,7 @@ #include "sphere.h" #include "moving_sphere.h" #include "camera.h" +#include "aarect.h" Color ray_color(const Ray& r, const Color& background, const Hittable& world, int depth) { hit_record rec; @@ -42,7 +44,7 @@ Color ray_color(const Ray& r, const Color& background, const Hittable& world, in return (1.0 - t) * Color(1.0, 1.0, 1.0) + t * Color(0.5, 0.7, 1.0);*/ } -Bvh_node setup_random_scene(const int sph_i) { +std::pair setup_random_scene(const int sph_i, const double aspect_ratio) { Hittable_list world; //auto ground_material = std::make_shared(std::make_shared(Color(0.5, 0.5, 0.5))); @@ -96,7 +98,17 @@ Bvh_node setup_random_scene(const int sph_i) { auto material3 = std::make_shared(Color(0.7, 0.6, 0.5), 0.0); world.add(std::make_shared(Point3(4, 1, 0), 1.0, material3)); - return world.generate_bvh(0, 1); + Point3 lookfrom(13, 2, 3); + Point3 lookat(0, 0, 0); + Vec3 vup(0, 1, 0); + auto dist_to_focus = (lookfrom - lookat).length(); + //auto dist_to_focus = 10; + auto aperture = 0.1; + auto vfov = 20; + + Camera cam(lookfrom, lookat, vup, vfov, aspect_ratio, aperture, dist_to_focus, 0.0, 1.0); + + return std::make_pair(world.generate_bvh(0, 1), cam); } Hittable_list two_spheres() { @@ -115,6 +127,54 @@ Hittable_list two_spheres() { return objects; } +Hittable_list simple_light() { + Hittable_list objects; + + auto checker = std::make_shared( + std::make_shared(0.2, 0.3, 0.1), + std::make_shared(0.9, 0.9, 0.9) + ); + auto material = std::make_shared(checker); + + objects.add(std::make_shared(Point3(0, -1000, 0), 1000, material)); + objects.add(std::make_shared(Point3(0, 2, 0), 2, material)); + + auto difflight = std::make_shared(std::make_shared(4, 4, 4)); + objects.add(std::make_shared(Point3(0, 7, 0), 2, difflight)); + objects.add(std::make_shared(3, 5, 1, 3, -2, difflight)); + + return objects; +} + +std::pair cornell_box(const double aspect_ratio) { + Hittable_list objects; + + auto red = std::make_shared(std::make_shared(0.65, 0.05, 0.05)); + auto white = std::make_shared(std::make_shared(0.73, 0.73, 0.73)); + auto green = std::make_shared(std::make_shared(0.12, 0.45, 0.15)); + + auto light = std::make_shared(std::make_shared(15, 15, 15)); + + objects.add(std::make_shared(std::make_shared( 0, 555, 0, 555, 555, green))); + objects.add(std::make_shared( 0, 555, 0, 555, 0, red )); + objects.add(std::make_shared(213, 343, 227, 332, 554, light)); + objects.add(std::make_shared(std::make_shared( 0, 555, 0, 555, 0, white))); + objects.add(std::make_shared( 0, 555, 0, 555, 555, white)); + objects.add(std::make_shared(std::make_shared( 0, 555, 0, 555, 555, white))); + + Point3 lookfrom(278, 278, -800); + Point3 lookat(278, 278, 0); + Vec3 vup(0, 1, 0); + //auto dist_to_focus = (lookfrom - lookat).length(); + auto dist_to_focus = 10; + auto aperture = 0.0; + auto vfov = 40; + + Camera cam(lookfrom, lookat, vup, vfov, aspect_ratio, aperture, dist_to_focus, 0.0, 1.0); + + return std::make_pair(objects, cam); +} + struct render_tile { int start_x; int start_y; @@ -142,21 +202,14 @@ int main() { //const int sph_i = 3; //const int sph_i = 5; - const int sph_i = 7; + //const int sph_i = 7; //const int sph_i = 11; - auto world = setup_random_scene(sph_i); - //auto world = two_spheres(); + //auto [world, camera] = setup_random_scene(sph_i, aspect_ratio); + //auto [world, camera] = two_spheres(aspect_ratio); + //auto [world, camera] = simple_light(aspect_ratio); + auto [world, camera] = cornell_box(aspect_ratio); - Point3 lookfrom(13, 2, 3); - Point3 lookat(0, 0, 0); - Vec3 vup(0, 1, 0); - //auto dist_to_focus = (lookfrom - lookat).length(); - auto dist_to_focus = 10; - auto aperture = 0.1; - //auto aperture = 0.0; - - Camera cam(lookfrom, lookat, vup, 20, aspect_ratio, aperture, dist_to_focus, 0.0, 1.0); const Color background(0, 0, 0); std::atomic queue_counter;