Last Part
Last Part
Spline Representations
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)
of
24
13
Bézier Spline Curves (cont…)
14
of
24
Important Properties Of Bézier Curves
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
-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 kin (1.3)
n–k+2 n < i n+k
e.g k=2, n = 3
0 0 i < 2
ui = i–2+1 2i3
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.
P(u) = Ni,k(u)pi
i=0
2
• = Ni,3(u)pi
i=0
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–1uNu
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–1uNu
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
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…)
y scan line
y - 1 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)
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
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
wavelengths are t
Absorbed
Ligh
absorbed, while green Green
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…)
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)
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
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
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…)
N3
N i
Nv i 1
n
N
i 1
i
129
of
29
Gouraud Surface Rendering (cont…)
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…)
http://www.nbb.cornell.edu/ne
urobio/land/OldStudentProject
s/cs490-96to97/anson/MachB
andingApplet/
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
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
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: