# TNM046 Introduction to Computer Graphics, Lecture 3 (Geometric

Document Sample

```					TNM046: Introduction to Computer Graphics,
Lecture 3 (Geometric operations)

Mark Eric Dieckmann,
VITA, ITN
o
o
Campus Norrk¨ping
o
SE-60174 Norrk¨ping

April 25, 2010
Content of lecture

◮   We have learned so far about how to deﬁne polygonal and
implicit objects and about how to transform their vertices.

◮   Now we develop a systematic framework, which deﬁnes

1. the necessary coordinate systems.
So far we know the local coordinate system and the global
coordinate system.

2. which graphics algorithms are implemented in each of the
coordinate systems.

◮   Algorithms that make use of the geometry (triangle plane and
normal) are discussed in the present lecture.
The graphics pipeline

◮   We understand the object deﬁnition in the local coordinate
system and the modelling transformation.
◮   Now, the geometric operations in the world coordinate system
and in the view coordinate system are discussed. These are:
1. Lighting and the camera (world system).
2. Culling, painters algorithm and clipping (View space).
World and view coordinate system

◮   The local coordinate system is attached to the object.
◮   The world (global) coordinate system is attached to the room:
The position and orientation of one local coordinate system or
more are speciﬁed in this system.
The objects move in the global system.
Light sources are deﬁned in the world coordinate system.
The camera is placed in this room.
◮   The view coordinate system is attached to the camera.
The visibility is determined in this system.
World coordinate system: Light source

First case: Light source at inﬁnity:

f3                                     ◮   All light rays are parallel
L
and can be described by:
The light direction L.
L

e3                                ◮   The light direction is
e1                    compared with a surface
normal N.
N
e2
o1
◮   The N is computed in the
o2                            f1           world coordinate system.

The object vertices have been transformed into the world space
prior to the normal calculation.
World coordinate system: Light source

First case: Light source at inﬁnity:

e3                    L
◮   For simplicity: Consider a
N4                                         local coordinate system and
N1                 normals at four points on
the sphere’s surface.
◮   The normals are N1 , N2 , N3
e1                and N4 .
◮   For practical reasons, the
N3                    N2                  intensity is deﬁned as going
from 0 (dark) to 1 (bright).

What intensity should the 4 surface points get?
World coordinate system: Light source

First case: Light source at inﬁnity:

e3                    L
◮   We expect an intensity
N4                                         maximum at the surface
N1                 point with the normal N1 .
◮   The intensity should be 0
at the surface points with
e1                the normals N2 , N4 .
◮   The intensity should also
N3                    N2                  be 0 at the point with the
normal N3 .

The intensity cannot be negative.
World coordinate system: Light source

First case: Light source at inﬁnity:

Combine the light direction L = (Lx , Ly , Lz ) and the normal
direction Nj = (Nx , Ny , Nz )t of triangle j to give an intensity Ij .
j

Triangle j                             ◮   The intensity should
Nj
(maximum) to 0 (no light).
L             ◮   The intensity calculation
should be fast: Preferably
only: +, -, *, /.
◮   L and N are normalized!

Implementation: Calculate the intensity according to
Step 1: Ij = (−1) · L · Nj followed by Step 2: If Ij < 0 then Ij = 0.
World coordinate system: Light source
Second case: Point light source:
◮   We need to introduce two new aspects into the illumination.
1. The light direction becomes a function of the light position
and the position of a surface point.
2. The light intensity depends on the distance between the light
and the object.
◮   Both these aspects are captured by the distance vector d.
Triangle                            ◮   We calculate the distance
vector as d = X − Y .
N
X                                   ◮   Use du = d/||d || as the
light source direction.
d            Y
◮   The distance is r = ||d||.
Light
source
World coordinate system: Light source

Second case: Point light source:

Triangle                           ◮   You pick one X of the
triangle, if you want one
N                          intensity Ij per triangle j.
X                                  ◮   Smooth intensity: calculate
it for many points X .
d               Y     ◮   The distance r = ||d||.
Light
source
◮   The light source direction
is du = d/||d ||.

Step 1: Ij = (−1/r s ) · du · Nj . Step 2: If Ij < 0 then Ij = 0.
Physically correct: s = 2. The limited intensity range (256
currently possible values) often forces us to use s = 1.
World coordinate system: Light source

Third case: Two light sources that are inﬁnitely far away:
Light
source 2
◮   Consider a light source 1
L2
with light direction L1 .
Triangle

Normal              ◮   The light source 2 has the
light direction L2 .
Light
L1            source 1   ◮   We calculate the intensity
IL1 and IL2 separately.

Step 1: IL1 = (−1) · L1 · N. Step 2: If IL1 < 0 then IL1 = 0.
Step 3: IL2 = (−1) · L2 · N. Step 4: If IL2 < 0 then IL2 = 0.
World coordinate system: Light source

Third case: Two light sources that are inﬁnitely far away:

◮   We calculated separately the intensity contributions IL1 from
lightsource 1 and IL2 from lightsource 2.

◮   Intensities are additive. The total intensity we give to the
triangle is Ij = IL1 + IL2 .

◮   The intensities are limited (||L1 || = ||L2 || = ||N|| = 1) to the
range 0 ≤ IL1 ≤ 1 and 0 ≤ IL2 ≤ 1.
However, Ij = IL1 + IL2 can be larger than 1.

◮   One possible solution is to set Ij = 1 if Ij > 1.
World coordinate system: The camera

f3                                       ◮   A view coordinate system is
View direction     X                deﬁned by its origin o3 and
o3
Z                                    by three coordinate axes X ,
View plane       Y and Z .
f2
Y                   ◮   The view coordinate system
is deﬁned with the right
hand. The thumb points
along X , the index ﬁnger
f1
along Y and the middle
o2 World coordinate system
ﬁnger points along Z .

We typically prescribe the position of the camera o3 and the view
direction Z .
World coordinate system: The camera

Now we want to deﬁne the directions of X and Y . A reference is
the ’up’ direction f3 in the world coordinate system.
Z
o3
Find a vector Y that:
◮   is orthogonal to the view
direction Z and
f3
◮   that lies in the plane
spanned by Z and f3 .
◮   points downwards relative
o2                                 to f3 , which means
Y                 f3 · Y < 0.

One method: Get ﬁrst X by calculating X ∗ = Z × f3 and
X = X ∗ /||X ∗ ||. Then calculate Y = Z × X .
View (camera) coordinate system: Culling

◮   We have illuminated the object triangles in the world
coordinate system with the origin o2 and the axes f1 , f2 and f3 .
◮   The camera system with the origin o3 (camera position), the
axis Z (view direction) and the axes X and Y has been
deﬁned in the world system.
◮   Now we ﬁnd the matrix for the coordinate system
transformation between both.
◮   The object(s) are transformed from the world coordinate
system into the view coordinate system.
◮   The objects are tested for visibility in this view coordinate
system. We discuss culling and the painters algorithm.
View (camera) coordinate system: Culling

How do we determine whether or not a triangle is visible?

Triangle normals N j         ◮   Our view direction is V . It
is V t = (0, 0, 1) in JAVA.
View direction V   ◮   The normal of the triangle
j is Nj .
◮   The triangle is visible, if the
normal points towards us.

We test for visibility with the scalar product S = Nj · V .
The triangle is visible if S ≤ 0 and not visible if S > 0.
View (camera) coordinate system: Culling

Culling works ﬁne if we have one convex object.
Object 1                     Object 2

Visible                    Visible        View
direction
Invisible                  Invisible
N1                         N2     V

◮   The view direction is V .
◮   Culling will remove the back sides of both objects.
◮   The triangles with the normals N1 and N2 are both ’visible’
⇒ Culling can not remove the front side of the left object.
View (camera) coordinate system: Culling

Culling can fail even if we have only one object.

An example for a concave
object is a torus.
If you look at it from above, it
is a ring (one object): Culling
works.
The torus from the side can
appear as two objects one after
another: Culling fails.

Culling is an elegant method to remove back sides of objects, but
in practice we need methods that always work.
View coordinate system: Hidden surface removal

A second elegant method to remove hidden surfaces is the painters
algorithm (it can fail too).
Let us consider the three triangles T1 , T2 and T3 .
T2

View
P2                direction
P1                   P3              O3
V

T1                    T3
A view ray intersects the triangles at the points P1 , P2 and P3 .
These points have diﬀerent distances from the origin O3 .
The painters algorithm makes use of these distances.
View coordinate system: Hidden surface removal

How can we make use of the distances in the view coordinate
system deﬁned by X , Y and Z ?
The Z -axis is the view direction and we use a parallel projection.
T1
T2                      We have two triangles T1 , T2 .
z1
X
Select points P1 and P2 .
P1        P2
z2           Take the z-values of the
Z                                       position vectors of P1 and P2 .
These are z1 and z2 .
Generate a list, which stores the
Y
z-values of the points.

Our list has information about the triangle number (in the triangle
list) and about its distance from the view plane.
View coordinate system: Hidden surface removal
Let us assume that we have 5 triangles, which are initially ordered
randomly according to their distance.

                                                                
Triangle   Distance                      Triangle   Distance

      T1         10      


        T5         11      


      T2          7                  
 Sorting :⇒         T1         10      


      T3          3      


        T4          8      

      T4          8                          T2          7      
T5         11                            T3          3

We get from the left list to the right list by sorting the triangles
according to their distance.
Draw the triangles from the top to the bottom in the list.
If there is an overlap between triangles, then the closer one
overplots the farther one.
View coordinate system: Hidden surface removal

Example: The ﬁgure shows ﬁve example triangles, which are
overplotted according to the distance list on the right side.

                         
T4                    T3               Triangle   Distance

      T5         11      

Y

      T1         10      


      T4          8      

T1             T5
      T2          7      
T3          3
T2

X

The painters algorithm works well if the typical distances are large
compared to the triangle sizes: Then the ordering is simple.
View coordinate system: Hidden surface removal

Problem: Consider triangles that are close compared to their size.
We list the triangles according to their distance along the Z -axis.
X◮
The point P1 determines
Z                                         the distance of triangle T1 .
P3
T2
◮   If we use the point P2 to
determine the distance of
P1
T2 , then T2 is farther away.
P2   T1
◮   If we use the point P3
T2 is closer to us.

The problem gets worse if the triangles intersect.
View coordinate system: Clipping

The ﬁeld of view is not unlimited. We deﬁne in this case the view
volume (for the case of a perspective projection).

◮   The eye point denotes the
observer position.
Far clip plane
◮   The view plane is the
View volume
computer screen.
Eye                                     Z

View plane                       ◮   No objects closer than the
Near                                       near clip plane or farther
clip plane                                 than the far clip plane
Y
should be shown.

Clipping must now separate the visible from the invisible objects.
View coordinate system: Clipping

◮   The most widely used computer graphics objects are
polygonal objects, e.g. those composed of triangles.
◮   Objects can consist of millions of triangles ⇒ Testing each
triangle against the clip planes is expensive.
◮   Signiﬁcant amounts of computations are unnecessary, if we
use bounding boxes or spheres.
◮   Such a bounding object acts as a wrapper around each
polygonal object.
◮   The bounding object, rather than the individual polygons, can
now be tested against the clip planes.
View coordinate system: Clipping
Example: A bounding sphere and the upper clip plane.
Clip plane ◮
Given is a polygonal object.
P
◮   We wrap around it a sphere
C                               center at C .
O3                              Z
◮   A line is x = C + λNcp ,
where Ncp is the normal of
the upper clip plane.
◮   It intersects the upper clip
Y                           Clip plane       plane at the point P.

If ||(o3 P) − C || ≥ R, then the upper clip plane does not intersect
the bounding sphere and, thus, any object triangle. The object is
either outside or inside the view volume.
View coordinate system: Clipping

Example: Clipping of a triangle against the view plane.
Assumption: The triangle has been projected onto the view plane.
X          Initially given: The points
P3        P1 , P2 , P3 (triangle list) and the
position vectors (vertex list).
I2
P1
We calculate the intersection
points I1 , I2 between the triangle
I1
P2   edges and the view plane
View plane           Triangle        boundary.

Y

A temporary vertex list and triangle list take the points P1 , I1 and
I2 . The P2 and P3 are discarded. The clipped triangle is plotted.
Summary lecture 3

◮   The graphics pipeline has been deﬁned.
◮   Some simple light source and illumination models have been
discussed.
◮   A camera has been placed into the world coordinate system,
which deﬁnes the view coordinate system.
◮   Culling and hidden surface removal has been introduced.
These methods do, however, not always work.
◮   It has been sketched out, how clipping removes the invisible
objects or components.

```
DOCUMENT INFO
Shared By:
Categories:
Stats:
 views: 55 posted: 6/4/2010 language: English pages: 28
How are you planning on using Docstoc?