Computer Graphics

Download Report

Transcript Computer Graphics

Basic Modelling
1
Lecture Objectives
To understand how 3D scenes can be
modelled - in terms of geometry,
appearance and behaviour - and
rendered on a display
 To understand how to deliver
interactive animated 3D graphics over
the Internet
 To be able to create interactive 3D
graphics applications using industry
standard software (OpenGL and
VRML)

2
The Basics

MODELLING
– representing objects in 3D
– transforming objects and composing scenes

VIEWING
– projecting 3D scenes onto a 2D display surface

RENDERING
– illumination
– shading
– adding realism via textures, shadows
3
Basic Modelling
y
z
x
objects represented
as set of faces - ie
polygons- and faces
as a set of points
scenes composed
by scaling, rotating,
translating objects to
create a 3D world
4
Viewing

Clipping
– selects a volume of interest
– Projection
– 3D scene is projected onto a 2D plane
camera
5
Rendering
illumination:
how is light reflected
from surfaces?
shading:
how do we use our
knowledge of illumination
to shade surfaces in our
world?
6
Rendering

texture

shadows
7
Internet

VRML
– ISO standard for 3D graphics over the Web
– allows modelling of geometry,
appearance and behaviour
8
Advanced Rendering

ADVANCED RENDERING
– direct versus global illumination methods
– ray tracing and radiosity

OTHER ADVANCED FEATURES
– curve and surface modelling
– image based rendering
– non-photorealistic rendering
9
Advanced Rendering

Advanced Rendering - global
illumination
objects
– ray tracing
eye
screen
light
– radiosity
based on physics of radioactive heat
transfer between surfaces
10
Before we begin...mathematics!

3D Co-ordinate Systems
y
y
z
x
LEFT
z points away
x
z
RIGHT
z points toward
Align thumb with x, first finger with y, then second finger
of appropriate hand gives z direction. Common now to
use a RIGHT HANDED system.
11
Points and Vectors

We shall write points as column
vectors
y
P =
x
y
z
P
x
z
Difference of two points gives a direction vector:
D = P 2 - P1
y
P2
z
P1
x
Note: If P1 and P2
are on a plane, then
D lies in the plane
12
Polygonal Representation

Any 3D object can be represented as
a set of plane, polygonal surfaces
V7
V8
V3
V4
V6
V5
V2
V1
Note: each vertex part of several
polygons
13
Polygonal Representation

Objects with curved surfaces can be
approximated by polygons improved approximation by more
polygons
14
Scene Organisation
Scene = list of objects
 Object = list of surfaces
 Surface = list of polygons
 Polygon = list of vertices

scene
object
vertices
surfaces
polygons
15
Polygon Data Structure
V7
Object Obj1
V8
V3
V2
V4
V6
V5
P2
V1
P1
Object Table
Obj1 P1, P2, P3,
P4, P5, P6
Polygon Table
P1
V1, V2, V3, V4
P2
V1, V5, V6, V2
.
...
Vertex Table
V1 X1, Y1, Z1
V2 X2, Y2, Z2
.
...
16
Typical Primitives

Graphics systems such as OpenGL
typically support:
– triangles, triangle strips and fans
– quads, quad strips
– polygons

Which way is front?
– convention is that normal points towards
you if vertices are specified counterclockwise
17
Modelling Regular Objects

Sweeping
sweep axis
2D Profile

Spinning
R1
R2
spinning axis
18
Sweeping a Circle to Generate a
Cylinder as Polygons
V13
V4
V5
V9
V11
V3
V2
V1
V6
V12
V10
V14
V15
V18
V17
V16
vertices at z=depth
V8
V7
vertices at z=0
V1[x] = R; V1[y] = 0; V1[z] = 0
V2[x] = R cos ; V2[y] = R sin ; V2[z] = 0 (=p/4)
Vk[x] = R cos k; Vk[y] = R sin k; Vk[z] = 0
where
k = 2 p (k - 1 )/8, k=1,2,..8
19
Complex Primitives

Some systems such as VRML have
cylinders, cones, etc as primitives
– polygonal representation calculated
automatically

OpenGL has a utility library (GLU)
which contains various high-level
primitives
– again converted to polygons

For conventional graphics hardware:
– POLYGONS RULE!
20
Automatic Generation of
Polygonal Objects

3D scanners - or laser rangers - are
able to generate computer
representations of objects
– object sits on rotating table
– contour outline generated for a given
height
– scanner moves up a level and next
contour created
– successive contours stitched together to
give polygonal representation
21
A Puzzle
22
Modelling Objects and Creating
Worlds
We have seen how boundary
representations of simple objects can
be created
 Typically each object is created in its
