Tip:
Highlight text to annotate it
X
In this segment, we're going to consider the core algorithm of
raytracing, which includes shadows and reflections: first,
shadows. I've drawn my usual diagram with the camera, the virtual
viewpoint, the virtual screen, and the objects. I've added a light
source. So I shoot a ray from the camera to the cylinder.
And now, to find shadows, I have to shoot a ray from there towards the
light source. In this case, the shadow ray hits the light source, so
it's unblocked, and the object is therefore visible to the light
source. Here is another pixel, where my ray from my camera hits the
ground. Again, I shoot a ray towards the light source. But this time,
it hits the cylinder. Therefore, the ray to the light source is
blocked, and the object is in shadow. As simple as that.
In standard rasterization in OpenGL, this is not that simple. There is
a way to simulate this using what is known as a shadow map. First store
the depths from the light source, then store the depths from the
eye. However, it is more complicated and it can have many artifacts
associated with it. In raytracing, by contrast, you can easily compute
shadows.
However, there is a little bit of trickery involved in the sense that
you have to be able to get around certain numerical issues. Here is
what I want to do, to shoot a ray from the surface towards the light
source.
But because of numerical error -- of course I'm exaggerating in this
diagram -- the ray goes below the surface. Now I shoot a ray towards the
light source and I incorrectly say to myself it shadows itself. The
solution to this is to move a little bit toward the light source
before shooting a ray or otherwise allow a small epsilon tolerance
where you don't consider intersections.
The next component deals with mirror reflections and refractions. Same
diagram again. This time I'm going to shoot a ray in the mirror
direction. Same thing for refractions, I'll shoot a ray according to
Snell's Law. And where that ray hits I will get the color of
background, and this will give me my reflection. So raytracing, in a
very simple way, is able to handle shadows and reflections.
Which brings us to Turner Whitted's recursive raytracing
algorithm. Again, the algorithm is extremely simple and fits on a
page. For each pixel, you trace the primary eye ray and you find the
intersection of that primary eye ray with the scene.
Notice the terminology I'm using here. I'm using eye rays for rays
from the eye, often called primary rays. Then you trace the secondary
ray or the shadow ray to the light sources. You may trace one shadow
ray for each light source. The color, if the shadow ray is visible,
corresponds to the illumination model in effect. For example the Blinn
Phong model and the Lambertian diffuse model. If the ray is blocked
there is no direct illumination from the light sources.
Next we trace the reflective ray and the color, notice the use of the
plus equal to operator. The color is equal to reflectivity of the
surface times the color of the reflected ray.
Here is where the recursive raytracing comes into play. Because we've
said color is equal to color plus reflectivity, times the color of the
reflected ray. To determine the color of the reflected ray you have to
go back and trace the ray.
Recursion is a great tool in computer science. It enables one to
easily express concepts that would be very difficult otherwise. But
with all recursive algorithms, we must have some guarantee that the
algorithm will stop. Reflection rays may be traced forever. Consider
especially if you have something that looks like a hall of mirrors.
To avoid this problem, we generally set a maximum recursion
depth. Like, if you've traced 5 times, you stop. Other things you
might imagine doing is set a threshold. Once the product of the
reflectivities goes below a threshold, like 0.02, you stop the
ray. Similarly, you can handle transmitted rays. If you study advanced
rendering, you'll notice that these kinds of processes involve some
notion of bias, because you're throwing away energy. And there is a
procedure known as Russian Roulette that adds the energy back in a way
that is unbiased. However we don't need to deal with it here.
So what are the effects needed for realism? We earlier in this lecture
talked about them. Soft shadows, reflections from mirror and glossy
surfaces, transparencies, water and glass inter-reflection, color
bleeding, complex illumination, natural and aerial lights.
The portions in white. That is shadows, mirror reflections,
transparency have been discussed in this lecture in the context of
recursive raytracing, and are supported by recursive raytracing.
The yellow parts, which is soft shadows from area light sources,
glossy reflections, complex illumination from natural and area
lights are not present in this standard recursive raytracing algorithm,
or what you'll implement for homework 3. However, they are possible
with simple extensions to distribution raytracing.
Finally, inter-reflections of color bleeding are hard with raytracing
but not impossible. In most renderings now-a-days are based on
raytracing or its extension to path tracing. However, this is a place
where the radiosity techniques became very popular and those are based
on finite element numerical calculations. As far as this course is
concerned, we just deal with simple recursive raytracing.