0% found this document useful (0 votes)
27 views173 pages

Last Part

The document discusses spline curves and Bézier curves. It introduces Bézier curves as a method developed by Pierre Bézier for approximating smooth curves using control points. The document focuses on cubic Bézier curves, which use 4 control points. It explains that B-splines were developed to address limitations of Bézier curves, such as the degree being dependent on the number of control points. B-splines allow the degree of the curve to be independent of the number of control points by using a knot vector to join multiple lower degree Bézier curve segments.

Uploaded by

I061NIHAL TIWARI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views173 pages

Last Part

The document discusses spline curves and Bézier curves. It introduces Bézier curves as a method developed by Pierre Bézier for approximating smooth curves using control points. The document focuses on cubic Bézier curves, which use 4 control points. It explains that B-splines were developed to address limitations of Bézier curves, such as the degree being dependent on the number of control points. B-splines allow the degree of the curve to be independent of the number of control points by using a knot vector to join multiple lower degree Bézier curve segments.

Uploaded by

I061NIHAL TIWARI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 173

Computer Graphics 12:

Spline Representations

Course Website: http://www.comp.dit.ie/bmacnamee


2
of
24
Contents
Today we are going to look at Bézier spline
curves
– Introduction to splines
– Bézier origins
– Bézier curves
– Bézier cubic splines
3
of
24
Spline Representations
A spline is a smooth curve
defined mathematically
using a set of constraints
Splines have many uses:

“Manifold Splines”, X. Gu,


Y. He & H. Qin, Solid and
Physics Modeling 2005.
– 2D illustration
– Fonts
– 3D Modelling
– Animation

ACM © 1987 “Principles of


traditional animation applied
to 3D computer animation”
4
of
24
Physical Splines
Physical splines are used in car/boat design

Pierre Bézier
5
of
24
Big Idea
User specifies control points
Defines a smooth curve

Curve

Control Control
Points Points
6
of
24
Interpolation Vs Approximation
A spline curve is specified using a
Images taken from Hearn & Baker, “Computer Graphics with OpenGL” (2004)

set of control points


There are two ways to fit a curve to
these points:
– Interpolation - the curve passes
through all of the control points
– Approximation - the
curve does not pass
through all of the control
points
7
of
24
Convex Hulls
The boundary formed by the set of control
Images taken from Hearn & Baker, “Computer Graphics with OpenGL” (2004)

points for a spline is known as a convex hull


Think of an elastic band stretched around the
control points
8
of
24
Control Graphs
A polyline connecting the control points in
Images taken from Hearn & Baker, “Computer Graphics with OpenGL” (2004)

order is known as a control graph


Usually displayed to help designers keep
track of their splines
9
of
24
Bézier Spline Curves
A spline approximation method developed
by the French engineer Pierre Bézier for use
in the design of Renault car bodies
A Bézier curve can be fitted to any number
of control points – although usually 4 are
used
10
of
24
Bézier Spline Curves (cont…)

Consider the case of n+1 control points


denoted as pk=(xk, yk, zk) where k varies
from 0 to n
The coordinate positions are blended to
produce the position vector P(u) which
describes the path of the Bézier polynomial
function between p0 and pn
n
P(u )   pk BEZ k ,n (u ), 0  u 1
k 0
11
of
24
Bézier Spline Curves (cont…)

The Bézier blending functions BEZk,n(u) are


the Bernstein polynomials
k nk
BEZ k ,n (u )  C (n, k )u (1  u )

where parameters C(n,k) are the binomial


coefficients
n!
C (n, k ) 
k!(n  k )!
12
of
24
Bézier Spline Curves (cont…)
So, the individual curve coordinates can be
given as follows
n
x(u )   xk BEZ k ,n (u )
k 0
n
y (u )   yk BEZ k ,n (u )
k 0
n
z (u )   z k BEZ k ,n (u )
k 0
Images taken from Hearn & Baker, “Computer Graphics with OpenGL” (2004)

of
24
13
Bézier Spline Curves (cont…)
14
of
24
Important Properties Of Bézier Curves

The first and last control points are the first


and last point on the curve
– P(0) = p0
– P(1) = pn
The curve lies within the convex hull as the
Bézier blending functions are all positive and
sum to 1
n

 BEZ
k 0
k ,n (u )  1
15
of
24
Cubic Bézier Curve
Many graphics packages restrict Bézier
curves to have only 4 control points (i.e. n =
3)
The blending functions when n = 3 are
simplified as follows:
3
BEZ 0,3  (1  u )
2
BEZ1,3  3u (1  u )
2
BEZ 2,3  3u (1  u )
BEZ 3,3  u 3
16
of
24
Cubic Bézier Blending Functions
17
of
24
Bézier Spline Curve Exercise
y

(6, 5)
(2, 4)

(4, 2)
(1, 1)

x
18
of
24
Summary
Today we had a look at spline curves and in
particular Bézier curves
The whole point is that the spline functions
give us an approximation to a smooth curve
(B-Spline)
B-Spline
• Motivation (recall bezier curve)
– The degree of a Bezier Curve is
determined by the number of
control points
– E. g. (bezier curve degree 11)
–Of course, we can add more control
points.
– BUT this will increase the degree
of the curve  increase
computational burden
B-Spline
• Motivation (recall bezier curve)
– Joint many bezier curves of lower
degree together (right figure)
– BUT maintaining continuity in
the derivatives of the desired
order at the connection point is
not easy or may be tedious and
undesirable.
B-Spline
• Motivation (recall bezier curve)
– moving a control point affects the
shape of the entire curve- (global
modification property) –
undesirable.
- Thus, the solution is B-Spline – the
degree of the curve is independent
of the number of control points
- E.g - right figure – a B-spline curve
of degree 3 defined by 8 control
points
B-Spline
• In fact, there are five Bézier curve
segments of degree 3 joining
together to form the B-spline curve
defined by the control points
• little dots subdivide the B-spline
curve into Bézier curve segments.
• Subdividing the curve directly is
difficult to do  so, subdivide the
domain of the curve by points 0 u 1
called knots
B-Spline
• In summary, to design a B-spline curve, we
need a set of control points, a set of knots
and a degree of curve.
B-Spline curve
n
• P(u) =  Ni,k(u)pi (u0 < u < um).. (1.0)
i=0