own co-ordinate system
 To create a world, we need to
understand how to transform objects
so as to place them in the right place translation, at the right size - scaling, in
the right orientation- rotation

23
Transformations

The basic linear transformations are:
– translation: P = P + T, where T is translation
vector
– scaling: P’ = S P, where S is a scaling
matrix
– rotation: P’ = R P, where R is a rotation
matrix

As in 2D graphics, we use
homogeneous co-ordinates in order to
express all transformations as matrices
and allow them to be combined easily
24
Homogeneous Co-ordinates
In homogeneous coordinates, a 3D point
P = (x,y,z)T
is represented as:
P = (x,y,z,1)T
 That is, a point in 4D space, with its ‘extra’
co-ordinate equal to 1
 Note: in homogeneous co-ordinates,
multiplication by a constant leaves point
unchanged

– ie (x, y, z, 1)T = (wx, wy, wz, w)T
25
Translation
Suppose we want to translate P (x,y,z)T
by a distance (Tx, Ty, Tz)T
 We express P as (x, y, z, 1)T and form a
translation matrix T as below
 The translated point is P’

x’
y’
z’
1
=
P’
=
1
0
0
0
0
1
0
0
0
0
1
0
T
Tx
Ty
Tz
1
x
y
z
1
P
=
x + Tx
y + Ty
z + Tz
1
26
Scaling

Scaling by Sx, Sy, Sz relative to the
origin:
x’
y’
z’
1
=
P’
=
Sx
0
0
0
0
Sy
0
0
S
0
0
Sz
0
0
0
0
1
x
y
z
1
=
Sx . x
Sy . y
Sz . z
1
P
27
Rotation
Rotation is specified with respect to an
axis - easiest to start with co-ordinate
axes
 To rotate about the x-axis:

x’
y’
z’
1
=
P’
=
1
0
0
0 cos -sin
0 sin cos
0 0
0
Rz ()
0
0
0
1
x
y
z
1
P
a positive angle corresponds to counter-clockwise direction looking
at origin from positive position on axis
28
Composite Transformations
The attraction of homogeneous co-ordinates
is that a sequence of transformations may
be encapsulated as a single matrix
 For example, scaling with respect to a fixed
position (a,b,c) can be achieved by:

– translate fixed point to origin- say, T(-a,-b,-c)
– scale- S
– translate fixed point back to its starting positionT(a,b,c)

Thus: P’ = T(a,b,c) S T(-a,-b,-c) P = M P
29
Rotation about a Specified Axis
It is useful to be able to rotate about
any axis in 3D space
 This is achieved by composing 7
elementary transformations

30
Rotation through  about
Specified Axis
y
y
P2
y
P1
x
x
z
z
z
translate P1
to origin
initial position
y
y
x
z
x
rotate through
requ’d angle, 
y
x
z
rotate so that
P2 lies on z-axis
(2 rotations)
z
rotate axis
to orig orientation
P2
P1
x
translate back
31
Inverse Transformations

As in this example, it is often useful to
calculate the inverse of a
transformation
– ie the transformation that returns to
original state
Translation: T-1 (a, b, c) = T (-a, -b, -c)
 Scaling: S-1 ( Sx, Sy, Sz ) = S ............
 Rotation: R-1z () = Rz (-)

32
SEN 992 Computer Graphics I
Viewing - Projections
33
Viewing
Graphics display devices are 2D
rectangular screens
 Hence we need to understand how to
transform our 3D world to a 2D surface
 This involves:

– selecting the observer position (or camera
position)
– selecting the view plane (or camera film
plane)
– selecting the type of projection
34
Perspective Projections
There are two types of projection:
perspective and parallel
 In a perspective projection, object
positions are projected onto the view
plane along lines which converge at
the observer

P1
P2
P1’
camera
P2’
view plane
35
Parallel Projection

In a parallel projection, the observer
position is at an infinite distance, so
the projection lines are parallel
P1
P2
view plane
36
Perspective and Parallel
Projection
Parallel projection preserves the
relative proportions of objects, but
does not give a realistic view
 Perspective projection gives realistic
views, but does not preserve
proportions

– Projections of distant objects are smaller
than projections of objects of the same
size which are closer to the view plane
37
Perspective and Parallel
Projection
perspective
parallel
38
Viewing Coordinate System

Viewing is easier if we work in a
viewing co-ordinate system, where the
observer or camera position is on the
z-axis, looking along the negative zdirection
yV
xV
zV
Camera is positioned at:
(0 , 0, zC)
39
View Plane

