Skip to main content

Beyond Ray tracer - Part 2

In my previous post I updated the render to allow perspective projection.

This time I will move forward, and introduce 3 important updates:

The construction of the Cornell Box


Fortunately the Renderer already provides functionality to create and display meshes. From this, I have created 2 base objects, A box and Plane. Both objects are of a unit size.

The Use of materials


Making proper "realistic" ray tracer involves more than having objects with color. I have created a new structure called Material, containing additional properties, like Specular power, and Specular strength.
In the following posts I will extend the material to include other properties, like BRDF, used to provide a more accurate physical light simulation.

The result is a Cornell Box, only accounting for Diffuse and Specular components. Note that this box doesn't have the dimensions, or material properties of the official Cornell Box.

Direct Lighting in a Cornell Box

Depth render of the Cornell Box

Indirect Light

If you have noticed in the screenshot, the areas in shadows are completely black. It happens because the light coming from the light source is blocked by the objects in the scene. Then, why in real life can you actually see what's behind the objects?

That's the Indirect Light. Defined basically as the light hitting the surfaces after it has bounced from other objects. Depending on the properties of the material, some light rays may be reflected, or absorbed.

Light bouncing on surfaces


In the real world, the light hitting a surface (what our eye perceive) comes from the contribution of an infinite number of light rays hitting that surface point in an infinite number of directions.

In CG terms, the light comes from all the possible rays forming a hemisphere aligned to the surface normal (As seen in the image below)


So, the equation defining the light on that specific point (Reflectance Equation) is defined as the integral (sum) of all light rays hitting that point (coming from infinite directions).

Of course, in computer terms we can't calculate the infinite rays hitting that point on the surface, and this for all points in the image. That's why we will use discrete methods to calculate the Radiance on that surface point.


In our first attempt, we will take a fixed number of rays (3) coming from randomly defined directions, average the Radiance from this rays, and add them to the Direct Lighting.

One thing to keep in mind is that the radiance from these rays has to be calculated as well. This means in computational terms "Recursion". For each ray, we calculate 3 more rays, and for each of these rays, we calculate 3 more. For simplicity we will do 4 bounces (or 4 rays deep).


1 Light, 3 Rays - 4 Bounces in a Cornell Box

The result provides a more realistic representation of the scene inside the box.
Notice that the image has plenty of noise. This is the result of using a discrete number of shadows. The situation can be improved by using an increased number of Rays.

1 Light, 10 Rays - 4 Bounces in a Cornell Box

Although quality has drastically increase, Render times increased as well. Usually exponentially.
Several methods for real time Ray tracing use a denoise filter to remove noise in the image (We will go through it later).
The image render using 10 rays took approximately 1 minute (A bit far from real time ray tracing), but as mentioned in previous posts, the Renderer is running completely in cpu in a single process without any optimizations (BVH, intrinsics, etc)

Comments