# T6 The Final Scene (Milestone 4)

### Set up a new scene&#x20;

Replace main() with the following

```cpp
int main() {
    hittable_list world;

    auto ground_material = make_shared<lambertian>(color(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 = random_double();
            point3 center(a + 0.9*random_double(), 0.2, b + 0.9*random_double());

            if ((center - point3(4, 0.2, 0)).length() > 0.9) {
                shared_ptr<material> sphere_material;

                if (choose_mat < 0.8) {
                    // diffuse
                    auto albedo = color::random() * color::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 = color::random(0.5, 1);
                    auto fuzz = random_double(0, 0.5);
                    sphere_material = make_shared<metal>(albedo, fuzz);
                    world.add(make_shared<sphere>(center, 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>(color(0.4, 0.2, 0.1));
    world.add(make_shared<sphere>(point3(-4, 1, 0), 1.0, material2));

    auto material3 = make_shared<metal>(color(0.7, 0.6, 0.5), 0.0);
    world.add(make_shared<sphere>(point3(4, 1, 0), 1.0, material3));

    camera cam;

    cam.aspect_ratio      = 16.0 / 9.0;
    // very slow
    // cam.image_width       = 1200;
    // cam.samples_per_pixel = 500;
    // My test setting
    cam.image_width       = 400;
    cam.samples_per_pixel = 100;
    
    cam.max_depth         = 50;
    cam.vfov     = 20;
    cam.lookfrom = point3(13,2,3);
    cam.lookat   = point3(0,0,0);
    cam.vup      = vec3(0,1,0);

    cam.defocus_angle = 0.6;
    cam.focus_dist    = 10.0;

    cam.render(world);
}
```

### Build and Run

It is slow so I am using the lower resolution for testing.

```cpp
cam.image_width       = 400;
cam.samples_per_pixel = 100;
```

Build your programme into the release version with VSCode or Visual Studio.

<figure><img src="https://3464970502-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3JUKGJZ67JX02QZdPhsy%2Fuploads%2FMRmcYBHvglgVwnKZEwAf%2F5e41d37e-0216-47ca-8dd5-09eb0b98bd3c.png?alt=media&#x26;token=5b08fc3d-17bb-4827-814e-100f2cd4a6a3" alt="" width="277"><figcaption></figcaption></figure>

On my laptop (AMD *R9-9955HX* ) , it takes about 2 minutes to run this programme with  release version while 30 minutes with the Debug version. <mark style="color:red;">**The Debug version is 15x slower.**</mark>

Again, it looks darker due to lack of Gamma correction.

<figure><img src="https://3464970502-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3JUKGJZ67JX02QZdPhsy%2Fuploads%2Ft48quITD8FL2f0Q3K6yy%2F0a4fd881-0adf-477e-a232-bc70fb944141.png?alt=media&#x26;token=0820595d-8cdd-486d-895b-5fcb35e95753" alt="" width="375"><figcaption></figcaption></figure>

It takes about 74 minutes to run the full resolution version on my laptop.

```cpp
    cam.image_width       = 1200;
    cam.samples_per_pixel = 500;
```

<figure><img src="https://3464970502-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3JUKGJZ67JX02QZdPhsy%2Fuploads%2FtorxrCuB3RBv621CN1ls%2F15a3ec3a-22e0-43e7-ba1c-9a638e7abe97.png?alt=media&#x26;token=b6d0cc4e-d7b3-47c9-9bb8-05ed1a29d2de" alt=""><figcaption></figcaption></figure>
