#include "rayTracer.h" #include "bvh.h" #include "camera.h" #include "hittable.h" #include "hittableList.h" #include "material.h" #include "sphere.h" #include "texture.h" void bouncingSpheres(void) { // World. hittableList world; // Code from the book. auto ground_material = make_shared(colour(0.5, 0.5, 0.5)); world.add(make_shared(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 sphere_material; if (choose_mat < 0.8) { // diffuse auto albedo = colour::random() * colour::random(); sphere_material = make_shared(albedo); world.add(make_shared(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(albedo, fuzz); world.add(make_shared(center, 0.2, sphere_material)); auto center2 = center + vec3(0, randomDouble(0,.5), 0); world.add(make_shared(center, center2, 0.2, sphere_material)); } else { // glass sphere_material = make_shared(1.5); world.add(make_shared(center, 0.2, sphere_material)); } } } } auto material1 = make_shared(1.5); world.add(make_shared(point3(0, 1, 0), 1.0, material1)); auto material2 = make_shared(colour(0.4, 0.2, 0.1)); world.add(make_shared(point3(-4, 1, 0), 1.0, material2)); auto material3 = make_shared(colour(0.7, 0.6, 0.5), 0.0); world.add(make_shared(point3(4, 1, 0), 1.0, material3)); world = hittableList(make_shared(world)); // 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); } void checkeredSpheres(void) { hittableList world; auto checker = make_shared(0.32, colour(.9, .1, .1), colour(.9, .9, .9)); world.add(make_shared(point3(0,-10, 0), 10, make_shared(checker))); world.add(make_shared(point3(0, 10, 0), 10, make_shared(checker))); camera cam; cam.aspectRatio = 16.0 / 9.0; cam.imageWidth = 800; 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; cam.render(world); } void earth(void) { auto earthTexture = make_shared("earthmap.jpg"); auto earthSurface = make_shared(earthTexture); auto globe = make_shared(point3(0, 0, 0), 2, earthSurface); camera cam; cam.aspectRatio = 16.0 / 9.0; cam.imageWidth = 800; cam.samplesPerPixel = 100; cam.maxDepth = 50; cam.vFieldOfView = 20; cam.lookFrom = point3(0,0,12); cam.lookAt = point3(0,0,0); cam.vUp = vec3(0,1,0); cam.defocusAngle = 0; cam.render(hittableList(globe)); } void funny() { auto texture = make_shared("face.png"); auto surface = make_shared(texture); auto object = make_shared(point3(0, 0, 0), 2, surface); camera cam; cam.aspectRatio = 16.0 / 9.0; cam.imageWidth = 800; cam.samplesPerPixel = 100; cam.maxDepth = 50; cam.vFieldOfView = 20; cam.lookFrom = point3(0,0,12); cam.lookAt = point3(0,0,0); cam.vUp = vec3(0,1,0); cam.defocusAngle = 0; cam.render(hittableList(object)); } int main(void) { int sceneToShow = 4; switch (sceneToShow) { case 1: bouncingSpheres(); break; case 2: checkeredSpheres(); break; case 3: earth(); break; case 4: funny(); break; } }