Where basis function = Ni,k(u)


Degree of curve  k-1
Control points, pi  0 < i < n
Knot, u  u0 < u < um
m=n+k
B-Spline : definition
• P(u) =  Ni,k(u)pi (u0 < u < um)
• ui  knot
• [ui, ui+1)  knot span
• (u0, u1, u2, …. um ) knot vector
• The point on the curve that corresponds to a knot ui,  knot
point ,P(ui)
• If knots are equally space  uniform (e.g, 0, 0.2, 0.4,
0.6…)
• Otherwise  non uniform (e.g: 0, 0.1, 0.3, 0.4, 0.8 …)
B-Spline : definition
• Uniform knot vector
– Individual knot value is evenly spaced
– (0, 1, 2, 3, 4)
– Then, normalized to the range [0, 1]
– (0, 0.25, 0.5, 0.75, 1.0)
Type of B-Spline uniform knot vector

Non-periodic knots Periodic knots


(open knots) (non-open knots)

-First and last knots are -First and last knots are
duplicated k times.
not duplicated – same
-E.g (0,0,0,1,2,2,2)
contribution.
-Curve pass through the -E.g (0, 1, 2, 3)
first and last control -Curve doesn’t pass
points
through end points.
- used to generate closed
curves (when first = last
control points)
Non-periodic (open) uniform B-Spline
• The knot spacing is evenly spaced except at the ends
where knot values are repeated k times.
n
• E.g P(u) =  Ni,k(u)pi
i=0
(u0 < u < um)
• Degree = k-1, number of control points = n + 1
• Number of knots = m + 1 @ n+ k + 1
for degree = 1 and number of control points = 4 (k = 2, n = 3)
 Number of knots = n + k + 1 = 6
non periodic uniform knot vector (0,0,1,2,3, 3)
* Knot value between 0 and 3 are equally spaced 
uniform
Non-periodic (open) uniform B-Spline
• Example
• For curve degree = 3, number of control points = 5
 k = 4, n = 4
 number of knots = n+k+1 = 9
 non periodic knots vector = (0,0,0,0,1,2,2,2,2)
• For curve degree = 1, number of control points = 5
 k = 2, n = 4
 number of knots = n + k + 1 = 7
 non periodic uniform knots vector = (0, 0, 1, 2, 3, 4, 4)
Non-periodic (open) uniform B-
Spline
• For any value of parameters k and n, non
periodic knots are determined from
0 0 i < k
ui = i–k+1 kin (1.3)
n–k+2 n < i n+k

e.g k=2, n = 3
0 0 i < 2
ui = i–2+1 2i3
3–2+2 3 < i 5

u = (0, 0, 1, 2, 3, 3)
B-Spline basis function
N i , k 1 u  N i 1, k 1 u 
N i , k u   u  u i   u i  k  u  
(1.1)2
u i  k 1  u i u i  k  u i 1

1 u i  u  u i 1
N i ,1   3 (1.2)
0 selainnya.
Otherwise
In equation (1.1), the denominators can have a value of
zero, 0/0 is presumed to be zero.

If the degree is zero basis function Ni,1(u) is 1 if u is in the


i-th knot span [ui, ui+1).
B-Spline basis function
• For example, if we have four knots u0 = 0, u1 = 1, u2
= 2 and u3 = 3, knot spans 0, 1 and 2 are [0,1), [1,2),
[2,3)
• the basis functions of degree 0 are N0,1(u) = 1 on
[0,1) and 0 elsewhere, N1,1(u) = 1 on [1,2) and 0
elsewhere, and N2,1(u) = 1 on [2,3) and 0 elsewhere.
• This is shown below
B-Spline basis function
• To understand the way of computing Ni,p(u) for p greater
than 0, we use the triangular computation scheme
Non-periodic (open) uniform B-Spline
Example
• Find the knot values of a non periodic
uniform B-Spline which has degree = 2 and
3 control points. Then, find the equation of
B-Spline curve in polynomial form.
Non-periodic (open) uniform B-Spline
Answer
• Degree = k-1 = 2  k=3
• Control points = n + 1 = 3  n=2
• Number of knot = n + k + 1 = 6
• Knot values  u0=0, u1=0, u2=0, u3=1,u4=1,u5= 1
Non-periodic (open) uniform B-Spline
Answer(cont)
• To obtain the polynomial equation,
n

P(u) =  Ni,k(u)pi
i=0
2

• =  Ni,3(u)pi
i=0

• = N0,3(u)p0 + N1,3(u)p1 + N2,3(u)p2

• firstly, find the Ni,k(u) using the knot value that


shown above, start from k =1 to k=3
Non-periodic (open) uniform B-Spline
Answer (cont)
• For k = 1, find Ni,1(u) – use equation (1.2):
• N0,1(u) = 1 u0 u u1 ; (u=0)
• 0 otherwise
• N1,1(u) = 1 u1 u u2 ; (u=0)
• 0 otherwise
• N2,1(u) = 1 u2 u u3 ; (0 u  1)
• 0 otherwise
• N3,1(u) = 1 u3 u u4 ; (u=1)
• 0 otherwise
• N4,1(u) = 1 u4 u u5 ; (u=1)
• 0 otherwise
Non-periodic (open) uniform B-Spline
Answer (cont)
• For k = 2, find Ni,2(u) – use equation (1.1):

