T5 Light Source and the Cornell Box (MS5)

Add emitted() method in class material

add the virtual method emitted() in the abstract class material in material.h

class material {
  public:
    virtual ~material() = default;

    // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    virtual color emitted(double u, double v, const point3& p) const {
        return color(0,0,0);
    }
    // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


    virtual bool scatter(
        const ray& r_in, const hit_record& rec, color & attenuation, ray& scattered
    ) const {
        return false;
    }
};

Add Emissive Material

Add a new emissive diffuse_light material at the end of material.h

Add Background Colour to class camera

Add a public color background in class camera in camera.h

Revise the ray_color() function of the camera class to return the background color if ray hits nothing.

Turn Objects into Lights

Add a simple light scene in main.cpp.

As we skipped the perlin noise part, we are still using the earth map texture here.

Build and Run

If successful, you are going to see the following image

Build the Cornell Box

Finally, we can set up the well-known cornell box

Build and Run

Build your programme, if successful, run your programme from the powershell terminal.

The following is my command:

The output message from Mesuare-Command shows that it takes nearly 2 minutes to finish on my laptop

The following is the output image, we can see a lot of noise in the image due to undersampling.

Last updated