- Forward


Lighting 3D Shapes
An Introduction


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu

Print

Physics Basics
Back SMYC Forward
  • When light falls on the surface of an object it can be:
    • Absorbed (and converted to heat)
    • Reflected
    • Transmitted (i.e., moved through the object)
  • Visible objects:
    • Reflect some light, in some wavelengths, to the eye
Physics Basics (cont.)
Back SMYC Forward
  • Properties of light that impact reflection:
    • Wavelengths and intensity of the light
    • Direction and geometry of the source
  • Properties of objects that impact reflection:
    • Surface orientation
    • Surface properties (e.g., roughness, conductivity)
Transparency
Back SMYC Forward
  • Perfectly Transparent Materials:
    • Transmit all of the light
  • Opaque Materials:
    • Materials that reflect some of the light and perhaps absorb some of the light
  • Translucent Materials:
    • Transmit (and perhaps refract/bend) some of the light and reflect some of the light (including Dielectric materials, which are insulators that can be polarized by an electric field)
Reflecting Materials
Back SMYC Forward
  • Diffuse Reflection:
    • A perfect diffuser reflects light equally in all directions making the object appear matte/flat and appear the same to all viewers
  • Specular Reflection:
    • The light isn't scattered (i.e., all of the light is reflected at one angle) and its properties are (essentially) unchanged making the object appear shiny
A Model of Diffuse Reflection
Back SMYC Forward
  • Assume:
    • A point source of light
    • A perfect diffuser (sometimes called a Lambertian surface)
  • Lambert's Law:
    • The intensity of light reflected is proportional to the cosine of the angle between the light source and the surface normal
A Model of Diffuse Reflection (cont.)
Back SMYC Forward
  • Simplifying the Notation:
    • We will develop the model for the point \(\bs{0}\)
    • \(\bs{l}\) denotes the (normalized) vector for the light source (which is also the position of the light source since the point of interest is \(\bs{0}\))
    • \(\bs{n}\) denotes the surface normal vector (which is perpendicular to the surface at the point)
  • Visualization:
    • reflection-diffuse
  • Lambert's Law:
    • For each color (or wavelength):
    • \(D = L \kappa_{D} \cos \theta\)
    • where \(D\) is the intensity of the diffuse reflection, \(L\) is the intensity of the light source, and \(\kappa_{D}\) is an "absorption parameter"
A Model of Diffuse Reflection (cont.)
Back SMYC Forward
  • From the Law of Cosines:
    • \(\cos \theta = \frac{\bs{n} \cdot \bs{l}} {||\bs{n}|| \enspace ||\bs{l}||}\)
    • Since \(\bs{n}\) and \(\bs{l}\) have been normalized (i.e., have unit length) we know \(||\bs{n}|| \enspace ||\bs{l}|| = 1\)
    • Hence, \(\cos \theta = \bs{n} \cdot \bs{l}\)
  • Substituting into the Model:
    • For each color (or wavelength):
    • \(D = L \kappa_{D} \bs{n} \cdot \bs{l}\)
A Model of Specular Reflection
Back SMYC Forward
  • For Perfectly Reflecting Surfaces:
    • The angle of reflection equals the angle of incidence
  • We Will Assume:
    • A point source of light
    • An imperfect reflecting surface
A Model of Specular Reflection (cont.)
Back SMYC Forward
  • Notation:
    • \(\bs{r}\) denotes the reflected ray
    • \(\bs{v}\) denotes the location of the viewer
  • Visualization:
    • reflection-specular
  • An Empirical Model for Imperfect Reflectors (Romney):
    • For each color (or wavelength):
    • \(S = L \kappa_{S} \cos^{\delta} \phi\)
    • where \(S\) is the intensity of the specular reflection, \(\delta\) is a "shininess" parameter (that is often specific to a material), and \(\kappa_{S}\) is an "absorption parameter"
A Model of Specular Reflection (cont.)
Back SMYC Forward
  • From the Law of Cosines:
    • Assuming that \(\bs{r}\) and \(\bs{v}\) have been normalized (i.e., have unit length):
    • \(\cos^{\delta} \phi = (\bs{r} \cdot \bs{v})^{\delta}\)
  • Substituting into the Model:
    • For each color (or wavelength):
    • \(S = L \kappa_{S} (\bs{r} \cdot \bs{v})^{\delta}\)
A Complete Model of Reflection
Back SMYC Forward
  • Ambient Light:
    • We will assume the ambient intensity is given by \(A \kappa_{A}\)
  • An Attenuation Effect:
    • To model attenuation, we will divide the non-ambient intensities by \(\beta(d)\) where \(\beta\) is some function and \(d\) is the distance.
  • The Complete Model:
    • \(I = A \kappa_{A} + \frac{L}{\beta(d)} [\kappa_{D} (\bs{n} \cdot \bs{l}) + \kappa_{S} (\bs{r} \cdot \bs{v})^{\delta}]\)
    • where \(I\) denotes the total intensity
