Add cornell box; move camera creation to scene setup.
This commit is contained in:
parent
d401600f1c
commit
af86494d89
81
main.cpp
81
main.cpp
@ -3,6 +3,7 @@
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <cstdio>
|
||||
#include <utility>
|
||||
|
||||
#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<Bvh_node, Camera> setup_random_scene(const int sph_i, const double aspect_ratio) {
|
||||
Hittable_list world;
|
||||
|
||||
//auto ground_material = std::make_shared<Lambertian>(std::make_shared<Solid_color>(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<Metal>(Color(0.7, 0.6, 0.5), 0.0);
|
||||
world.add(std::make_shared<Sphere>(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<Checker_texture>(
|
||||
std::make_shared<Solid_color>(0.2, 0.3, 0.1),
|
||||
std::make_shared<Solid_color>(0.9, 0.9, 0.9)
|
||||
);
|
||||
auto material = std::make_shared<Lambertian>(checker);
|
||||
|
||||
objects.add(std::make_shared<Sphere>(Point3(0, -1000, 0), 1000, material));
|
||||
objects.add(std::make_shared<Sphere>(Point3(0, 2, 0), 2, material));
|
||||
|
||||
auto difflight = std::make_shared<Diffuse_light>(std::make_shared<Solid_color>(4, 4, 4));
|
||||
objects.add(std::make_shared<Sphere>(Point3(0, 7, 0), 2, difflight));
|
||||
objects.add(std::make_shared<Xy_rect>(3, 5, 1, 3, -2, difflight));
|
||||
|
||||
return objects;
|
||||
}
|
||||
|
||||
std::pair<Hittable_list, Camera> cornell_box(const double aspect_ratio) {
|
||||
Hittable_list objects;
|
||||
|
||||
auto red = std::make_shared<Lambertian>(std::make_shared<Solid_color>(0.65, 0.05, 0.05));
|
||||
auto white = std::make_shared<Lambertian>(std::make_shared<Solid_color>(0.73, 0.73, 0.73));
|
||||
auto green = std::make_shared<Lambertian>(std::make_shared<Solid_color>(0.12, 0.45, 0.15));
|
||||
|
||||
auto light = std::make_shared<Diffuse_light>(std::make_shared<Solid_color>(15, 15, 15));
|
||||
|
||||
objects.add(std::make_shared<Flip_face>(std::make_shared<Yz_rect>( 0, 555, 0, 555, 555, green)));
|
||||
objects.add(std::make_shared<Yz_rect>( 0, 555, 0, 555, 0, red ));
|
||||
objects.add(std::make_shared<Xz_rect>(213, 343, 227, 332, 554, light));
|
||||
objects.add(std::make_shared<Flip_face>(std::make_shared<Xz_rect>( 0, 555, 0, 555, 0, white)));
|
||||
objects.add(std::make_shared<Xz_rect>( 0, 555, 0, 555, 555, white));
|
||||
objects.add(std::make_shared<Flip_face>(std::make_shared<Xy_rect>( 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<int> queue_counter;
|
||||
|
Loading…
Reference in New Issue
Block a user