Advanced Graphics

Dr Neil Dodgson, University of Cambridge Computer Laboratory
Part II course, 1998

Lecture 1 Index
Part A: Ray tracing vs polygon scan conversion
Part B: Polygon mesh management & hardware PSC quirks
Part C: Ray tracing primitives
on to lecture 2...

1C) Ray tracing primitives

Relevant mainly to RT.

A primitive is a shape for which a ray-shape intersection routine has been written. More complex objects can be built out of the primitives. Most ray tracers will have a variety of primitives. They are limited only by the ability of the programmer to write a function to analytically intersect a ray with the surface of the shape.

Common primitives

The infinite plane is a simple object with which to intersect a ray (see Part IB notes for details). On its own it can represent boundary objects such as the ground or the sky or perhaps an infinite wall. Intersection with the infinite plane is a useful building block in a ray tracing system.

<Image: ray traced polygon> Polygon
Having the polygon as a ray tracing primitive allows a ray tracer to render anything that a PSC algorithm could. To find the intersection of a ray with a polygon, first find the intersection of the ray with the infinite plane in which the polygon lies. Then ascertain whether the intersection lies inside or outside the polygon: this is a reasonably straightforward two dimensional graphics operation.

<Image: ray traced box> Box
A box is essentially six polygons and could be ray traced as such. However, intersection with an axis-aligned box can be optimised. Any box can be axis-aligned by appropriate transformations. We can thus write a routine to intersect an arbitrary ray with an axis-aligned box and then transform the ray under consideration in exactly the same way as we transform the box which we are trying to intersect with it. This sort of idea generalises neatly to the concept of specifying any object in a convenient object coordinate system and then applying transforms to the whole object to place it at the appropriate point in the world coordinate system.

<Image: ray traced sphere> Sphere
The sphere is the simplest finite object with which to intersect a ray. Practically any ray tracing program will include the sphere as a primitive. Scaling a sphere by different amounts along the different axes will produce an ellipsoid: a squashed or stretched sphere. There is thus no need to include the ellipsoid as a primitive provided that your ray tracer contains the usual complement of transformations. (It would be a poor ray tracer if it did not!)

<Image: ray traced cylinder> Cylinder
Intersecting a ray with an infinitely long cylinder is practically as easy as intersecting one with a sphere. The tricky bit, if it can be called that, is to intersect a ray with a more useful finite length cylinder. This is achieved by intersecting the ray with the appropriate infinitely long cylinder and then ascertaining where along the cylinder the intersection lies. If it lies in the finite length in which you are interested then keep the intersection. If it does not then ignore the intersection. Note that the ray tracer used to render the accompanying image has cylinders without end caps. This is the correct result if you follow the procedure outlined in this paragraph. Adding end caps to your cylinders requires extra calculations.

<Image: ray traced cone> Cone
Cones are very like cylinders. Like the infinite cylinder, there is a simple mathematical definition of an infinite cone which makes it easy to write a ray-cone intersection algorithm. Note that a cone does not need to have a point -- it can be truncated short of its `top', as illustrated in the accompanying image. The particular ray tracer used does not add end caps to cones.

<Image: ray traced disc> Disc
The disc is not a common ray tracing primitive, but is necessary in ray tracers which implement cones and cylinders without end caps. It is handled in much the same way as the polygon. The routine to check if the intersection with the plane lies inside or outside of the disc is simpler than the equivalent routine for the polygon. In the accompanying ray traced image, the disc has been positioned so that it just catches the light -- this illustrates how specular reflection varies across a completely flat surface. The sphere, cone and torus images illustrate how specular reflection varies across three curved surfaces.

<Image: ray traced torus> Torus
Toroids are reasonably rare in real life (doughnuts and tyre inner tubes notwithstanding). They are somehow alluring to the kinds of people who implement ray tracers and, having a reasonably straightforward mathematical definition, are reasonably simple to implement. They thus appear as primitives in many ray tracers. They become more useful when combined with Constructive Solid Geometry (see Lecture 3A).

  1. Work out mathematical equations to define a plane, a sphere, an infinitely long cylinder, an infinitely long cone, and a torus. You will find it helpful to centre each primitive at the origin and to align it in a sensible way with respect to the coordinate axes. You may like to use cylindrical polar coordinates where these prove useful. As a starting point remember that a circle can be represented by the equation:x^2+y^2=r^2
  2. Work out a way to intersect a ray with each of the five primitives. You may assume that you are provided with functions to find the roots of linear, quadratic, cubic and quartic equations.

Lecture 1 Index
Part A: Ray tracing vs polygon scan conversion
Part B: Polygon mesh management & hardware PSC quirks
Part C: Ray tracing primitives
on to lecture 2...

Neil Dodgson | Advanced Graphics | Computer Laboratory

Source file: l1c.html
Page last updated on Tue Sep 8 16:01:40 BST 1998
by Neil Dodgson (