N i , k 1 u  N i 1, k 1 u 
N i , k u   u  u i   u i  k  u  2
• N0,2(u) = u - u0 N0,1 +uui 2 k–1uNu
1,1i (u0 =u1 =u2 = u
0)i  k  u i 1
• u1 - u0 u2 – u 1
• = u – 0 N0,1 + 0 – u N1,1 = 0
• 0–0 0–0
• N1,2(u) = u - u1 N1,1 + u3 – u N2,1 (u1 =u2 = 0, u3 = 1)
• u2 - u1 u3 – u 2
• = u – 0 N1,1 + 1 – u N2,1 = 1 - u
• 0–0 1–0
Non-periodic (open) uniform B-Spline
Answer (cont)
• N2,2(u) = u – u2 N2,1 + u4 – u N3,1 (u2 =0, u3 =u4 = 1)
• u3 – u 2 u4 – u3
• = u – 0 N2,1 + 1 – u N3,1 = u
• 1–0 1–1
• N3,2(u) = u – u3 N3,1 + u5 – u N4,1 (u3 =u4 = u5 = 1)
• u4 – u 3 u5– u4
• = u – 1 N3,1 + 1 – u N4,1 = 0
• 1–1 1–1
Non-periodic (open) uniform B-Spline
Answer (cont)
For k = 2
N0,2(u) = 0
N1,2(u) = 1 - u
N2,2(u) = u
N3,2(u) = 0
Non-periodic (open) uniform B-Spline
Answer (cont)
• For k = 3, find Ni,3(u) – use equation (1.1):

N i , k 1 u  N i 1, k 1 u 
N i , k u   u  u i   u i  k  u  2
• N0,3(u) = u - u0 N0,2 +uui 3 k–1uNu
1,2i (u0 =u1 =u2 = u  u) i 1
0,i uk3 =1
• u2 - u0 u3 – u 1
• = u – 0 N0,2 + 1 – u N1,2 = (1-u)(1-u) = (1- u)2
• 0–0 1–0
• N1,3(u) = u - u1 N1,2 + u4 – u N2,2 (u1 =u2 = 0, u3 = u4 = 1)
• u3 - u1 u4 – u 2
• = u – 0 N1,2 + 1 – u N2,2 = u(1 – u) +(1-u)u = 2u(1-u)
• 1–0 1–0
Non-periodic (open) uniform B-Spline
Answer (cont)
• N2,3(u) = u – u2 N2,2 + u5 – u N3,2 (u2 =0, u3 =u4 = u5 =1)
• u 4 – u2 u5 – u3
• = u – 0 N2,2 + 1 – u N3,2 = u2
• 1–0 1–1
N0,3(u) =(1- u)2, N1,3(u) = 2u(1-u), N2,3(u) = u2

n
The polynomial equation, P(u) =  Ni,k(u)pi
i=0
• P(u) = N0,3(u)p0 + N1,3(u)p1 + N2,3(u)p2
• = (1- u)2 p0 + 2u(1-u) p1 + u2p2 (0 <= u <= 1)
Non-periodic (open) uniform B-
Spline
• Exercise
• Find the polynomial equation for curve with
degree = 1 and number of control points = 4
Non-periodic (open) uniform B-Spline
• Answer
• k = 2 , n = 3  number of knots = 6
• Knot vector = (0, 0, 1, 2, 3, 3)
• For k = 1, find Ni,1(u) – use equation (1.2):
• N0,1(u) = 1 u0 u u1 ; (u=0)
• N1,1(u) = 1 u1 u u2 ; (0 u  1) N2,1(u) = 1 u2 u
u3 ; (1 u  2)
• N3,1(u) = 1 u3 u u4 ; (2 u  3) N4,1(u) = 1 u4 u
u5 ; (u=3)

Non-periodic (open) uniform B-Spline
Answer (cont)
• For k = 2, find Ni,2(u) – use equation (1.1):
N i , k 1 u  N i 1, k 1 u 
N i , k u   u  u i   u i  k  u  2
u i  k 1  u i u i  k  u i 1
• N0,2(u) = u - u0 N0,1 + u2 – u N1,1 (u0 =u1 =0, u2 = 1)
• u1 - u 0 u2 – u1
• = u – 0 N0,1 + 1 – u N1,1
• 0–0 1–0
• = 1–u (0 u  1)
Non-periodic (open) uniform B-Spline
Answer (cont)
• For k = 2, find Ni,2(u) – use equation (1.1):
N i , k 1 u  N i 1, k 1 u 
N i , k u   u  u i   u i  k  u  2
u i  k 1  u i u i  k  u i 1
• N1,2(u) = u - u1 N1,1 + u3 – u N2,1 (u1 =0, u2 =1, u3 = 2)
• u2 - u 1 u3 – u2
• = u – 0 N1,1 + 2 – u N2,1
• 1–0 2–1
• N1,2(u) = u (0 u  1)
• N1,2(u) = 2 – u (1 u  2)
Non-periodic (open) uniform B-Spline
Answer (cont)
• N2,2(u) = u – u2 N2,1 + u4 – u N3,1 (u2 =1, u3 =2,u4 = 3)
• u 3 – u2 u4 – u3
• = u – 1 N2,1 + 3 – u N3,1 =
• 2–1 3–2
• N2,2(u) = u – 1 (1 u  2)
• N2,2(u) = 3 – u (2 u  3)
Non-periodic (open) uniform B-Spline
Answer (cont)
• N3,2(u) = u – u3 N3,1 + u5 – u N4,1 (u3 = 2, u4 = 3, u5 = 3)

• u 4 – u3 u5– u4
• = u – 2 N3,1 + 3 – u N4,1 =
• 3–2 3–3
• = u – 2 (2 u  3)
Non-periodic (open) uniform B-Spline
Answer (cont)
• The polynomial equation P(u) =  Ni,k(u)pi
• P(u) = N0,2(u)p0 + N1,2(u)p1 + N2,2(u)p2 + N3,2(u)p3

