UNIT 4 Module
UNIT 4 Module
Basic illumination models - halftone patterns and dithering techniques - Properties of light -
Standard primaries and chromaticity diagram; Intuitive colour concepts – Color Model :
RGB – YIQ – CMY – HSV – HLS. Computer Graphics Realism: Tiling the plane –
Recursively defined curves – space filling curves – fractals – ray tracing.
Ambient illumination represents the uniform, non-directional light that illuminates all surfaces
equally. In the real world, ambient light results from multiple reflections and scattering that create a
general level of illumination even in areas not directly lit by light sources.
The ambient illumination model is the simplest lighting model:
I ambient =k a ⋅ I a
Where:
I ambient is the ambient light intensity reaching the viewer
The ambient reflection coefficient k a represents the fraction of ambient light that the surface
reflects. A value of 0 means the surface absorbs all ambient light (appears black), while a value of 1
means the surface reflects all ambient light.
Ambient lighting alone produces flat, unrealistic images because it provides no information about
the three-dimensional shape of objects. However, it serves an important role in preventing
completely dark areas and providing a base level of illumination in realistic rendering systems.
In practice, ambient lighting is often implemented as a constant term added to more sophisticated
lighting calculations. The ambient component ensures that no surface appears completely black,
which would be unrealistic in most real-world lighting conditions.
Where:
I diffuse is the diffusely reflected light intensity
⃗
N is the unit surface normal vector
⃗
L is the unit vector pointing from the surface toward the light source
max (0 , x) ensures that surfaces facing away from the light source (⃗
N ⋅ ⃗L <0) receive no
direct illumination
The dot product ⃗N ⋅ ⃗L equals cos θ , where θ is the angle between the surface normal and the light
direction. This cosine relationship means that:
Surfaces perpendicular to the light direction (θ=0 °) receive maximum illumination
Surfaces at grazing angles receive proportionally less light
Surfaces facing away from the light (θ> 90° ) receive no direct illumination
The Lambert model accurately represents many real materials including paper, unfinished wood,
concrete, and fabrics. It forms the foundation for more complex shading models and is
computationally efficient, making it widely used in real-time graphics applications.
Where:
I specular is the specularly reflected light intensity
⃗
R is the unit vector in the perfect reflection direction
⃗
V is the unit vector pointing from the surface toward the viewer
n is the shininess exponent (typically 1 ≤ n ≤ 200)
Small values (n = 1-10) create large, soft highlights typical of rough metals
Large values (n = 50-200) create small, sharp highlights typical of highly polished surfaces
Very large values (n > 500) approach mirror-like reflection
The Phong model is an empirical approximation that doesn’t perfectly match physical reflection but
provides visually acceptable results with low computational cost. More physically accurate models
like Blinn-Phong or Cook-Torrance are used when higher realism is required.
I total=k a I a +k d I p max(0 , ⃗
N ⋅⃗
L )+ k s I p ¿
For color rendering, this calculation is performed separately for red, green, and blue components:
I total ,red ∧¿ k a ,red I a ,red +k d ,red I p ,red max(0 , ⃗
N ⋅⃗
L )+ k s , red I p ,red ¿
¿
The material properties (k a ,k d , k s ) and shininess n determine the surface appearance:
Light direction: ⃗
L=(0.577 , 0.577 , 0.577) (pointing toward upper-right)
View direction: ⃗
V =(0 , 0 , 1) (viewer directly above)
Output (i , j)=
{1 if Input (i, j) ≥T
0 if Input (i, j)<T
Where T is the threshold value, typically 0.5 for normalized intensities. This method is fast but
produces poor quality results with high contrast and loss of detail.
Ordered Dithering: Ordered dithering uses a predefined threshold matrix (dither matrix) that
varies the threshold value spatially. The most common is the Bayer matrix, constructed recursively:
D 1= [ 0 ]
D 2=
[ 03 21]
[ ]
0 8 2 10
12 4 14 6
D4 =
3 11 1 9
15 7 13 5
D 2 n=
[ 4 Dn 4 D n+ 2
4 Dn +3 4 D n+ 1 ]
For dithering, compare each pixel intensity with the corresponding normalized matrix value:
{
D(imod n , j mod n)
1 if Input (i, j)>
Output (i , j)= n
2
0 otherwise
Ordered dithering produces regular patterns that avoid temporal flickering in animations but can
create visible texture artifacts.
Error=Input (i , j)−Output(i , j)
4. Distribute the error to neighboring pixels using the Floyd-Steinberg filter:
Current 7 /16
1/16 ¿ ¿
3 /16 ¿
7
Input (i+ 1 , j)∧← Input (i+ 1, j)+Error ×
16
3
Input (i−1 , j+1)∧← Input(i−1 , j+1)+ Error ×
16
5
Input (i , j+1)∧← Input (i, j+1)+Error ×
16
1
Input (i+ 1 , j+1)∧← Input (i+ 1, j+1)+Error ×
16
The Floyd-Steinberg coefficients sum to 1, ensuring that the total error is preserved. The algorithm
produces high-quality results with minimal visible artifacts, making it suitable for photographic
images.
Other Error Diffusion Methods:
Jarvis-Judice-Ninke (JJN) uses a larger 5×3 filter:
[
1 X 7 5
48 3 5 ¿
5 ¿ 3 ¿ 1 ¿ 3 ¿ 5 ¿ 3 ¿ 1¿
]
Stucki uses a 5×3 filter with different coefficients:
[
1 X 8
42 2 4
4
¿
4 ¿2¿1¿2¿ 4¿2¿1¿
]
3.4 Visual Examples
Quality Comparison: Consider a smooth gray gradient from black (0) to white (1):
1. Threshold Dithering: Produces a sharp transition at the threshold point with complete loss of
gradient information.
2. Ordered Dithering (2×2 Bayer): Creates a regular checkerboard pattern that maintains gradient
information but introduces visible texture.
3. Ordered Dithering (8×8 Bayer): Produces smoother gradients with less visible patterns but may
show banding in smooth areas.
4. Floyd-Steinberg: Generates irregular but visually pleasing noise that effectively represents the
gradient without obvious patterns.
Detail Preservation: For images containing fine details:
IFETCE R-2019A
Academic Year: 2025-26
- Threshold dithering eliminates small features below the threshold - Ordered dithering preserves
details but adds regular texture - Floyd-Steinberg maintains fine details while adding organic-
looking noise
[ ]
0.1 0.3 0.5 0.7
0.2 0.4 0.6 0.8
0.3 0.5 0.7 0.9
0.4 0.6 0.8 1.0
Problem 2: Implement Floyd-Steinberg dithering for the first row of the above image, showing
error propagation.
Problem 3: Calculate the error diffusion coefficients for a simplified 3-pixel filter that distributes
error only to the right neighbor (weight α ) and bottom neighbor (weight 1−α ). What value of α
minimizes visible artifacts?
4. PROPERTIES OF LIGHT
Understanding the physical and perceptual properties of light is fundamental to computer graphics
color reproduction. Light, as electromagnetic radiation, possesses measurable physical
characteristics that determine how we perceive color, brightness, and other visual qualities.
Monochromatic light contains a single wavelength, while most light sources emit mixtures of
wavelengths described by spectral power distribution (SPD) functions P(λ) .
Intensity and Photometry: Light intensity describes the amount of electromagnetic energy per
unit area per unit time. Several photometric quantities are relevant:
Luminous flux (Φ ): Total visible light power, measured in lumens (lm)
Luminous intensity ( I ): Flux per solid angle, measured in candela (cd = lm/sr)
Luminance ( L): Flux per unit area per solid angle, measured in cd/m²
Illuminance ( E ): Incident flux per unit area, measured in lux (lm/m²)
The relationships are:
dΦ
I ∧¿
dΩ
d2 Φ
L∧¿
dA d Ωcosθ
dΦ
E∧¿
dA
Where Ω is solid angle, A is area, and θ is the angle from the surface normal.
Polarization: Light waves oscillate in planes perpendicular to the propagation direction.
Polarization describes the orientation of these oscillations:
Linear polarization: Oscillations in a single plane
Circular polarization: Oscillations rotate uniformly
Unpolarized light: Random oscillation orientations (most natural light)
Polarization affects reflection and transmission at surfaces, described by Fresnel equations. This is
important for realistic rendering of glass, water, and metallic surfaces.
Saturation (Chroma): Saturation describes color purity or vividness. High saturation colors appear
vivid and pure, while low saturation colors appear washed out or grayish.
Physically, saturation relates to spectral purity:
Monochromatic component
Purity =
Total intensity
Perceptually, saturation depends on the ratio of chromatic to achromatic content and varies with
overall brightness level.
Brightness and Lightness: Brightness is the perceptual correlate of luminance, but the relationship
is nonlinear due to visual adaptation and contrast effects.
The Weber-Fechner law describes the relationship:
Perceived brightness ∝ log (Luminance)
More accurate models include Stevens’ power law:
Perceived brightness=k ⋅¿
Where n ≈ 0.33 for typical viewing conditions.
L∧¿∫ P(λ)⋅l(λ)dλ
λ
M ∧¿ ∫ P( λ)⋅m(λ) dλ
λ
Where P(λ) is the spectral power distribution and l(λ), m(λ), s( λ) are the cone sensitivity
functions.
Color Adaptation: The visual system adapts to different illumination conditions, maintaining
approximately constant color appearance. This involves:
IFETCE R-2019A
Academic Year: 2025-26
[ ][ ][ ]
L' αL 0 0 L
'
M = 0 αM 0 M
S' 0 0 αS S
These monochromatic primaries enable precise color specification but have practical limitations: 1.
Some colors require negative amounts of primaries (impossible in physical systems) 2. The
primaries are difficult to reproduce accurately in devices
CIE XYZ System: To address RGB limitations, the CIE defined mathematical primaries X, Y, Z
that: 1. Produce only positive tristimulus values for all visible colors 2. Have Y correspond to
luminance (brightness) 3. Enable efficient computation
The transformation from CIE RGB to XYZ uses:
[][ ][ ]
X 2.7689 1.7517 1.1302 R
Y = 1.0000 4.5907 0.0601 G
Z 0.0000 0.0565 5.5943 B
The XYZ color matching functions x́ (λ), ý (λ) , ź (λ) allow calculation of tristimulus values from
spectral data:
X ∧¿ k ∫ P(λ) x́ (λ)dλ
λ
Y ∧¿ k ∫ P (λ) ý (λ)dλ
λ
Z∧¿ k ∫ P( λ) ź ( λ)dλ
λ
Saturation: Saturation describes color intensity or purity—how vivid or muted a color appears.
High saturation colors appear vibrant and pure, while low saturation colors appear grayish and
muted.
Saturation can be understood as:
Distance from gray: Highly saturated colors are far from the neutral gray axis
Spectral purity: Monochromatic light produces maximum saturation
Chroma content: The ratio of chromatic to achromatic content
Factors affecting perceived saturation: 1. Viewing conditions: Colors appear less saturated under
dim light 2. Adaptation state: Prolonged viewing of saturated colors reduces their apparent
saturation 3. Surrounding colors: Neutral surroundings increase apparent saturation
Brightness/Lightness/Value: These terms describe the light-dark dimension of color but have
subtle differences:
Brightness: Subjective impression of light emission or reflection
Lightness: Relative brightness compared to white under the same viewing conditions
Value: The lightness dimension in color systems (HSV, Munsell)
The relationship between physical luminance and perceived lightness follows approximately:
( )
1/ 3
¿ Y
L =116 −16
Yn
Where Y is the luminance and Y n is the luminance of white (CIE L*a*b* formula).
{
0 if V =0
S∧¿ C
otherwise
V
{
G−B
×60 ° if V =R
C
H∧¿ ( B−R +2)×60 ° if V =G
C
R−G
( + 4)×60 ° if V =B
C
Where r , g, b are intensity coefficients (typically 0-1 or 0-255) and R , G , B are the primary color
vectors.
Device Dependencies: RGB is device-dependent—the same RGB values produce different colors
on different devices due to variations in: 1. Phosphor/LED spectral characteristics 2. White point
temperature 3. Gamma response curves 4. Manufacturing tolerances
Color management systems address these issues using: - Device profiles (ICC profiles) - Color
space transformations - Gamut mapping algorithms
Standard RGB Color Spaces:
sRGB: Default color space for web and consumer applications - Gamma: 2.4 (with linear portion) -
White point: D65 (6500K) - Gamut: Covers 35 - Primaries: R(0.640,0.330), G(0.300,0.600),
B(0.150,0.060)
Adobe RGB: Professional photography and printing - Larger gamut than sRGB ( 50 - Better cyan-
green reproduction - Requires color management for accurate display
ProPhoto RGB: Maximum gamut for photography - Covers 90 - 16-bit processing recommended
to avoid banding - Theoretical primaries (outside visible spectrum)
RGB Applications:
Digital cameras and scanners
Computer monitors and televisions
LED displays and projectors
Web graphics and digital images
Video games and real-time rendering
These weights reflect the eye’s sensitivity to different colors (highest for green, lowest for blue).
RGB to YIQ Conversion:
[][ ][ ]
Y 0.299 0.587 0.114 R
I = 0.596 −0.274 −0.322 G
Q 0.211 −0.523 0.312 B
[][ ][ ]
R 1.000 0.956 0.621 Y
G = 1.000 −0.272 −0.647 I
B 1.000 −1.106 1.703 Q
K∧¿1−max(R ,G , B)
(1−R−K )
C∧¿
(1−K )
(1−G−K )
M ∧¿
(1−K )
(1−B−K )
Y ∧¿
(1−K )
When K=1 (pure black), C = M = Y = 0.
Printing Considerations:
Dot gain: Ink dots spread on paper, darkening the image
Color gamut: CMYK gamut is smaller than RGB, especially for bright colors
Paper color: White point varies with paper type
Ink limitations: Total ink coverage typically limited to 300-400
{
0 if V =0
S∧¿ Δ
otherwise
V
Hue calculation:
IFETCE R-2019A
Academic Year: 2025-26
{
G−B
×60 ° if V =R
Δ
B−R
( +2)× 60° if V =G
H= Δ
R−G
( + 4)× 60 ° if V =B
Δ
undefined if Δ=0
{
(C , X ,0) if 0 ° ≤ H <60 °
( X ,C ,0) if 60 ° ≤ H <120 °
' ' ' (0 ,C , X) if 120 °≤ H <180 °
(R ,G , B )=
(0 , X , C) if 180 °≤ H <240 °
( X ,0 , C) if 240 °≤ H <300 °
(C , 0 , X) if 300 °≤ H <360 °
{
0 if Δ=0
Δ
if L> 0.5
S= 2−max−min
Δ
if L ≤ 0.5
max+min
Semi-regular Tilings (Archimedean): These use two or more regular polygons with the same
arrangement at every vertex. There are exactly 8 semi-regular tilings, including: - Truncated square:
squares and octagons (4.8²) - Snub square: squares and triangles (3⁴.6) - Hexagon-triangle:
hexagons and triangles (3.6²)
Penrose Tilings: Non-periodic tilings using two rhombi create fascinating patterns with fivefold
symmetry. Properties include: - Aperiodic: No translational symmetry - Quasicrystalline: Long-
range order without periodicity - Self-similar: Contains smaller copies of itself - Golden ratio
relationships: Edge ratios follow φ = (1+√5)/2
Applications in Graphics:
Texture mapping: Seamless tiling textures
Procedural generation: Infinite terrain and architectural patterns
Mesh refinement: Adaptive tessellation for curved surfaces
User interfaces: Pattern backgrounds and decorative elements
Where h(P) is the height value from a texture and N is the surface normal.
Algorithm: 1. Divide segment into three equal parts 2. Remove the middle third 3. Add two sides of
an equilateral triangle where the middle third was 4. Repeat for each new segment
Mathematical properties: - Length after n iterations: Ln=L0 ⋅¿ - Perimeter approaches infinity as n
→ ∞ - Area remains finite (bounded by the initial triangle’s circumcircle) - Hausdorff dimension:
log (4)/ log(3)≈ 1.26
Dragon Curve: Generated by folding paper and unfolding at right angles:
Recursion rules: - Dragon₀ = "F" (forward) - Dragon_n+1 = Dragon_n + "L" + reverse(Dragon_n
with R↔L)
Where L = turn left 90°, R = turn right 90°, F = move forward.
Sierpinski Gasket: Created by recursively subdividing triangles:
Algorithm: 1. Start with solid triangle 2. Remove central triangle (connecting midpoints) 3. Repeat
for each remaining triangle
Properties: - Self-similar at all scales - Area approaches zero - Hausdorff dimension:
log (3)/log (2)≈ 1.58
8.5 Fractals
Fractals exhibit self-similarity across scales and are characterized by non-integer dimensions. They
effectively model natural phenomena like coastlines, mountains, and vegetation.
For each complex number c: 1. Iterate the function 2. If |z_n| remains bounded (|z_n| ≤ 2), c is in
the set 3. Color pixels based on iteration count before divergence
Pseudocode: “‘ for each pixel (x,y): c = complex(x, y) z = 0 iteration = 0 while |z| ≤ 2 and iteration
< max_iterations: z = z² + c iteration++ color = palette[iteration] “‘
Julia Sets: Related to Mandelbrot but with fixed c parameter: For fixed c, iterate z n+1=z 2n + c
starting from z₀ = pixel position.
Fractal Landscapes: Procedural terrain generation using fractal algorithms:
Diamond-Square Algorithm: 1. Initialize corner heights 2. Diamond step: Set center = average of
corners + random offset 3. Square step: Set edge midpoints = average of neighbors + random offset
4. Reduce random range and subdivide recursively
Midpoint Displacement: For 1D profiles (mountain silhouettes): 1. Connect endpoints with line 2.
Displace midpoint by random amount 3. Recursively displace subdivided segments with scaled
randomness
Perlin Noise: Generates coherent noise for natural textures: - Gradient-based interpolation -
Multiple octaves for different detail levels - Widely used in procedural content generation
¿ R(t )−C ¿2 ∧¿ r 2
¿ O+t D−C ¿2∧¿ r 2
Expanding and solving quadratic:
IFETCE R-2019A
Academic Year: 2025-26
2
a t + bt+ c=0
Where:
a∧¿ D ⋅ D
b∧¿ 2 D⋅(O−C )
c∧¿(O−C )⋅(O−C)−r 2
T=
n1
n2
I+
n1
n2( )
cos θ1−cos θ 2 N
Advanced Ray Tracing: - Monte Carlo methods: Statistical sampling for global illumination -
Bidirectional path tracing: Tracing from both camera and lights - Photon mapping: Two-pass
algorithm for caustics and indirect lighting - Real-time ray tracing: Hardware acceleration (RTX,
RDNA2)
Problem 3: Implement the midpoint displacement algorithm for a 1D mountain profile with 9
points.
Problem 4: Design a Penrose tiling pattern using the two basic rhombi shapes.