# Question # 1:

When do chalky spheres appear as uniformly shaded (apparently flat) disks,
and when do they appear as depth-modulated 3D objects with varying brightness ?

# Problem # 2:

List some effects of real surfaces that are NOT captured by the Phong model.

PREVIOUS < - - - - > CS 184 HOME < - - - - > CURRENT < - - - - > NEXT

# Lecture #9 -- Mon 2/23/2009.

## Crucial Concepts from Last Lecture:

Ray-casting:  (Assignment #4) For each pixel on the display screen, shoot a ray from the eye into the scene and determine what it hits, and what color we should put there.
The apparant color of a particular spot in the scene depends on its surface properties, on what light illuminates it, and how the re-emitted light is transformed on the way to the eye/camera.

Types of Light Sources:   Light source models and their key parameters (SLIDE notation)

• Ambient Light (e.g., sky): Iamb, Clight (r,g,b).
• Directional Light (e.g., sun): Idir, Clight (r,g,b). -- Calculate: L.
• Point Light (e.g., candle): Ipoint, Clight (r,g,b), d0, n1. -- Calculate: L, d.
• Spot Light (e.g., stage light):  Ispot, Clight (r,g,b), d0, n1, n2. -- Calculate: L, D, d.
• Superposition Law: Calculate the effects of each light individually and sum all the resulting effects. (I.e., there is no interaction between photons).

Controling Light Intensities, Brightness:
How bright should you make those lights?  (trial and error).
What if they are too bright ?  (adjust the light; scale or clip the output intensities).

### Brightness Normalization.

Normally one tries to carefully choose lights so that the produced brightnesses fall into the range 0 to 1.0,
which is then mapped onto the, say, 256 discrete beam intensities in the CRT.
In spite of best intentions the sum of all calculated brightnesses may exceed unity; this may produce strange effects if left unchecked !
--> at the very least: clip to unity
--> better: detect this, and scale down all brightness values on object or in whole scene.

Types of Surfaces:
The two simplest, idealized surface models are:
a Lambert surface that reflects light diffusely (like the surface of chalk). When uniformly lit, its apparent brightness is independent of viewer position;
a Perfect Mirror that reflects incominng light specularly in the plane of the incident light and the surface normal, with an equal exit angle on the other side of the normal vector.

Real surfaces are a mixture of both of the above type and can be represented reasonably well with the Phong model:
Highlights are modeled as "fuzzy club" shapes, in which the intensity falls of with a suitable power of the cosine of the deviation angle from the R direction.\

## More on Surfaces

When do chalky spheres appear as uniformly shaded (apparently flat) disks ?
When do they appear as depth modulated 3D objects with varying brightness ?

Highlights in the Phong Illumination/Lighting/Surface Model: Show effect of exponent of cosine function.

Phong Highlight on flat glossy surface:
Even uniform directional light falling on a flat surface can produce non-uniform brightness, if surface is partially reflective and we use a Phong illumination model.

### Advanced Approximations of Real Surfaces:

Effects of a real surface that are NOT captured by the Phong model:

Real materials are more complicated:  Spreading of light (Phong exponent) may depend on:
-- the incident angle {Torrence Sparrow model }.
-- the color of the light {spectral behavior; different wavelenghts get absorbed/reflected differently.

Reflected and refracted images of other objects (not just lights).  ==> Raytracing to the rescue !!

# Rendering by Ray-Tracing

Raytracing (Assignment #5) When a cast ray hits a first surface, more rays may be cast from that particular location:
1.) to determine which lights are visible from that spot, and thus how much light it receives;
2.) to compose possible reflected inages;
3.) to gather refracted light;
4.) to do other more advanced stuff ...
If reflected or refracted secondary rays hit another reflective or refractive surface, then recurse!

For each surface point hit by a viewing ray, determine what lights are directly visible from there, in order to determinate the amount of illumination that this point receives.

## Reflected and Refracted Rays

If a viewing ray hits a specularly reflection surface, bounce it off in the direction of the ideal reflection angle and find out what it "sees" in that direction.

If a viewing ray hits the surface of a transparent object, refract it into the object and follow it through the object find out what it "sees" in that direction.

If a ray in an optically dense medium hits a surface under a shallow angle, it may be totally internally reflected.

In many cases, reflection and refraction may happen simulatneously (splitting the "energy" of the incoming beam), and creating TWO secondary rays.
Physiscs tells us how the energy of a light beam is split into the two components. In raytracing, the contributions of the two secondary rays are combined with the same weighting factor.

## Recursive Call to Secondary Rays

If the scene has has mostly clear transparent and shiny object, the cast rays may bifurcate at every intersection with a surface, and the number of rays thus grows exponentially!
Thus it is good to put in a cut-off limit for the recursive call to secondary rays.

A reminder about Scene Hierarchies: "Railroad Bridge" -- "Robot Arm" -- "Defective 18 Wheeler"

## 3D Scenes Need 3D Transformations

Most 3D transformation matrices can be readily be derived from the 2D versions. Add an additional row and column in all matrices to make them 4x4.
For detailed view of matrices; see  [Shirley, Chapter 6.2].

Scaling ==> trivial; just add the 3rd coordinate.

Rotation around one coordinate axis ==> just like 2D, involving only those two axes.    Cyclically move through xy, yz, zx - planes to get all three cases.
Positive rotations are CCW when looking down the corresponding rotation axis (right hand rule: thumb in axis direction ==> fingers point in positive rotation sense).
(Angles in the "matrix machinery" should be expressed in radians; at the user interface level, degrees are more convenient)
Rotations around arbitrary axes deserve some extra attention; (-- next time).

Translation -- not really a linear transform ! ==> need to resort to homogeneous coordinates again.
A shear transformation in 4-dimensional space  has the effect of a net translation in the plane w=1.

Inverse transformations are also straight forward; see  [Shirley, Chapter 6.4].

Transformation of normal vectors deserves again some extra attention. (You need that to compute the proper illumination intensities and reflection angles.)
The proper transformation matrix is the transpose of the inverse matrix, i.e., (M-1)T [Shirley, Chapter 6.2.2].