A Complete Model (cont.)
Back SMYC Forward
  • Incorporating Multiple Light Sources:
    • Have non-ambient terms for each light source and add them up
  • Incorporating Multiple Wavelengths/Colors Components:
    • People often have a separate model for each color component (e.g., red, green, and blue)
An Example of Reflection
Back SMYC Forward
  • Parameters:
    • \(\beta(d) = 1\) for all \(d\)
    • \(A = 1\), \(L = 10\)
    • \(\kappa_{S} = 0.65\), \(\kappa_{D} = \kappa_{A} = 0.15\) (Note: \(\kappa_{S} + \kappa_{D} + \kappa_{A} = 0.95\) implies 5 percent of the light is absorbed)
    • \(\delta=5\)
  • The Point of Interest:
    • \(\bs{0}\)
  • Normal at \(\bs{0}\):
    • \(\bs{n} = [0.0 \quad 1.0 \quad 0.0]^T\)
  • The Location of the Light Source and the Viewer:
    • Light Source: \(\bs{s} = [-1.0 \quad 2.0 \quad -1.0]^T\)
    • Viewer: \(\bs{e} = [1.0 \quad 1.5 \quad 0.5]^T\)
An Example of Reflection (cont.)
Back SMYC Forward
  • The Normalized Vectors at \(\bs{0}\):
    • \(\bs{n} = [0 \quad 1 \quad 0]^T\)
    • \(\bs{l} = \frac{[-1.0 \quad 2.0 \quad -1.0]^T} {|| [-1.0 \quad 2.0 \quad -1.0]^T ||} = [-0.408 \quad 0.816 \quad -0.408]^T\)
    • \(\bs{v} = \frac{[1.0 \quad 1.5 \quad 0.5]^T} {||[1.0 \quad 1.5 \quad 0.5]^T||} = [0.534 \quad 0.801 \quad 0.267]^T\)
    • \(\bs{r} = [0.408 \quad 0.816 \quad 0.408]^T\)
  • The Angles:
    • \(\theta = \cos^{-1}(\bs{n} \cdot \bs{l}) = \cos^{-1}(0.816) = 35.26\)
    • \(\phi = \cos^{-1}(\bs{r} \cdot \bs{v}) = \cos^{-1}(0.982) = 10.89\)
An Example of Reflection (cont.)
Back SMYC Forward
  • The Intensity:
    • \(I = (1)(0.15) + (\frac{10}{1}) [ (0.15)(0.816) + (0.65)(0.982^{5}) ] = 7.31\)
  • Interpretation:
    • The sight vector is almost coincident with the reflection vector so this point is bright
Calculating the Surface Normal if it is Not Provided
Back SMYC Forward
  • For Triangles:
    • Use the cross product
  • For Planar Polygons:
    • Use the equation of the plane
Calculating the Reflection Vector
Back SMYC Forward
  • Getting Started:
    • Normalize all of the vectors
  • The Conditions that must be Satisfied:
    • The angle of incidence equals the angle of reflection
    • All of the rays lie in the same plane
Calculating the Reflection Vector (cont.)
Back SMYC Forward
  • The First Condition:
    • \(\theta_{i} = \theta_{r}\)
    • \(\Rightarrow \cos \theta_{i} = \cos \theta_{r}\)
    • \(\Rightarrow \bs{l} \cdot \bs{n} = \bs{n} \cdot \bs{r}\)
  • The Second Condition:
    • \(\gamma \bs{n} = \bs{l} + \bs{r}\) for some real number \(\gamma\)
    • \(\Rightarrow \bs{r} = \gamma \bs{n} - \bs{l}\)
  • Combining:
    • \(\bs{l} \cdot \bs{n} = (\gamma \bs{n} - \bs{l}) \cdot \bs{n}\)
    • \(\Rightarrow \bs{l} \cdot \bs{n} = \gamma \bs{n} \cdot \bs{n} - \bs{l} \cdot \bs{n}\)
    • \(\Rightarrow \bs{l} \cdot \bs{n} = \gamma - \bs{l} \cdot \bs{n}\) (since \(\bs{n}\) has a norm of 1)
    • \(\Rightarrow \gamma = 2 \bs{l} \cdot \bs{n}\)
  • Substituting:
    • \(\bs{r} = 2(\bs{l} \cdot \bs{n}) \bs{n} - \bs{l}\)