• P(u) = (1 – u) p0 + u p1 (0 u  1)
• P(u) = (2 – u) p1 + (u – 1) p2 (1 u  2)
• P(u) = (3 – u) p2 + (u - 2) p3 (2 u  3)
Computer Graphics 14:
Surface Detection Methods

Course Website: http://www.comp.dit.ie/bmacnamee


52
of
28
Contents
Today we will start to take a look at visible
surface detection techniques:
– Why surface detection?
– Back face detection
– Depth-buffer method
– A-buffer method
– Scan-line method
53
of
28
Why?
We must determine what is visible within a
scene from a chosen viewing position
For 3D worlds this is known as visible
surface detection or hidden surface
elimination
54
of
28
Two Main Approaches
Visible surface detection algorithms are
broadly classified as:
– Object Space Methods: Compares objects
and parts of objects to each other within the
scene definition to determine which surfaces
are visible
– Image Space Methods: Visibility is decided
point-by-point at each pixel position on the
projection plane
Image space methods are by far the more
common
55
of
28
Back-Face Detection
The simplest thing we can do is find the
faces on the backs of polyhedra and discard
them
56
of
28
Back-Face Detection (cont…)

We know from before that a point (x, y, z) is


behind a polygon surface if:
Ax  By  Cz  D  0
where A, B, C & D are the plane parameters
for the surface
This can actually be made even easier if we
organise things to suit ourselves
57
of
28
Back-Face Detection (cont…)
Ensure we have a right handed system with
Images taken from Hearn & Baker, “Computer Graphics with OpenGL” (2004)

the viewing direction along the negative z-axis


Now we can simply say that if the z component
of the polygon’s normal is less than zero the
surface cannot be seen
58
of
28
Back-Face Detection (cont…)
In general back-face detection can be
expected to eliminate about half of the
polygon surfaces in a scene from further
visibility tests
More complicated surfaces
though scupper us!
We need better techniques
to handle these kind of
situations
59
of
28
Depth-Buffer Method
Compares surface depth values throughout
a scene for each pixel position on the
projection plane
Usually applied to scenes only containing
polygons
As depth values can be computed easily,
this tends to be very fast
Also often called the z-buffer method
Images taken from Hearn & Baker, “Computer Graphics with OpenGL” (2004)

of
28
60
Depth-Buffer Method (cont…)
61
of
28
Depth-Buffer Algorithm
1. Initialise the depth buffer and frame buffer
so that for all buffer positions (x, y)
depthBuff(x, y) = 0
frameBuff(x, y) = bgColour
62
of
28
Depth-Buffer Algorithm (cont…)
2. Process each polygon in a scene, one at a
time
– For each projected (x, y) pixel position of a
polygon, calculate the depth z (if not already
known)
– If z >depthBuff(x, y), compute the surface
colour at that position and set
depthBuff(x, y) = z
frameBuff(x, y) = surfColour(x, y)
After all surfaces are processed depthBuff
and frameBuff will store correct values
63
of
28
Calculating Depth
At any surface position the depth is
calculated from the plane equation as:
 Ax  By  D
z
C
For any scan line adjacent x positions differ
by ±1, as do adjacent y positions

 A( x  1)  By  D A
z'  z'  z 
C C
64
of
28
Iterative Calculations
The depth-buffer algorithm proceeds by
starting at the top vertex of the polygon
Then we recursively calculate the x-
coordinate values down a left edge of the
polygon
The x value for the beginning position on
each scan line can be calculated from the
previous one
1
x'  x  where m is the slope
m
65
of
28
Iterative Calculations (cont…)
Depth values along the edge being
considered are calculated using
A B
z'  z  m
C
66
of
28
Iterative Calculations (cont…)

top scan line

y scan line

y - 1 scan line

bottom scan line

x x’
67
of
28
Scan-Line Method
An image space method for identifying
visible surfaces
Computes and compares depth values
along the various scan-lines for a scene
68
of
28
Scan-Line Method (cont…)
Two important tables are maintained:
– The edge table
– The surface facet table
The edge table contains:
– Coordinate end points of each line in the
scene
– The inverse slope of each line
– Pointers into the surface facet table to
connect edges to surfaces
69
of
28
Scan-Line Method (cont…)
The surface facet tables contains:
– The plane coefficients
– Surface material properties
– Maybe pointers into the edge table
70
of
28
Scan-Line Method (cont…)
To facilitate the search for surfaces crossing
a given scan-line an active list of edges is
formed for each scan-line as it is processed
The active list stores only those edges that
cross the scan-line in order of increasing x
Also a flag is set for each surface to indicate
whether a position along a scan-line is either
inside or outside the surface
71
of
28
Scan-Line Method (cont…)
Pixel positions across each scan-line are
processed from left to right
At the left intersection with a surface the
surface flag is turned on
At the right intersection point the flag is
turned off
We only need to perform depth calculations
when more than one surface has its flag
turned on at a certain scan-line position
Images taken from Hearn & Baker, “Computer Graphics with OpenGL” (2004)

of
28
72
Scan Line Method Example
73
of
28
Scan-Line Method Limitations
The scan-line method runs into trouble when
Images taken from Hearn & Baker, “Computer Graphics with OpenGL” (2004)

surfaces cut through each other or otherwise


cyclically overlap
Such surfaces need to be divided
74
of
28
Depth-Sorting Method
A visible surface detection method that uses
both image-space and object-space
operations
Basically, the following two operations are
performed
– Surfaces are sorted in order of decreasing
depth
– Surfaces are scan-converted in order, starting
with the surface of greatest depth
The depth-sorting method is often also known
as the painter’s method
75
of
28
Depth-Sorting Method (cont…)
First, assume that we are viewing along the
z direction
All surfaces in the scene are ordered
according to the smallest z value on each
surface
The surface S at the end of the list is then
compared against all other surfaces to see if
there are any depth overlaps
If no overlaps occur then the surface is scan
converted as before and the process
repeats with the next surface
76
of
28
Depth Overlapping

