CS 184: COMPUTER GRAPHICS

Warm-up Exercise:

Given a directional white light source (sun) sending 3 trillion photons per second per mm2

shining at an angle of 60 degrees (measured against the normal vector) on to a cyan-colored lacquered surface

with those specifications:    color = (0.2  1.0  0.7),  ka = kd = 0.2,      ks = 0.8,      ksp = 75,      ksm = 0.6;

the surface is in an environment of yellow ambient light:    color = (1.0  1.0  0.0),    I =  0.4*1012 photons / s / mm2.

Calculate the intensities of the (r,g,b) components sent towards an eye located in direction of the ideally reflected rays.

Ieye, r = _____ ;      Ieye, g = _____ ;      Ieye, b = _____ .



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

Lecture #9 -- Wed 2/16/2011.

Collect Take-Home Exam

Discuss last page of it, because it is important for ...

Rendering by Ray-Tracing (cont.)

The most important difference to ray-casting are the reflected or refracted secondary rays.

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
to 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.

Reflection and refraction may happen simultaneously (splitting the "energy" of the incoming beam),
and creating TWO secondary rays. 
Physiscs (or the Schlick approximation) tells us how the energy of a light beam is split into the two components.
In ray-tracing, the contributions of the two secondary rays are combined with an appropriate weighting factor.

Limit Recursive Calls 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.

Illumination/Shadow Rays

For each surface point hit by any viewing ray (also for secondary, ternary ...),
determine what lights are directly visible from there, and what the total illumination is at this point.

SOLUTIONS TO THE ABOVE PROBLEM:

Calculate the diffusely reflected components:

I'd   = (  Ia + Id*cos(inc.angle) ) * kd * (r,g,b):
I'dR = (  0.2   +  1 * 0.5   )    *   0.2    *  (0.2)  = 0.028 
*1012 photons / s / mm2.
I'dG = (  0.2
   +  1 * 0.5   )    *   0.2    *  (1.0)  = 0.14    *1012 photons / s / mm2.
I'dB = (  0.0   +  1 * 0.5   )    *   0.2    *  (0.7)  = 0.07    *1012 photons / s / mm2.

Calculate the speculalrly reflected component:

I's   = Id  * ks * (Phong.Factor) * (adjusted color):
I'sR = 1  * 0.8  *       (1.0)          * (0.6*0.2 + 0.4*1.0)  = 0.416  *1012 photons / s / mm2.
I'sG = 1  * 0.8  *       (1.0)          * (0.6*1.0 + 0.4*1.0)  = 0.8      *1012 photons / s / mm2.
I'sB = 1  * 0.8  *       (1.0)          * (0.6*0.7 + 0.4*1.0)  = 0.656  *1012 photons / s / mm2.

Sum up the components:

I'totalR  = 0.444  *1012 photons / s / mm2.
I'totalG  = 0.94    *1012 photons / s / mm2.
I'totalB  = 0.663  *1012 photons / s / mm2.

This kind of computation has to be done by your raytracer every time it hits a surface !


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].

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


Rotations around arbitrary axes in 3D  deserve some extra attention
They are useful for building kinematic scenes, e.g., with wheels spinning around skewed axes.
3 conceptual approaches:

1.)  Classical approach: build a compound transformation in the following way:
--  move the rotating object so that its rotation axis goes through origin;
--  turn rotation axis into the z-axis (in a 2-step rotation around z-axis and y-axis);
--  apply the desired rotation around the current z-axis;
--  rotate the axis back to its former orientation (inverse of the 2 rotations in second step);
--  move object back to its original position (inverse of original translation).

2.)  Another way to achieve the above effect is to use the "change of basis" matrix.
Define a local coordinate system with its z-axis aligned with the desired rotation axis.
Do a coordinate transform that expresses the world coordinates in this new coordinate system,
-- in which the desired rotation can be done easily (around the z-axis).
(This can be achieved with a matrix that describes the X-, Y-, Z- axis unit vectors as the first 3 columns,
and the coordinates xO, yO, zO of the origin as the fourth.)
After doing the desired rotation, do a change of basis back to the old coordinate system.

3.)  A third way is to use vector algebra to decompose the vector from the origin to the point to be transformed
into two components: one parallel to the rotation axis, and the other perpendicular to it.
Only that second component needs to be rotated, and this can be done in a plane perpendicular to the rotation axis.
The overall transformation matrix then results from a composition of these vector components (see lab notes).

Mathematically, this results in the following formulation (assuming  is a unit-length axis through the origin):
First, create the matrix A which is the linear transformation that computes the cross product of the vector a with any other vector, v.