We assume the view plane is
perpendicular to the viewing direction
yv
The view plane
is positioned at:
(0, 0, zVP)
xv
zv
Let d = zC - zVP be the
distance between the
camera and the plane
40
Perspective Projection Calculation
yv
Q
xv
zv
yV
camera
zQ
zVP
view plane
zC
zV
looking along x-axis
41
Perspective Projection Calculation
Q
P
yV
camera
zQ
zVP
view plane
By similar triangles,
yP / yQ = (zC - zVP) / (zC - zQ)
and so
yP = yQ * (zC - zVP) / (zC - zQ)
or
yP = yQ * d / (zC - zQ)
zC
zV
xP likewise
42
Transformation Matrix for
Perspective
1
0
0
0
xQ
yH
0
1
0
0
yQ
zH
0
0 -zVP/d zVPzC/d
zQ
wH
0
0 -1/d
1
xH
=
Then xP = xH / wH
ie
xP = xH / ( (zC - zQ) / d )
ie
xP = xQ / ( (zC - zQ) / d )
zC/d
yP likewise
43
Note for Later

The original z co-ordinate of points is
retained
– we need relative depth in the scene in
order to sort out which faces are visible to
the camera
44
Vanishing Points

When a 3D object is projected onto a
view plane using perspective, parallel
lines in object NOT parallel to the view
plane converge to a vanishing point
vanishing point
one-point
perspective
projection
of cube
view plane
45
One- and Two-Point Perspective
Drawing
46
One-point Perspective
This is:
Trinity with the Virgin,
St John and Donors,
by Mastaccio in 1427
Said to be the first
painting in perspective
47
Two-point Perspective
Edward
Hopper
Lighthouse
at Two Lights
-see
www.postershop.com
48
Parallel Projection - Two types

Orthographic parallel
projection has view
plane perpendicular to
direction of projection

P1
P2
Oblique parallel
projection has view plane
at an oblique angle to
direction of projection
P1
P2
view plane
We shall only consider orthographic projection
view plane
49
Parallel Projection Calculation
yv
Q
xv
zv
yV
zQ
zVP
view plane
zV
looking along x-axis
50
Parallel Projection Calculation
Q
P
yV
view plane
zV
yP = y Q
and similarly xP = xQ
51
Parallel Projection Calculation

So this is much easier than
perspective!
– xP = xQ
– yP = yQ
– zP = zVP

The transformation matrix is simply
1
0
0
0
0
1
0
0
0
0
0
0
zVP/zQ 0
0
1
52
View Volumes - View Window

Type of lens in a camera is one factor which
determines how much of the view is
captured
– wide angle lens captures more than regular lens

Analogy in computer graphics is the view
window, a rectangle in the view plane
view window
yv
xv
zv
53
View Volume - Front and Back
Planes
We will also typically want to limit the
view in the zV direction
 We define two planes, each parallel to
the view plane, to achieve this

– front plane (or near plane)
– back plane (or far plane)
zV
back plane
front plane
54
View Frustum - Perspective
Projection
back
plane
view frustum
view window
camera
front
plane
zV
55
View Volume - Parallel Projection
back
plane
view volume
view window
front
plane
zV
56
View Volume
The front and back planes act as
important clipping planes
 Can be used to select part of a scene
we want to view
 Front plane important in perspective to
remove near objects which will
swamp picture

57
SEN 992 Computer Graphics I
VRML - An Introduction
58
Good Ideas are Simple

Realization 1:
– Hypertext + Internet = World Wide Web

Realization 2:
– Adding images makes pages more interesting

Realization 3:
– Images are pictures taken by the publisher why not send 3D scenes and allow the user to
take the picture!

VRML: Virtual Reality Modelling Language
– a language to describe 3D worlds - for the
Web
59
World Wide Web Pages
AUTHORING
PROCESS
INTERNET
HTML
file
.html
server
WEB
BROWSER
text/
html
MIME
type
client
60
VRML
AUTHORING
PROCESS
INTERNET
VRML
file
.wrl
server
VRML
BROWSER
x-world/
x-vrml
client
Major browser:
CosmoPlayer
61
Advantages of VRML

Transferring a 3D model - rather than a
2D image - to the browser has great
advantages
– viewer can choose how to look at the
model - or world
– viewer can navigate the world
– file size can often be much less
62
How Did It All Begin?

Original brainwave
– Mark Pesce and Tony Parisi - early 1994
– vision of a VR interface to the Web

VRML 1.0
– practical realisation based on Open
Inventor (Silicon Graphics toolkit - similar
to OpenGL but higher level)
– Open Inventor file format PLUS hyperlinks
– static, non-interactive worlds
– Gavin Bell (SGI) - late 1994
63
Where are we now?