z z
zmax zmax

S S
z’max
zmin S’
z’max zmin
S’

z’min z’min

x x
No Depth Overlap Depth Overlap
77
of
28
Depth-Sorting Method (cont…)
When there is depth overlap, we make the
following tests:
– The bounding rectangles for the two surfaces
do no overlap
– Surface S is completely behind the
overlapping surface relative to the viewing
position
– The overlapping surface is completely in front
of S realtive to the viewing position
– The boundary edge projections of the two
surfaces onto the view plane do not overlap
78
of
28
Depth-Sorting Method (cont…)
The tests are performed in the order listed
and as soon as one is true we move on to
the next surface
If all tests fail then we swap the orders of the
surfaces
79
of
28
Summary
We need to make sure that we only draw
visible surfaces when rendering scenes
There are a number of techniques for doing
this such as
– Back face detection
– Depth-buffer method
– Scan-line method
Next time we will look at some more
techniques and think about which
techniques are suitable for which situations
Computer Graphics 15:
More Surface Detection Methods

Course Website: http://www.comp.dit.ie/bmacnamee


81
of
11
Contents
Today we will continue to look at visible
surface detection methods:
– Depth-sorting method
82
of
11
Depth-Sorting Method
A visible surface detection method that uses
both image-space and object-space
operations
Basically, the following two operations are
performed
– Surfaces are sorted in order of decreasing
depth
– Surfaces are scan-converted in order, starting
with the surface of greatest depth
The depth-sorting method is often also known
as the painter’s method
83
of
11
Depth-Sorting Method (cont…)
First, assume that we are viewing along the
z direction
All surfaces in the scene are ordered
according to the smallest z value on each
surface
The surface S at the end of the list is then
compared against all other surfaces to see if
there are any depth overlaps
If no overlaps occur then the surface is scan
converted as before and the process
repeats with the next surface
84
of
11
Depth Overlapping

z z
zmax zmax

S S
z’max
zmin S’
z’max zmin
S’

z’min z’min

x x
No Depth Overlap Depth Overlap
85
of
11
Depth-Sorting Method (cont…)
When there is depth overlap, we make the
following tests:
– The bounding rectangles for the two surfaces
do no overlap
– Surface S is completely behind the
overlapping surface relative to the viewing
position
– The overlapping surface is completely in front
of S realtive to the viewing position
– The boundary edge projections of the two
surfaces onto the view plane do not overlap
86
of
11
Depth-Sorting Method (cont…)
The tests are performed in the order listed
and as soon as one is true we move on to
the next surface
If all tests fail then we swap the orders of the
surfaces
Computer Graphics 16:
Illumination

Course Website: http://www.comp.dit.ie/bmacnamee


88
of
50
Contents
Today we will start to look at illumination
models in computer graphics
– Why do we need illumination models?
– Different kinds of lights
– Different kinds of reflections
– Basic lighting model
89
of
50
Why Lighting?
If we don’t have lighting effects nothing
looks three dimensional!
90
of
50
Why Lighting? (cont…)
-To obtain realistic displays of a scene
natural light effects are applied
-An illumination model or a lighting model or
shading model is used to calculate the
intensity of the light that we should see at a
given point on the surface of an object

-A surface rendering algorithm uses intensity


calculations from illumination model to
determine the light intensity for all pixel
positions for various surfaces in the scene.
91
of
50
Light sources
Light viewed from an opaque nonluminous
surface is in general a combination of
reflected light from a light source and
reflections of light from other sources.

Sometime light sources are referred as light


emitting sources and reflecting surfaces are
termed as light reflecting sources.
92
of
50
Point Light Sources
A point source is the simplest
model we can use for a light
source
We simply define:
– The position of the light
– The RGB values for the colour of the light
Light is emitted in all directions
Useful for small light sources
93
of
50
Reflected Light
The colours that we perceive are determined
by the nature of the light reflected from an
object
For example, if white
light is shone onto a Wh
ite Ligh
green object most t
Colours

wavelengths are t
Absorbed

Ligh
absorbed, while green Green

light is reflected from


the object
94
of
50
Surface Lighting Effects
The amount of incident light reflected by a
surface depends on the type of material
Shiny materials reflect more of the incident
light and dull surfaces absorb more of the
incident light
For transparent surfaces some of the light is
also transmitted through the material
95
of
50
Diffuse Reflection
Surfaces that are rough or grainy tend to
reflect light in all directions
This scattered light is called diffuse
reflection
96
of
50
Specular Reflection
Additionally to diffuse reflection some of the
reflected light is concentrated into a highlight
or bright spot
This is called specular reflection
97
of
50
Ambient Light
A surface that is not
exposed to direct light
may still be lit up by
reflections from other
nearby objects –
ambient light
The total reflected light
from a surface is the
sum of the contributions
from light
sources and reflected
light
98
of
50
Example
99
of
50
Example

Ambient Diffuse

Final
Specular Image
100
of
50
Basic Illumination Model
We will consider a basic illumination model
which gives reasonably good results and is
used in most graphics systems
The important components are:
– Ambient light
– Diffuse reflection
– Specular reflection
For the most part we will consider only
monochromatic light
101
of
50
Ambient Light
To incorporate background light we simply
set a general brightness level for a scene
This approximates the global diffuse
reflections from various surfaces within the
scene
We will denote this value as Ia
102
of
50
Diffuse Reflection
First we assume that surfaces reflect
incident light with equal intensity in all
directions
Such surfaces are referred to as ideal
diffuse reflectors or Lambertian reflectors
103
of
50
Diffuse Reflection (cont…)

A parameter kd is set for each surface that


determines the fraction of incident light that
is to be scattered as diffuse reflections from
that surface
This parameter is known as the diffuse-
reflection coefficient or the diffuse
reflectivity
kd is assigned a value between 0.0 and 1.0
– 0.0: dull surface that absorbs almost all light
– 1.0: shiny surface that reflects almost all light
104
of
50
Diffuse Reflection – Ambient Light
For background lighting effects we can
assume that every surface is fully
illuminated by the scene’s ambient light Ia
Therefore the ambient contribution to the
diffuse reflection is given as:
I ambdiff  k d I a
Ambient light alone is very uninteresting so
we need some other lights in a scene as
well
105
of
50
Diffuse Reflection (cont…)
When a surface is illuminated by a light
source, the amount of incident light depends
on the orientation of the surface relative to
the light source direction
106
of
50
Diffuse Reflection
The angle between the incoming light
Images taken from Hearn & Baker, “Computer Graphics with OpenGL” (2004)

direction and a surface normal is referred to


as the angle of incidence given as θ
107
of
50
Diffuse Reflection (cont…)
So the amount of incident light on a surface
is given as:
I l ,incident  I l cos 

So we can model the diffuse reflections as:

I l ,diff  k d I l ,incident
 k d I l cos 
108
of
50
Diffuse Reflection (cont…)
Assuming we denote the
Images taken from Hearn & Baker, “Computer Graphics with OpenGL” (2004)

normal for a surface as N


and the unit direction
vector to the light source
as L then:
N  L  cos 
So:
k d I l ( N  L ) if N  L  0
I l ,diff 
 0 if N  L  0
109
of
Combining Ambient And Incident Diffuse
50 Reflections
To combine the diffuse reflections arising
from ambient and incident light most
graphics packages use two separate diffuse-
reflection coefficients:
– ka for ambient light
– kd for incident light
The total diffuse reflection equation for a
single point source can then be given as:
k a I a  k d I l ( N  L ) if N  L  0
I diff 
 ka I a if N  L  0
110
of
50
Examples
111
of
50
Specular Reflection
The bright spot that we see on a shiny
Images taken from Hearn & Baker, “Computer Graphics with OpenGL” (2004)

surface is the result of near total of the


incident light in a concentrated region
around the specular reflection angle
The specular reflection angle equals the
angle of the incident light
112
of
50
Specular Reflection (cont…)
A perfect mirror reflects light only in the
Images taken from Hearn & Baker, “Computer Graphics with OpenGL” (2004)

specular-reflection direction
Other objects exhibit specular reflections
over a finite range of viewing positions
around vector R
113
of
50
The Phong Specular Reflection Model

The Phong specular reflection model or


Images taken from Hearn & Baker, “Computer Graphics with OpenGL” (2004)

Phong model is an empirical model for


calculating specular reflection range
developed in 1973 by Phong Bui Tuong
The Phong model sets the intensity of
specular reflection as
proportional to the angle
between the viewing
vector and the specular
reflection vector
114
of
The Phong Specular Reflection Model
50 (cont…)
So, the specular reflection intensity is
ns
proportional to cos 
The angle Φ can be varied between 0° and
90° so that cosΦ varies from 1.0 to 0.0
The specular-reflection exponent, ns is
determined by the type of surface we want to
display
– Shiny surfaces have a very large value (>100)
– Rough surfaces would have a value near 1
115
of
The Phong Specular Reflection Model
50 (cont…)
The graphs below show the effect of ns on
Images taken from Hearn & Baker, “Computer Graphics with OpenGL” (2004)

the angular range in which we can expect to


see specular reflections
116
of
The Phong Specular Reflection Model
50 (cont…)
For some materials the amount of specular
reflection depends heavily on the angle of
the incident light
Fresnel’s Laws of Reflection describe in
great detail how specular reflections behave
However, we don’t need to worry about this
and instead approximate the specular
effects with a constant specular reflection
coefficient ks
For an explanation of Fresnel’s laws try here
117
of
The Phong Specular Reflection Model
50 (cont…)
So the specular reflection intensity is given
as:
I l , spec  k s I l cos ns 

Remembering that V  R  cos  we can say:


k s I l (V  R ) ns if V  R  0 and N  L  0
I l , spec 
 0.0 if V  R  0 or N  L  0
118
of
50
Example
119
of
Combining Diffuse & Specular
50 Reflections
For a single light source we can combine the
effects of diffuse and specular reflections
simply as follows:
I  I diff  I spec
k a I a  k d I l ( N  L)  k s I l (V  R ) ns
120
of
Diffuse & Specular Reflections From
50 Multiple Light Sources
We can place any number of light sources in
a scene
We compute the diffuse and specular
reflections as sums of the contributions from
the various sources
n
 

Exam Question
I  I ambdiff   I l ,diff  I l , spec

Common
l 1

 
n
 k a I a   I l k d N  L   k s V  R 
ns

l 1
121
of
50
Summary
T create realistic (or even semi-realistic)
looking scenes we must model light correctly
To successfully model lighting effects we
need to consider:
– Ambient light
– Diffuse reflections
– Specular reflections
Computer Graphics 16:
Polygon Rendering
Methods

Course Website: http://www.comp.dit.ie/bmacnamee


123
of
29
Contents
Today we will start to look at rendering
methods used in computer graphics
– Flat surface rendering
– Gouraud surface rendering
– Phong surface rendering
124
of
29
Flat Surface Rendering
The simplest method for rendering a
polygon surface
The same colour is assigned to all surface
positions
The illumination at a single point on the
surface is calculated and used for the entire
surface
Flat surface rendering is extremely
fast, but can be unrealistic
Images come from:
http://www-static.cc.gatech.edu/classes/AY2004/cs4451a_spring/shading_models/linint.ht

of
29
ml 125

