Posts RSS Comments RSS Digg Technorati Blinklist Furl reddit 105 Posts and 7 Comments till now
This wordpress theme is downloaded from wordpress themes website.

Archive for September, 2013 (2013/09)

3. Transformations I: Linear Transformations (vector, matrix)

3. Transformations I: Linear Transformations. Multiple Transformations (2/14) … vectors & linear transformations (4×4 matrices)

Vector is length & direction, can be represented as 2D (dx, dy) or 3D (dx, dy, dz).  Add vectors adds components (visually attach tail to head).  Subtract vector just add the negative (visually flip direction of minus vector).  To compute the length, use pythagorean theorem.  Unit vector is vector length 1, compute by dividing the vector by its length.

Dot product A dot B = AxBx + AyBy + AzBz = cos(theta) * ||A|| * ||B||.  Theta is the angle between A and B.  ||A|| is magnitude of A.  For unit vectors, A dot B = cos(theta).  Because for unit vectors, ||A|| is 1 and ||B|| is 1.  Dot product can tell you which side of a surface something is on.  Example take the dot product of the Normal vector (to a plane) and the View vector (to the camera); the sign (greater than or less than zero) tells you if the angle is less than or greater than 90 degrees…  Using dot product (instead of a trig function such as cosine).

Cross product in 3D: A cross B gives a third vector perpendicular to A and B.  Use right-hand rule (A pointer finger, B middle, AxB thumb) for right-handed coordinate system.  A cross B = (AyBz – AzBy, AzBx – AxBz, AxBy -  AyBx).  Mnemonic: to memorize this (for fun?), I think of each component’s subscripts for A*B-A*B as going xyzxyz-(reverse of that) and you start at X for X but there’s no X in the X (same for Y & Z).  Cross product gives normal to a plane (used for lighting calculations) (typically 3D models created by 3D modeling software will have pre-computed normals saved as parameters for each vertex).

Linear transformation between two vector spaces is a map such that: L(k*A) = k*L(A) for scalar k.  L(A+B) = L(A) + L(B).  Lines are preserved.  We do linear transformations with matrices.  For 3D graphics, we use 4×4 matrices.  Today we will talk about the top three rows (not the bottom row).  Identity matrix:
(1 0 0 0)(x)   (x)
(0 1 0 0)(y) = (y)
(0 0 1 0)(z)   (z)
(0 0 0 1)(1)   (1)

Scaling (negative values causes reflection).  Translation (not a linear transformation in 3D, but it is in 4D, so we use the 4th column, which is why we have a 4×4 instead of 3×3).  Shearing (stretching, parallel lines stay parallel) by axis (eg, to shear along Z, X and Y values are altered by an amount proportional to the value of Z, without changing Z).
(Sx  Exy Exz  Tx)(x)   (Sx*x + Tx + y*Exy + z*Exz)
(Eyx Sy  Eyz  Ty)(y) = (Sy*y + Ty + x*Eyx + z*Eyz)
(Ezx Ezy Sz   Tz)(z)   (Sz*z + Tz + x*Ezx + y*Ezy)
(0   0   0    1 )(1)   (1)

Rotation about x-axis, using right-hand rule:
(   1      0       0      0   )(x)   ()
(   0    cos(a) -sin(a)   0   )(y) = ()
(   0    sin(a)  cos(a)   0   )(z)   ()
(   0      0       0      1   )(1)   ()

Rotation about y-axis:
( cos(b)   0     sin(b)   0   )(x)   ()

(   0      1       0      0   )(y) = ()
(-sin(b)   0     cos(a)   0   )(z)   ()
(   0      0       0      1   )(1)   ()
Rotation about z-axis:

( cos(c) -sin(c)   0      0   )(x)   ()

( sin(c)  cos(c)   0      0   )(y) = ()
(   0      0       1      0   )(z)   ()
(   0      0       0      1   )(1)   ()

There are other rotations, such as the general case is rotation about an arbitrary line, which can be simplified assuming the arbitrary line is a unit vector.

A taxonomy of some linear transformations.  Rigid Body (preserve distance): rotation, translation.  Similarity (preserve angles): rigid body, uniform scaling / reflection.  Affine (preserve parallel lines): similarity, shear.  Projective (preserves lines => lines stay straight => it’s a linear transformation).

The order of your transformations matters.  For example, if you do rotation then translation, it’s different than if you do translation then rotation.

2. Light, Illumination & Reflectance

