# Ray Tracing

#### Distribution Ray Tracing

What's wrong with

1. Beam tracing
2. Super sampling
3. Stochastic sampling

It doesn't try explicitly to put the work into the places that make the most difference.

Trying to do so we should get heuristics like

• If <xxx> is important, then put extra rays into <yyy>.

Here are a few such heuristics

Distribute carefully over

1. Reflection directions <==>
• you want better highlights.
• Put extra rays in the highlight
• How?
• Ray-trace a coarse image
• find the pixels/rays that contribute to the highlight
• Send extra rays between and near them
2. Area lights <==>
• Put extra rays at the edges of the shadows
• How?
• Ray-trace coarsely with a point light source
• determine pixels/rays that are near the edges of shadows
• Send extra rays doing a more complex lighting calculation near shadow edges
• How would you get them?
3. Time <==>
• you want motion blur.
• Concentrate on the objects that are moving
• How?
• Ray-trace coarsely for different times
• Determine pixels/rays that change between the images
• Cast extra rays there for even more times
• Average
4. Anti-aliasing
• You want better anti-aliasing
• Put extra rays where more than one primitive contributes to an object
• How?
• Ray trace coarsely
• Run an edge detector to find pixels/rays on edges
• Cast extra rays for those pixels and their neighbours.

These techniques are hard!

• Not to cast the extra rays
• But to find out where extra rays are needed.

# Modelling

## Constructive Solid Geometry (CSG)

Geometric primitives can make other geometric primitives by

1. union
2. intersection
3. subtraction

This is like sculpting.

The result of doing CSG modelling is a complex Boolean expression to be evaluated.

• Idea. Do it not on the volumes of objects but on the rays.
• Then work out the Boolean expression

E.g. Cylinder, A, with stretched cube, B, subtracted unioned with a small sphere, C.

• (A - B ) \union C
• On the ray
```    Bin    Ain     Cin     Bout     Cout     Aout
_____________________________________________________
A
____________________________________
B
_________________________
A-B
__________________
C
___________________
(A-B) \union C
___________________________```
```build the expression tree
for each CSG primitive
find entry and exit intersections
recursively evaluate the expression tree```

## Texture Mapping

#### Basic

2. Map 2D image onto primitive using a 2D affine transformation
• Simple if the surface of the primitive is flat
• otherwise, ...
3. Backwards map intersection point with ray into the image to get the surface properties

#### Normal Mapping, aka Bump Mapping

1. Start with a difference surface, defined with respect to the surface
2. Calculate the normals to the difference surface and map them onto the surface of the primitive
3. Use the mapped surface models for lighting
4. No occlusion, shadows are wrong, silhouettes are wrong, nobody notices!

#### Solid Textures

1. Solution to mapping texture onto curved surfaces
• or objects like wood or marble where we see differently oriented surfaces
2. Usually procedural