this is SLOW!
Just add lots and lots of polygons – however,
Overcoming Flat Shading Limitations
126
of
29
Gouraud Surface Rendering
Gouraud surface shading was
developed in the 1970s by
Henri Gouraud
Worked at the University of
Utah along with Ivan
Sutherland and David Evans
Often also called intensity-
interpolation surface
rendering
Intensity levels are calculated at each vertex
and interpolated across the surface
127
of
29
Gouraud Surface Rendering (cont…)

To render a polygon, Gouraud surface


rendering proceeds as follows:
1. Determine the average unit normal vector at
each vertex of the polygon
2. Apply an illumination model at each polygon
vertex to obtain the light intensity at that
position
3. Linearly interpolate the vertex intensities over
the projected area of the polygon
128
of
29
Gouraud Surface Rendering (cont…)

The average unit


normal vector at v is
N1
given as:
N1  N 2  N 3  N 4
Nv Nv 
v
N1  N 2  N 3  N 4
N4 N2
or more generally:
n

N3
N i
Nv  i 1
n

N
i 1
i
129
of
29
Gouraud Surface Rendering (cont…)

Illumination values are linearly interpolated


across each scan-line
y
3 y4  y2 y1  y4
I4  I1  I2
y1  y2 y1  y2
1
Scan-line y5  y 2 y 3  y5
4 p 5
I5  I3  I2
y3  y 2 y3  y 2

x5  x p x p  x4
Ip  I4  I5
2 x5  x4 x5  x4
x
130
of
Advantages of Gouraud Surface
29 Rendering
Images come from:
http://www-static.cc.gatech.edu/classes/AY2004/cs4451a_spring/shading_models/linint.ht

of
29
ml 131
Gouraud Surface Rendering Example
132
of
Gouraud Surface Rendering
29 Implementation
Gouraud surfacing rendering can be
implemented relatively efficiently using an
iterative approach
Typically Grouaud shading is implemented
as part of a visible surface detection
technique
133
of
29
Problems With Gouraud Shading
Gouraud shading
tends to miss
certain highlighting
In particular Gouraud
shading has a
problem with specular
reflections
Also, Gouraud shading
can introduce anomalies known as Mach
bands
134
of
Problems With Gouraud Shading
29 (cont…)

Gouraud shading Phong shading

The major problem with Gouraud shading is


in handling specular reflections
135
of
29
Mach Bands
A psychological phenomenon
whereby we see bright bands
where two blocks of solid
colour meet
A good demo is available to
experiment with this at:

http://www.nbb.cornell.edu/ne
urobio/land/OldStudentProject
s/cs490-96to97/anson/MachB
andingApplet/

Try playing with the various


parameters and see if you can
predict what the sphere will
look like
136
of
29
Phong Surface Rendering
A more accurate interpolation based
approach for rendering a polygon was
developed by Phong Bui Tuong
Basically the Phong surface rendering
model (or normal-vector interpolation
rendering) interpolates normal vectors
instead of intensity values
137
of
29
Phong Surface Rendering (cont…)
To render a polygon, Phong surface
rendering proceeds as follows:
1. Determine the average unit normal vector at
each vertex of the polygon
2. Linearly interpolate the vertex normals over
the projected area of the polygon
3. Apply an illumination model at positions along
scan lines to calculate pixel intensities using
the interpolated normal vectors
138
of
29
Phong Surface Rendering (cont…)

N3
y4  y2 y1  y4
N1 N4  N1  N2
y1  y2 y1  y2
y5  y 2 y3  y5
N5  N3  N2
N4 y3  y 2 y3  y 2
Np
Scan line
p N5
y p  y5 y4  y p
Np  N4  N5
y 4  y5 y 4  y5
N2
139
of
Phong Surface Rendering
29 Implementation
Phong shading is much slower than
Gouraud shading as the lighting model is
revaluated so many times
However, there are fast Phong surface
rendering approaches that can be
implemented iteratively
Typically Phong shading is implemented as
part of a visible surface detection technique
Images come from Garry’s Mod:

of
http://www.garry.tv/

29
140
Phong Shading Examples
Images come from Garry’s Mod:

of
http://www.garry.tv/

29
141
Phong Shading Examples
142
of
29
Summary
For realistic rendering of polygons we need
interpolation methods to determine lighting
positions
Flat shading is fast, but unrealistic
Gouraud shading is better, but does not
handle specular reflections very well
Phong shading is better still, but can be slow
Computer Graphics 11: Fractals

Course Website: http://www.comp.dit.ie/bmacnamee


144
of
24
Fractals
All of the modelling techniques covered so
far use Euclidean geometry methods
“Clouds
– Objects are not spheres,
were described usingmountains
equationsare
not cones, coastlines are not circles and
This is finebark
for ismanufactured
not smooth, nor objects
does lightning
But what about
travel innatural objects
a straight line.” that have
irregular or fragmented features? Benoit Mandelbrot
– Mountains, clouds, coral…
145
of
Fractal Geometry Methods & Procedural
24 Modelling
Natural objects can be realistically described
using fractal geometry methods
Fractal methods use procedures rather than
equations to model objects - procedural
modelling
The major characteristic of any procedural
model is that the model is not based on
data, but rather on the implementation of a
procedure following a particular set of rules
Modelling On The Fly!
146
of
24
Fractals
A fractal object has two basic
characteristics:
– Infinite detail at every point
– A certain self similarity between object parts
and the overall features of the object

Mandelbrot Set Video From:


The Koch Curve http://www.fractal-animation.net/ufvp.htm
147
of
24
Generating Fractals
A fractal object is generated by repeatedly
applying a specified transform function to
points in a region of space
If P0 = (x0, y0, z0) is a selected initial position,
each iteration of a transformation function F
generates successive levels of detail with the
calculations:
P1  F P0 , P2  F P1 , P3  F P2 , ...
In general the transformation is applied to a
specified point set, or to a set of primitives
(e.g. lines, curves, surfaces)
148
of
24
Generating Fractals (cont…)
Although fractal objects, by definition have
infinite detail, we only apply the
transformation a finite number of times
Obviously objects we display have finite
dimension – they fit on a page or a screen
A procedural representation approaches a
true representation as we increase the
number of iterations
The amount of detail is limited by the
resolution of the display device, but we can
always zoom in for further detail
Images taken from Hearn & Baker, “Computer Graphics with OpenGL” (2004)