Calculating the Reflection Vector (cont.)
Back SMYC Forward
  • An Aside (for those who care):
    • \(\bs{r} = 2(\bs{l} \cdot \bs{n}) \bs{n} - \bs{l}\)
    • \(\Rightarrow \bs{r} = 2[\bs{l}^{T} \bs{n}] \bs{n} - \bs{l}\)
    • \(\Rightarrow \bs{r} = 2[\bs{n} \bs{n}^{T}] \bs{l} - \bs{l}\)
    • \(\Rightarrow \bs{r} = (2[\bs{n} \bs{n}^{T}] - \bs{I}) \bs{l}\)
  • Some Observations:
    • \([\bs{n} \bs{n}^{T}]\) is a symmetric matrix with rank 1 (i.e., a dyadic matrix)
    • \(\bs{H} = (2[\bs{n} \bs{n}^{T}] - \bs{I})\) is a Householder matrix (which is a type of matrix that is often used in the solution of linear systems)
Reflection at Points other than \(\bs{0}\)
Back SMYC Forward
  • Be Careful:
    • There is often confusion involving the distinction between points and direction vectors
  • Visualization:
    • lighting-otherpoints
  • In practice:
    • We are often given the position of the light source, \(\bs{s}\), (which usually isn't normalized) and we must work with (and normalize) the direction vector, \(\bs{s}-\bs{p}\)
    • Artists usually provide the normal vector, \(\bs{n}\), at the point, \(\bs{p}\) (and it is usually normalized)
An Example of Reflection (cont.)
Back SMYC Forward
  • Parameters, Light Source and Viewer (As Before):
    • Light Source: \(\bs{s} = [-1.0 \quad 2.0 \quad -1.0]^T\)
    • Viewer: \(\bs{e} = [1.0 \quad 1.5 \quad 0.5]^T\)
  • The Point of Interest (and the Normal):
    • \(\bs{p} = [1.0 \quad -1.0 \quad 0.0]^T\)
    • \(\bs{n} = [1.0 \quad 0.0 \quad 0.0]^T\)
  • The Vectors of Interest:
    • \(\bs{l} = \frac{\bs{s}-\bs{p}}{||\bs{s}-\bs{p}||} = \frac{[-2.0 \quad 3.0 \quad -1.0]^T} {3.742} = [-0.534 \quad 0.801 \quad -0.267]^T\)
    • \(\bs{v} = \frac{\bs{e}-\bs{p}}{||\bs{e}-\bs{p}||} = \frac{[0.0 \quad 2.5 \quad 0.5]^T} {2.549} = [0.000 \quad 0.981 \quad 0.196]^T\)
    • \(\bs{r} = 2(\bs{l} \cdot \bs{n})\bs{n} - \bs{l} = 2(-0.534)\left[\begin{array}{c}1.0\\0.0\\0.0\end{array}\right] - \left[\begin{array}{c}-0.534\\0.801\\-0.267\end{array}\right] = \left[\begin{array}{c}-0.534\\-0.801\\0.267\end{array}\right] \)
  • The Intensity:
    • \(I = (1)(0.15) + (\frac{10}{1}) [ (0.15)(-0.534) + (0.65)(-0.734^{5}) ] = -2.036\)
An Example of Reflection (cont.)
Back SMYC Forward
  • Comparison of the Points:
    • The light source is to the left of \(\bs{0}\); the normal at \(\bs{0}\) is directed up
    • This point is to the right of and below \(\bs{0}\); the normal at this point is directed away from the light source
  • Comparison of the Intensities:
    • This point will be darker than the origin
Interpreting A Different Example of Reflection
Back SMYC Forward

What is "going on" in the following example?

lighting-3d_cube
Transparent/Translucent Materials
Back SMYC Forward
  • The Issues:
    • Some or all of the light is transmitted through the medium
    • The transmitted light may be refracted (i.e., bent)
  • The Main Result:
    • Snell's Law describes the relationship between the angle of incidence and the angle of transmission when light passes through a boundary between two isotropic (i.e., uniform) media
A Model of Transmission and Refraction
Back SMYC Forward

Understanding the Transmission/Refraction Angle

snells-law

Where \(\eta_i\) and \(\eta_t\) denote the index of refraction of the initial medium and transmitting medium, respectively, \(\bs{n}\) denotes the normal vector, and \(\bs{b}\) is chosen so as to form a basis with \(\bs{n}\) (i.e., \( \bs{b} = \frac{\bs{i} + \cos(\theta_i)\bs{n}}{\sin(\theta_i)}\)).

A Model of Transmission and Refraction (cont.)
Back SMYC Forward
  • Snell's Law:
    • \(\frac{\sin(\theta_i)}{\sin(\theta_t)} = \frac{\eta_t}{\eta_i} \)
  • The Implication:
    • \(\bs{t} = \frac{\eta_i}{\eta_t} \left(\bs{i} - (\bs{i} \cdot \bs{n}) \bs{n}\right) - \bs{n} \sqrt{1 - \frac{\eta_i^2}{\eta_t^2} \left(1 - (\bs{i} \cdot \bs{n})^2\right)}\)
  • A Special Case:
    • When the square root is imaginary (which can only happen when \(\eta_t \lt \eta_i\)) the light is reflected internally (i.e., total internal reflection)
A Model of Transmission and Refraction (cont.)
Back SMYC Forward
One Derivation (Assuming all Vectors have been Normalized)
  1. From Snell's Law: \( \sin(\theta_t) = \frac{\eta_i}{\eta_t} \sin(\theta_i) \)
  2. \(\sin^2(\alpha) + \cos^2(\alpha) = 1\) for any angle, \(\alpha\), so:
    \( \sin^2(\alpha) = \left(1 - \cos^2(\alpha) \right) \Rightarrow \sin(\alpha) = \sqrt{\left(1 - \cos^2(\alpha) \right)} \\ \cos^2(\alpha) = \left(1 - \sin^2(\alpha) \right) \Rightarrow \cos(\alpha) = \sqrt{\left(1 - \sin^2(\alpha) \right)} \)
  3. Substituting the first equation in (2) into (1): \( \sin(\theta_t) = \frac{\eta_i}{\eta_t} \sqrt{\left(1 - \cos^2(\alpha) \right)} \)
  4. From our study of the standard basis and and the unit circle:
    \( \bs{t} = \sin(\theta_t)\bs{b} - \cos(\theta_t)\bs{n} \\ \bs{i} = \sin(\theta_i)\bs{b} - \cos(\theta_i)\bs{n} \)
  5. From the second equation in (4): \( \sin(\theta_i)\bs{b} = \bs{i} + \cos(\theta_i)\bs{n} \)
  6. Substituting Snell's Law into the first equation in (4): \( \bs{t} = \frac{\eta_i}{\eta_t} \sin(\theta_i)\bs{b} - \cos(\theta_t)\bs{n} \)
  7. Substituting (5) into (6): \( \bs{t} = \frac{\eta_i}{\eta_t} \left( \bs{i} + \cos(\theta_i)\bs{n} \right) - \cos(\theta_t)\bs{n} \)
  8. Since \(\cos(\theta_i) = -\bs{i} \cdot \bs{n}\), it follows from (7) that:
    \( \bs{t} = \frac{\eta_i}{\eta_t} \left(\bs{i} - (\bs{i} \cdot \bs{n}) \bs{n} \right) - \cos(\theta_t) \bs{n} \)
  9. Substituting (3) into the second equation in (2): \( \cos^2(\theta_t) = 1 - \frac{\eta_i^2}{\eta_t^2} \left( 1 - \cos^2(\theta_i) \right) \)
  10. Substituting (9) into (8): \( \bs{t} = \frac{\eta_i}{\eta_t} (\bs{i} - (\bs{i} \cdot \bs{n}) \bs{n}) - \bs{n} \sqrt{1 - \frac{\eta_i}{\eta_t^2} (1 - \cos^2(\theta_i)} \)
  11. Since \(\cos(\theta_i) = -\bs{i} \cdot \bs{n}\) and \((-\cos(\theta_i))^2 = \cos^2(\theta_i)\):
    \( \bs{t} = \frac{\eta_i}{\eta_t} (\bs{i} - (\bs{i} \cdot \bs{n}) \bs{n}) - \bs{n} \sqrt{1 - \frac{\eta_i^2}{\eta_t^2} \left( 1 - (\bs{i} \cdot \bs{n})^2 \right)} \)
A Model of Transmission and Refraction (cont.)
Back SMYC Forward
  • A Simplifying Assumption:
    • Assume all objects are in the air with an index of refraction of 1 and surface normals that point towards the air
  • The Implication:
    • You can determine whether a vector is headed into or out of an object using the sign of the inner product of the vector and the surface normal
    • snells-law_in-or-out
A Model of Transmission and Refraction (cont.)
Back SMYC Forward
  • Fresnel's Equations:
    • Describe the ratio of the intensity of the reflected and transmitted light
  • Schlick's Approximation of the Reflection Coefficient:
    • \(R(\theta) = R_0 + (1 - R_0) \left( 1 - \cos(\theta)\right)^5\)
    • where:
    • \(R_0 = \left(\frac{\eta_i - \eta_t} {\eta_i + \eta_t}\right)^2\)
There's Always More to Learn
Back -