T5 Supersampling (Milestone 2)

Now we are going to cast multiple rays through a pixel to obtain better results. It is similar that you are using a mobile phone/digital camera with more number of pixel sensors to take a high-resolution picture.

This is not only important to achieve better edge renderings, but is also critial for the upcoming many-ray sampling.

T1 Add random number generation in rtweekend.h

Please add the content between

=================================

in the following code:

Make sure to put color.h after interval.h in the common header section at the end.

Generating Pixels with Multiple Samples

T2 Add a clamp() function in interval.h

Add a clamp(double x) function in interval.h to ensure all colour values are in the range of [0, 1]. It is a straightforward function to check the values and limit them into [0, 1].

Add the following clamp function to class interval:

T3 Revise color.h to use the clamp function

T4 Add two class members to the camera class

In camera.h, do the following:

  1. Add a public member samples_per_pixel.

Revise your render() function as follows

  1. Add a private member double pixel_samples_scale;

Use this variable in initialise() by adding one line

T5 Add two methods: get_ray(i,j) and sample_square()

Function camera::get_ray(i,j) obtain a ray from a subpixel.

sample_square() is doing a random sampling in that pixel.

Finally add oneline in your main()

Build And Run Your Programme

Build you programme to make sure everything is correct.

Run your programme, for example:

As we are using multiple rays per pixel, it will take much more time to generate one image.

If successful, you will see a similar result as previous, but with much smoother edges.

Last updated