VRML97
– adds object behaviours and interaction to
allow creation of dynamic worlds
– ISO standard - December 1997
– Gavin Bell, Rikk Carey (ex-SGI) and Chris
Marrin (SGI)

2000
– being reworked as XML (X3D)
– many new developments
64
A VRML File
VRML file consists of:
 header
 nodes
– objects such as
cylinders and
spheres
– operations such as
transformations

fields
– parameters of nodes
#VRML V2.0 utf8
Shape {
geometry Cylinder {
radius
3
height
6
}
}
65
As Seen By A Browser
#VRML V2.0 utf8
Shape {
geometry Cylinder {
radius
2
height
4
}
}
66
Adding Color to the Scene
#VRML V2.0 utf8
Shape {
geometry Cylinder {
radius
2
height
4
}
appearance Appearance {
material Material {
diffuseColor 1 0 0
specularColor 1 1 1 }
}
}
67
Co-ordinate Systems

Each node is drawn
within its own local
co-ordinate system..
y
x
z
68
Modelling Transformations



...and can be
subjected to a
modelling
transformation to
scale, rotate,
translate
Transform is a VRML
node - treated just
like an object
It applies to a group
of children nodes
#VRML V2.0 utf8
Transform{
scale
5.0 0.5 1.0
children [
Shape {
geometry Cylinder {
radius
2
height
4
}
appearance Appearance {
material Material {
diffuseColor 1 0 0
specularColor 1 1 1 }
}}]}
69
Hierarchical Structure
parent
TRANSFORM
child
SHAPE
#VRML V2.0 utf8
Transform{
scale
5.0 0.5 1.0
children [
Shape {
geometry Cylinder {
radius
2
height
4
}
appearance Appearance {
material Material {
diffuseColor 1 0 0
specularColor 1 1 1 }
}}]}
70
Hierarchical Structure

TRANSFORM
SHAPE

TRANSFORM
SHAPE
This generalises to
allow nodes to
appear in a
hierarchy
This is known as the
VRML scene graph
SHAPE
71
Transformations


Here we see Cylinder,
Sphere and Cone
nodes
Each has been
subjected to a
modelling
transformation in
order to position them
72
Instances



A node can be
given a ‘name’ and
then used multiple
times - with different
transformations
applied to each
DEF kwb Shape {...}
gives it a name
USE kwb allows it to
be included at other
points in the scene
graph
73
Anchors

A piece of
geometry can act
as a link to another
URL
74
Textures


Texture mapping: Images
can be mapped to
geometry to provide
texturing
VRML looks like:
Shape{
geometry Sphere { }
appearance Appearance{
texture ImageTexture{
url “http://..../kwb.gif”}
75
Polygonal Surfaces

The general
primitive for drawing
polygonal surfaces
is:
– IndexedFaceSet
– coord field lists the
points
– coordIndex
describes the
polygons
Shape{
geometry IndexedFaceSet {
coord Coordinate {
point [ 17.5 11.2 -1.2,
17.5 15.0 -1.2,
…]
}
coordIndex [ 0 1 2 3 -1,
4 1 0 5 -1,
…]
}
}
76
Lights

VRML includes:
– DirectionalLight
– PointLight
– SpotLight

Note # sign is a
comment
Example:
PointLight{
on
intensity
color
location
radius
}
TRUE
0.75
1 0 0 #red
000
100
77
Viewing



Specified via the
Viewpoint node
VRML file can have
a number of
Viewpoint nodes browsers allow a
user to jump from
one viewpoint to
another
Orientation = axis +
angle of rotation
Example:
Viewpoint {
position
orientation
description
}
005
0 0 1 0.3
“frontview”
78
Other Basic Features

Inline node
– incorporate VRML code from another url
– this allows us to compose large worlds
from many smaller ones

Level of Detail
– different geometric representations
depending on distance
79
Information About VRML

Web3D Consortium
– http://www.web3d.org
– links to specifications and resources

Web3D Information
– http://web3d.about.com/compute/web3d

Leeds University VRML/Java3D Information
Centre
– http://www.scs.leeds.ac.uk/vrmljava3d

VRML Repository
– http://www.sdsc.edu/vrml/
80
Books and Tutorials

Range of books now available
– The VRML 2.0 Handbook (Addison Wesley)
Jed Hartman and Josie Wernecke
http://vrml.sgi.com/handbook
– The Annotated VRML Reference Book (Addison
Wesley)
Rikk Carey and Gavin Bell
http://www.best.com/~rikk/Book/

Tutorials include:
– Floppy’s guide: www.vapourtech.com/vrmlguide
81