a x v =
ayvz - azvy
azvx - axvz
axvy - ayvx
=
0 -az ay
az 0 -ax
-ay ax 0
vx
vy
vz
= Av, with A =
0 -az ay
az 0 -ax
-ay ax 0

Now, the rotation matrix can be written in terms of A as:   Q = eAb = I + A sin(b) + A2 [1 - cos(b)]    
-- This is also known as Rodrigues Formula.

The framework that the TAs are building will do all this work for you ! 
( later in the course: Quaternions!).


SVD still works the same way: i.e., any arbitrary affine 3D transformation can also be expressed as a compound matrix of pure rotations and non-uniform scalings.
The  eigenvectors of a matrix M still correspond to those vectors that do not change direction when M is applied,
   (e.g. vectors parallel to the rotation axis when M is an arbitrary 3D rotation).


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].
An intuitive explanation why this makes some sense (Thanks to Jimmy Andrews):
Let's assume that M is the compound matrix that inserts a leaf-node into WORLD.
Doing an SVD on that Matrix will decompose it into the form R1*S*R2.
The inverse of a compound matrix:  (A*B*C)-1 = C-1*B-1*A-1      ===>   Thus,  M-1 = R2-1*S-1*R1-1
The transpose of a compound matrix:  (A*B*C)T = CT*BT*AT    ===>   Thus,  (M-1)T = (R1-1)T*(S-1)T*(R2-1)T = R1*(S-1)*R2
Thus,  (M-1)T leaves all rotation components untouched, but inverts the non-uniform scaling component.

More information on transforming planes and normals

The Sphere-World of Assignment #5

An inspirational sculpture by Chris Bathgate

How to move up an down this scene hierarchy:
Move rays from camera all the way to unit spheres at the leaves of the tree, do intersections there.
Then move the found intersection point and the normal at that point back up to the WORLD coordinate system to cast secondary rays.
Need to calculate proper reflection and refraction angles -- and from those: the direction vectors for the secondary rays.

Later we will start moving the camera around this world, too!
==> Build a robust transformation data structure and become proficient with it.

Extension of the Scene Description format  SCD09

(sphere id
   (radius radius_float)
   (material material_id)
)

(material id
   (color  color_triple )
   (ka ka_float)     # diffuse reflection coefficient for ambient light (hack!)
   (kd kd_float)     # diffuse reflection coefficient
   (ks ks_float)     # specular reflection coefficient, aka "kr"
   (ksp ksp_float)   # specular angle fall-off
   (ksm ksm_float)   # metalness  
   (kt kt_float)     # transmission coefficient
   (ktn ktn_float)   # refractive index
)

(camera id
   (perspective  0|1 )   # (perspective 0) means parallel projection
   (l l_float)           # left   boundary of window in the image/near-clipping plane
   (r r_float)
           # right  boundary of window in the image/near-clipping plane
   (b b_float)           # bottom boundary of window in the image/near-clipping plane
   (t t_float)           # top    boundary of window in the image/near-clipping plane
   (n n_float)           # sets the -z coordinate of the image plane, and of the near-clipping plane
   (f f_float)           # sets the far clipping plane; this is typically NOT used for raytracing.
)

(light id
   (type  lighttype_flag)
   (color  color_triple )
   (falloff  falloff_float)                 # falloff exponent for point- and spot-lights
   (deaddistance  deaddistance_float)       # dead_distance  for point- and spot-lights
   (angularfalloff  angularfalloff_float)   # exponent on cosine for spot-lights
         # by default localized lights are positioned at (0,0,0)
)        # and directed lights are shining in the direction (0,0,-1).


Reading Assignments:

Study: ( i.e., try to understand fully, so that you can answer questions on an exam): 
Shirley: [ 2nd Ed: Ch 6.2-6.5; Ch 9.1-9.2; Ch 10.1-10.8 ] 
Shirley: { 3rd Ed: 4.1-4.9; Ch 6.2-6.5;  Ch 10.1-10.2; 13.1-13.2 }


Take-Home-Exam due:  Wednesday 2/16 start of class.

Programming Assignment #4: To be done individually; due (electronically submitted) before Sunday 2/20, 11:00pm.
NOTE the EXTENDED DEADLINE, because of the Take-Home Exam.

Programming Assignment #5: To be done individually; due (electronically submitted) before Saturday 2/26, 11:00pm.


PREVIOUS < - - - - > CS 184 HOME < - - - - > CURRENT < - - - - > NEXT
Page Editor: Carlo H. Séquin