Notes on lecture, 2. Illumination. What is light? The BRDF. Vectors and dot products. The Phong BRDF model (2/7) … Light-Material interactions, what is light, illumination & reflectance, phong reflectance model, vectors & dot products. … more details about vectors & dot product in lecture 3

Diffuse reflections (incident ray reflects at many angles).  Specular reflections (mirror-like, incident ray reflects at many angles).  Specular highlights (bright spot on shiny object).  Refraction (bends light).  Dispersion (e.g. rainbow) (phase velocity of wave depends on its frequency) (different refractive index for different wavelengths).  Rainbow photo shows refraction, internal reflection, dispersion.  Atmospheric effects (haze, fog, crepuscular rays / god rays, light under water).  Interference (e.g. soap bubbles, thin layer of oil on water) (two waves superimpose to form a resultant wave of greater or lower amplitude).  Diffraction (e.g. CD discs) (physically similar to interference, but diffraction tends to mean lots of interference) (wave encounters obstacle) (disc example, tiny grooves are close to the wavelength of light so it causes some of the light to reflect in phase and some out of phase).  Motion blur.

What is light, wave-particle duality, but basic CG does geometric view of optics (rays of photos), and we simulate wave behaviors as effects.  Newton dispersion.

Human eye detects light (biology).  Visible spectrum of electromagnetic waves is about 390 to 700nm.  Human eye photoreceptor cells: rods adapt to brightness (helps vision in low light), cones detect red & green & blue (trichromatic vision) (cone peaks are short 420-440 nm, middle 530-540 nm, long 560-580 nm).  Metamers (different combinations of light across all wavelengths can produce the same visible color in terms of human eye receptor response).  Humans see light as additive colors (R+G=Yellow, R+B=Magenta, G+B=Cyan, R+G+B=White).  Ink (CMYK printing) & paint & crayons uses subtractive colors (Magenta+Yellow=R, Cyan+Yellow=G, Cyan+Magenta=B, Magenta+Yellow+Cyan=Black).

Illumination light sources: emittance spectrum (color), geometry (position & direction), directional attenuation (falloff).  Illumination surface properties: reflectance spectrum (color), geometry (position, orientation, micro-structure), absorption.

Graphics jargon (he’s using): illumination is transport of energy from light sources between points (direct & indirect paths).  Lighting is compute light intensity reflected from a specific 3D point.  Shading is assign color to a pixel based on illumination in the scene.

Direct illumination: surface point receives light directly from all light sources in scene – determine which light sources are visible, compute by local illumination model; OpenGL.  Global illumination: surface point receives light after light rays interact with other objects; indirect illumination; slow, ray tracing.

Light sources.  Directional light source.  Point light source.  Other: spotlights, area light sources, extended light sources (spherical).

Light is linear – you can add light sources and components.

Reflectance models.  BRDF (bi-directional reflection distribution function).  Can measure this experimentally (with real object, light camera) for lots of angles.  Or approximate with code – physically-based models (laws of physics), or empirical models (ad hoc), or data driven (lots of data).

Phong reflectance model uses diffuse + specular + ambient.
* Diffuse Reflectance uses Lambert’s Cosine Law, dL = dA*cos(theta).  Use three vectors from object point to: viewer, normal, light.  For Diffuse, viewer vector/angle doesn’t matter; all we use is: Id = kd*(N dot L)*Il … Illumination Diffuse = Diffuse Reflection Coefficient * (Normal Vector dot Light Direction Vector) * Illumination Light Source.  Vectors must be normalized.
* Specular Reflectance is affected by view vector (object point to camera).  Special case of Snell’s Law.  Incoming light direction is same as outgoing, meaning angle between light vector & normal vector is the same as the angle between reflect vector & normal vector (angle between L & N is same as angle between R & N).  Is = ks*(V dot R)*Il => Illumination Specular = Constant Specular * (View Vector dot Reflect Vector) * Illumination Light Source.
* Non-Ideal Specular Reflectance adds an exponent to the equation: Illumination Specular = Constant Specular * (View Vector dot Reflect Vector)^Exponent * Illumination Light Source
* Blinn & Torrance Variation: Illumination Specular = Constant Specular * (View Vector dot H)^Exponent * Illumination Light Source … H vector is halfway between L (light vector) and V (view vector) => don’t need to compute reflection vector R at every point.  Also, if V is very far away and L is very far away, then Illumination Specular is just a function of N (Normal Vector)

Single light source Phong Reflectance model is Ambient + Diffuse + Specular:


Equation from wikipedia for multiple light sources: