Lecture 8 Notes: Illumination and Shading in Computer Graphics
Object Creation in Blender
Objects can be sourced online or created using Blender.
If creating in Blender, textures should not be mapped in Blender itself.
Objects should be plain, with textures applied programmatically using Python within the curve environment.
Avoid importing entire scenes as single objects.
Introduction to Illumination
Illumination is a core aspect of computer graphics.
Topics covered:
Introduction to illumination.
Different light sources.
Global illumination modeling.
Local illumination modeling.
Shading methods.
Additional resources for understanding concepts are available on the learning platform.
The Rendering Pipeline
Object creation → Wireframe → Filled faces with color → Adding light sources → Illumination and shading.
Illumination adds depth, shadows, reflections, and refractions to the scene.
Illumination is vital for producing realistic computer graphics.
Types of Light Sources
Point Light: A small, singular light source.
Directed Light: Light from a distant source (e.g., the sun), assumed to be at infinite distance.
Spotlight: A focused light source (e.g., torch).
Distributed Light Source: Commonly found in buildings.
Light Attenuation
Light attenuates as it travels through the environment.
Directed light from a distance has negligible attenuation.
Point lights have attenuation inversely proportional to the distance () from the source.
Intensity is inversely proportional to the square of the distance () from the light source.
Justification: Light is emitted as packets of energy distributed around the point light source, forming expanding spheres. The energy per unit area decreases as the sphere's surface increases.
The surface area of a sphere is given by , where is the radius.
As the distance increases, the energy is spread over a larger surface, reducing the light intensity per unit area.
Light and Surface Interactions
Absorption: The surface absorbs all light; no re-emission.
Reflection:
Diffuse Reflection: Light is emitted in all directions after hitting the surface.
Specular Reflection:
Perfect Specular Reflection: Light is emitted at the same angle as it hits the surface.
Imperfect Specular Reflection: Light is mostly emitted in the same angle but with some scattering.
Refraction: Light bends as it passes through a surface (e.g., water).
The angle of incidence and angle of refraction are different due to the properties of the materials involved.
Fluorescence: Absorption of UV light and emission of visible light (e.g., glowing objects in nightclubs). Not commonly used in computer graphics.
Global Illumination Modeling
Scene components: Objects, light source, and camera/viewer.
Light travels from the source, interacts with objects (reflection, refraction, etc.), and eventually reaches the eye.
The idealized model considers all possible light paths from the source to the eye.
This approach is computationally intensive.
The formula for calculating the intensity of light from point to point is:
Where:
is the intensity of light from to .
represents attenuation or visibility between the points (accounts for objects blocking the path).
is the self-emitted light (if the object emits light itself).
The integral represents all potential light directions and paths from any object into .
represents the scattering behavior of light.
The integral part makes the formula computationally intractable.
Local Illumination Modeling
Imposes a significant constraint: light interacts with an object and stops; no object-to-object interactions are considered.
Simpler and faster than global illumination.
Limitations: Fails in scenarios like mirrors, where object-to-object reflections are crucial.
Environment mapping techniques can be used to simulate reflections in local illumination models.
Despite limitations, it produces reasonable results in many scenarios.
Ambient Light
Ambient light is always present, regardless of other light sources.
It is a component in all illumination calculations.
Diffuse Reflection Calculation
Diffuse reflection scatters light in all directions.
Parameters needed:
Light intensity ().
Direction from point to light source (; normalized).
Surface normal (; normalized).
Material parameter ().
, where is the light source coordinates and is the coordinates of the point being considered. L is a normalized vector.
Diffuse reflection is calculated as: , where is the angle between and .
Cosine of theta can be calculated using the dot product: (since both vectors are normalized).
When light hits the surface perpendicularly, maximum light is absorbed. When the surface is at an angle, less light is absorbed, proportional to .
Specular Reflection Calculation
Two scenarios: perfect and imperfect reflection.
Vectors Needed:
Normal (N).
Direction to light source (L).
Reflection vector (R).
Viewer vector (V).
All vectors are normalized.
Calculating distance to light source:
Reflection vector calculation:
Specular reflection calculation:
: Material parameter representing shininess.
: empirical value to control highlight size.
The equation is an empirical model.
Larger values leads to smaller, pointier, and shinier highlights.
Combining Reflection Models
Total illumination is the sum of ambient, diffuse, and specular components.
: Ambient light component.
: Diffuse reflection component =
: Specular reflection component =
Local illumination only considers light-to-object interactions.
Approximations may be used (e.g., treating I and L as constant over a small area).
Spotlight
Spotlights have a cone of light with maximum intensity in the center.
Intensity decreases as the angle from the main direction increases.
Attenuation Considerations
Directed light at infinity has no attenuation.
Point lights typically use quadratic attenuation (inversely proportional to ).
In practice, a polynomial attenuation () is often used for better results.
Material Properties: Kd and Ks
Kd (diffuse coefficient) and Ks (specular coefficient) affect the appearance of objects.
Changing Kd varies the brightness of the diffuse component.
Changing Ks varies how shiny the object appears
Color Channels
If lights contain color (RGB), treat each channel separately using the same formulas.
Multiple Light Sources
Ambient light remains constant.
Diffuse and specular components are summed over all light sources.
, where N is the number of light sources.
Blinn-Phong Model
An alternative to the Phong model for specular reflection, offering improved performance.
Instead of calculating the reflection vector R, it uses a halfway vector H between L and V.
Specular reflection is calculated as .
Use the normalized of L + V to calculate H.
If distance from viewer and light are far, V and L become constant, which means that H becomes constant as well, so you don't have to calculate everything for every point.
Only changes how specular reflection is handled; diffuse and ambient components remain the same.
Shading Methods
Flat Shading: Single intensity is calculated for each polygon/face.
Use the cross product to determine normal direction
Normals are determined by the polygon normal and light source direction.
Fastest method, but results in visible boundaries between faces.
Gouraud Shading: Interpolates intensity values between vertices.
More complex than flat shading.
The vertices calculate the color at the vertices, and then interpolate the values between the vertices.
Averages the normals of all faces sharing a vertex to approximate a smooth normal at that vertex.
Reduces the visibility of face boundaries, but can smooth out details.
Calculating the normal for each face, take the average on those normals for each face to get an average normal at the vertices.
Interpolates intensity values or color values between the vertices.
Phong Shading: Interpolates normal vectors between vertices.
More computationally intensive.
Considers that curvature is also changing.
It wouldn't get rid of all the shiny components or any specific characteristics that we might have that interpolation might blend out.
Most accurate and realistic looking, preserves specular highlights and curvature.
Summary of Shading Methods
Flat Shading: Fastest, but lowest quality.
Gouraud Shading: Good for scenes with mostly diffuse reflections.
Interpolate intensity values or color values between vertices.
Phong Shading: Highest quality, best for specular reflections, but slowest.
Interpolates the normal, which means that you preserve the curvature.
The choice of method depends on the desired level of realism and computational resources.
If you have lower values of Ks less specularity and only diffuse, go with graw chaining. If you have some specularity in the scenes or some objects that they have large values of Ks, then it's probably best to represent them with graw chaining.