86 lines
3.3 KiB
C++
86 lines
3.3 KiB
C++
#include "rayTracer.h"
|
|
#include "camera.h"
|
|
#include "hittable.h"
|
|
#include "hittableList.h"
|
|
#include "material.h"
|
|
#include "sphere.h"
|
|
|
|
int main(void) {
|
|
// World.
|
|
hittableList world;
|
|
|
|
// auto groundMaterial = make_shared<lambertian>(colour(0.1, 0.0, 0.0));
|
|
// auto centreMaterial = make_shared<lambertian>(colour(0.1, 0.2, 0.5));
|
|
// auto leftMaterial = make_shared<dielectric>(1.50);
|
|
// auto bubbleMaterial = make_shared<dielectric>(1.00 / 1.50);
|
|
// auto rightMaterial = make_shared<metal>(colour(1.0, 0.0, 0.0), 1.0);
|
|
|
|
// world.add(make_shared<sphere>(point3( 0.0, -100.5, -1.0), 100.0, groundMaterial));
|
|
// world.add(make_shared<sphere>(point3( 0.0, 0.0, -1.2), 0.5, centreMaterial));
|
|
// world.add(make_shared<sphere>(point3(-1.0, 0.0, -1.0), 0.5, leftMaterial));
|
|
// world.add(make_shared<sphere>(point3(-1.0, 0.0, -1.0), 0.4, bubbleMaterial));
|
|
// world.add(make_shared<sphere>(point3( 1.0, 0.0, -1.0), 0.5, rightMaterial));
|
|
|
|
// Code from the book.
|
|
auto ground_material = make_shared<lambertian>(colour(0.5, 0.5, 0.5));
|
|
world.add(make_shared<sphere>(point3(0,-1000,0), 1000, ground_material));
|
|
|
|
for (int a = -11; a < 11; a++) {
|
|
for (int b = -11; b < 11; b++) {
|
|
auto choose_mat = randomDouble();
|
|
point3 center(a + 0.9*randomDouble(), 0.2, b + 0.9*randomDouble());
|
|
|
|
if ((center - point3(4, 0.2, 0)).length() > 0.9) {
|
|
shared_ptr<material> sphere_material;
|
|
|
|
if (choose_mat < 0.8) {
|
|
// diffuse
|
|
auto albedo = colour::random() * colour::random();
|
|
sphere_material = make_shared<lambertian>(albedo);
|
|
world.add(make_shared<sphere>(center, 0.2, sphere_material));
|
|
} else if (choose_mat < 0.95) {
|
|
// metal
|
|
auto albedo = colour::random(0.5, 1);
|
|
auto fuzz = randomDouble(0, 0.5);
|
|
sphere_material = make_shared<metal>(albedo, fuzz);
|
|
world.add(make_shared<sphere>(center, 0.2, sphere_material));
|
|
|
|
auto center2 = center + vec3(0, randomDouble(0,.5), 0);
|
|
world.add(make_shared<sphere>(center, center2, 0.2, sphere_material));
|
|
} else {
|
|
// glass
|
|
sphere_material = make_shared<dielectric>(1.5);
|
|
world.add(make_shared<sphere>(center, 0.2, sphere_material));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
auto material1 = make_shared<dielectric>(1.5);
|
|
world.add(make_shared<sphere>(point3(0, 1, 0), 1.0, material1));
|
|
|
|
auto material2 = make_shared<lambertian>(colour(0.4, 0.2, 0.1));
|
|
world.add(make_shared<sphere>(point3(-4, 1, 0), 1.0, material2));
|
|
|
|
auto material3 = make_shared<metal>(colour(0.7, 0.6, 0.5), 0.0);
|
|
world.add(make_shared<sphere>(point3(4, 1, 0), 1.0, material3));
|
|
|
|
// Camera.
|
|
camera cam;
|
|
cam.aspectRatio = 16.0 / 9.0;
|
|
cam.imageWidth = 400;
|
|
cam.samplesPerPixel = 100;
|
|
cam.maxDepth = 50;
|
|
|
|
cam.vFieldOfView = 20;
|
|
cam.lookFrom = point3(13,2,3);
|
|
cam.lookAt = point3(0,0,0);
|
|
cam.vUp = vec3(0,1,0);
|
|
|
|
cam.defocusAngle = 0.6;
|
|
cam.focusDistance = 10;
|
|
|
|
cam.render(world);
|
|
|
|
return 0;
|
|
} |