#
CS184 Section 3

Modeling a Ray Tracer

Brandon Wang

February 12, 2013

Material adapted from James O'Brien, Fu-Chung Huang, Ravi Ramamoorthi, and Carlo Sequin.

Modeling a Ray Tracer

Brandon Wang

February 12, 2013

Material adapted from James O'Brien, Fu-Chung Huang, Ravi Ramamoorthi, and Carlo Sequin.

- AS1 due this Friday.
- AS2 out soon.

- Review on Rodrigues' Rotation Formula
- Ray Tracing Basics
- Worksheet (if time)

Rotate a vector around an axis:

\mathbf{R}(\theta,\vec{k})

Gets rid of Gimbal Lock

(On board)

Write a ray tracer from scratch.

Make a ray starting at your eye, through an image plane, and off into space...

Ray:

\vec{r} = \vec{a}+t\cdot\vec{d}

For now, loop over all objects, figure out if the ray intersects it. (Next week, do something smarter.)

Imagine a world of spheres only - center and radius. Intersection is if the ray comes closer than radius to sphere.

For transformations, transform the **ray** to **object** space. (This is done so you don't have to write arbitrary intersection tests, only with your primitives)

Once you do spheres, move on to boxes and triangles, and other shapes if you wish.

You've already done this! Phong illumination model. (Review old slides when implementing)

But if you **recurse**, you can do nice things.

Shoot a ray from the point of intersection to...

- Towards the light for shadows. Check if it intersects
**anything**. - Into the object for refraction using Snell's law.
- Back into the scene for reflections.
- ...And many more things.

It will be a bit more difficult to get started with this, as you start from scratch.

- Get the BSOD. (Black image output.) Start with eye position, image plane corners, and image dimension.
- Make a primitive shape (sphere, triangle, or even circle). Write the ray-primitive intersection, but make it return some color for intersection. (Don't write the Phong stuff yet - make sure your geometry is right).
- Transform the primitive (scale, rotate, translate, etc). Make sure your rays are being transformed correctly
- Phong illumination model
- Shadows
- Acceleration structures (Next week)
- Fancy stuff (Your own leisure)

I've heard that this is useful.