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 (dd) from the source.

  • Intensity is inversely proportional to the square of the distance (d2d^2) from the light source.

  • Attenuation1d2Attenuation \propto \frac{1}{d^2}

  • 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 4πd24 \pi d^2, where dd 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.

      • angle<em>incidence=angle</em>reflectionangle<em>{incidence} = angle</em>{reflection}

      • 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 xx' to point xx is:

    • I(x,x)=g(x,x)[E(x)+f(x,x)I(x,x)dω]I(x', x) = g(x', x) [E(x') + \int f(x', x) I(x, x') d\omega]

    • Where:

      • I(x,x)I(x', x) is the intensity of light from xx' to xx.

      • g(x,x)g(x', x) represents attenuation or visibility between the points (accounts for objects blocking the path).

      • E(x)E(x') is the self-emitted light (if the object emits light itself).

      • The integral represents all potential light directions and paths from any object xx into xx'.

      • ff 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 (II).

    • Direction from point to light source (LL; normalized).

    • Surface normal (NN; normalized).

    • Material parameter (KdK_d).

  • L=P<em>lightP</em>pointP<em>lightP</em>pointL = \frac{P<em>{light} - P</em>{point}}{||P<em>{light} - P</em>{point}||}, where P<em>lightP<em>{light} is the light source coordinates and P</em>pointP</em>{point} is the coordinates of the point being considered. L is a normalized vector.

  • Diffuse reflection is calculated as: IKdcos(θ)I * K_d * cos(\theta), where θ\theta is the angle between NN and LL.

  • Cosine of theta can be calculated using the dot product: cos(θ)=NLcos(\theta) = N \cdot L (since both vectors are normalized).

  • I<em>diffuse=IK</em>d(NL)I<em>{diffuse} = I * K</em>d * (N \cdot L)

  • When light hits the surface perpendicularly, maximum light is absorbed. When the surface is at an angle, less light is absorbed, proportional to cos(θ)cos(\theta).

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:

    • distance=amplitude(P<em>lightP</em>point)distance = amplitude(P<em>{light} - P</em>{point})

  • Reflection vector calculation:

    • R=2(NL)NLR = 2(N \cdot L)N - L

  • Specular reflection calculation:

    • I<em>s=K</em>s(RV)nI<em>s = K</em>s * (R \cdot V)^n

    • KsK_s: Material parameter representing shininess.

    • nn: 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.

  • I<em>total=I</em>a+I<em>d+I</em>sI<em>{total} = I</em>a + I<em>d + I</em>s

    • IaI_a: Ambient light component.

    • I<em>dI<em>d: Diffuse reflection component = K</em>d(NL)K</em>d * (N \cdot L)

    • I<em>sI<em>s: Specular reflection component = K</em>s(RV)nK</em>s * (R \cdot V)^n

  • 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 d2d^2).

  • In practice, a polynomial attenuation (1a+bd+cd2\frac{1}{a + bd + cd^2}) 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.

  • I<em>total=I</em>a+<em>i=1N(I</em>di+Isi)I<em>{total} = I</em>a + \sum<em>{i=1}^{N} (I</em>{di} + I_{si}), 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.

  • H=L+VL+VH = \frac{L + V}{||L + V||}

  • Specular reflection is calculated as Ks(NH)nK_s(N \cdot H)^n.

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