of
24
149
Example: The Koch Snowflake
150
of
24
Example: Ferns
Very similar techniques can be used to
generate vegetation
151
of
24
Fractal Dimension
The amount of variation in the structure of a
fractal object is described as the fractal
dimension, D
– More jagged looking objects have larger
fractal dimensions
Calculating the fractal dimension can be
difficult, especially for particularly complex
fractals
We won’t look at the details of these
calculations
152
of
24
Types Of Fractals
Fractals can be classified into three groups
– Self similar fractals
• These have parts that are scaled down versions of
the entire object
• Commonly used to model trees, shrubs etc
– Self affine fractals
• Have parts that are formed with different scaling
parameters in each dimension
• Typically used for terrain, water and clouds
– Invariant fractal sets
• Fractals formed with non-linear transformations
• Mandelbrot set, Julia set – generally not so useful
153
of
Geometric Construction of Deterministic
24 self similar fractals
Start with a given geometric shape ,called
initiator. Subparts of the initiators are then
replace with a pattern called the generator.
154
of
24

Multiple disjoints component can also be


used as generators.
Fractal dimension
155
of
Random Midpoint Displacement
24 Methods For Topography
One of the most successful uses of fractal
techniques in graphics is the generation of
landscapes
One efficient method for doing this is
random midpoint displacement
156
of
Random Midpoint Displacement
24 Methods For Topography (cont…)
Easy to do in two dimensions
Easily expanded to three dimensions to
generate terrain
Can introduce a roughness factor H to
control terrain appearance
Control surfaces can be used to start with a
general terrain shape

Terrain generation demo:


http://world.std.com/~bgw/applets/1.02/MtFractal/MtFractal.html
157
of
24
Fractals In Film Special Effects
158
of
24
Summary
In today’s lecture we looked at how octrees
and fractals are used in modelling
Fractals in particular are a fairly exotic
modelling technique, but can be extremely
effective
Next time we will look at curved surfaces
which are extremely important
Computer Animation
 Any time sequence of visual changes
in a picture
Computer Animation
 Real-time animation
 Each stage of the sequence is viewed as it is created
 Useful in simulators

 Frame-by-frame animation
 Each frame of the motion is separately generated and
stored
 Used for movies
Raster Method for Computer
Animation
 Double buffering: while the screen is being refreshed
from one buffer, we construct the scene in the other
buffer

 Raster operations
 Block transfers of rectangular arrays of pixel values
 Often used in games
Design of Animation Sequences
 Storyboard layout
 Rough sketches
 A list of basic ideas for the action
 Object definitions
 Each participant in the action
 Basic shapes
 Movements to be performed by each character and object
 Key-frame specifications
 Detailed drawing of the scene at a certain time in the animation sequence
 Generation of in-between frames
 Intermediate frames between the key frames
Key-Frame Systems
 Generate in-between frames from the user-
specified key frames (two or more)
 Complex scenes separated into individual
components called cels
Morphing
 Transformation of object shapes from one to
another
Morphing
 Transforming a line segment
 Given two frames first adjust the object specification in one of the frames so that the number of polygon edges is same for the two
frames

added
point
key frame k e
halfway fram
key frame k+1
General processing rule for
equalizing key frames
 Lk and Lk+1 denote the no of line segments in two key
frames
 Lmax = max (Lk,Lk+1) and Lmin= min(Lk,Lk+1)
Ne = Lmax mod Lmin
Ns = int (Lmax/Lmin)
Then preprocessing is done by:
1. Dividing Ne edges of Keyframemin into Ns+1 section
2. Dividing the remaining line of keyframe min into Ns
sections.
 Vertex can be equalized :
 Vmax =max( V ,V ) Vmin=min(V ,V )
k k+1 k k+1
Nls=(Vmax-1)mod(Vmin-1)
Np=int(Vmax-1/Vmin -1)
Preprocessing is done:
1.Adding Np points to Nls line section of Keyframemin
2.Adding Np -1 points to the remaining edges of
Keyframemin
Morphing
 Transforming a triangle into a quadrilateral

added
point
key frame k halfway frame key frame k+1
Simulating Acceleration
 Curve fitting techniques are often used to
specify the animation paths between Key
frames.
 With the given vertex positions at key frames ,
positions can be fitted with linear or nonlinear
paths which determines the trajectory for the
in-betweens.
 To simulate the acceleration we can adjust the
time spacing for the in betweens.
For constant speed or zero acceleration:
If we need n in-betweens for key frames at time
t1 and t2 the time interval between key frames
is divided into equal n+1 sub intervals with
∆t= t2-t1/n+1
Ant time for any in-between can be calculated as
tbj= t1+j ∆t where j= 1,2,3…n
 Realistic displays are produced using nonzero
acceleration
 Trigonometric functions can be used to model start up
and slowdown positions of animation path
 A function for increasing speed : 1- cosθ 0< θ<Π/2
 For n in-betweens the time for jth in-between then
calculated as
 tbj= t1+ ∆t(1-cos j Π/2(n+1)) where j=1,2,3..n
 For decreasing speed
 tbj= t1+ ∆t sin j Π/2(n+1) where j=1,2,3..n
Motion Specification
 Direct specification of geometric transformation
(transformation matrix)
 Equation of the path
 Bouncing ball: y ( x)  A sin( x   0 ) e  kx
Goal directed motion
Goals are specified that describe the parameter
of motion
kinematics and dynamics:

You might also like