computer graphics i. images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98...

79
Computer Graphics I

Upload: loreen-lauren-lewis

Post on 29-Dec-2015

222 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Computer Graphics I

Page 2: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Images in a computer...

94 100 104 119 125 136 143 153 157 158103 104 106 98 103 119 141 155 159 160109 136 136 123 95 78 117 149 155 160110 130 144 149 129 78 97 151 161 158109 137 178 167 119 78 101 185 188 161100 143 167 134 87 85 134 216 209 172104 123 166 161 155 160 205 229 218 181125 131 172 179 180 208 238 237 228 200131 148 172 175 188 228 239 238 228 206161 169 162 163 193 228 230 237 220 199

… just a large array of numbers

Page 3: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

True-color frame buffer

Store R,G,B values directly in the frame-buffer.

Each pixel requires at least 3 bytes => 2^24 colors.

Page 4: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Indexed-color frame buffer

Store index into a color map in the frame-buffer.

Each pixel requires at least 1 bytes => 2^8 simultaneous colors.

Enables color-map animations.

Page 5: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Drawing lines

Page 6: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Line algorithm 5, BresenhamBrushing up things a little

Xdifference = (Xend-Xstart)Ydifference = (Yend-Ystart)

Yerror = 2*Ydifference - XdifferenceStepEast = 2*YdifferenceStepNorthEast = 2*Ydifference - 2*Xdifference

put_pixel(x, y)loop x Xstart to Xend if Yerror <= 0 then Yerror = Yerror + StepEast else y = y + 1 Yerror = Yerror + StepNorthEast end_if put_pixel(x, y)end_of_loop x

Uses only integermaths => Fast!

Page 7: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Drawing polygonsWe draw our polygons scan line byscan line. This is called scan conversion.

The process is done by following theedges of the polygon, and then fillbetween the edges.

Page 8: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Bi-linear interpolationLinear interpolation in two directions.First we interpolate in the y-direction,then we interpolate in the x-direction.Unique solution for flat objects (triangles are

always flat.)

Page 9: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Anti-aliasingDue to the discrete nature of our computers, aliasing effects appear in many situations, when drawing edges, shaded surfaces, textures etc. To reduce the effect of aliasing various anti-aliasing techniques can be applied. Some examples are:

•Low-pass filtering (poor mans anti-aliasing)•Area-sampling (colour proportional to area)•Super-sampling (more samples than pixels)•Dithering (anti-aliasing in the colour domain)•MIP mapping (prefiltering for textures)

Dithering

Page 10: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Color = The eye’s and the brain’s impression of electromagnetic radiation in the visual spectra.

How is color perceived?

light source

reflecting object

detector

s( )r( )

r

g

b

( )

( )

( )

rodsrods & cones

red-sensitive

green-sensitive

blue-sensitive

COLOR

Page 11: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

The Fovea

There are three types of cones, S, M and L

Page 12: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

standard lightsource

object reflectance

CIE 1931 standard observer

CIE XYZ values

400nm 700nm 400nm 700nm 400nm 700nm

xy

z

xx =X=14.27Y=14.31Z=71.52

s( ) r( )

Each color is represented by a point (X,Y,Z) in the 3D CIE color space. The point is called the tristimulus value.

X s r x d

Y s r y d

Z s r z d

( ) ( ) ( )

( ) ( ) ( )

( ) ( ) ( )

Page 13: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Projection of the CIE XYZ-space

Perceptual equal distances

Page 14: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Mixing light and mixing pigment

green

blue

red

yellow

cyan

magenta

green

blue

red

yellow

cyan

magenta

CMY

RGB

= 1- [][] R+B+G=white (additive) R+G=Y

C+M+Y=black (subtractive) C+M=B etc...

(CMYK common in printing, where K is black pigment)

Page 15: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

HLS color spaceHueLightnesSaturation

Hue=dominant wavelength, toneLightness=intensity, brightnessSaturation=purity, dilution by white

Important aspects:•Intensity decoupled from color•Related to how humans perceive color

Page 16: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Affine transformationsTo build objects, as well as move them around we need to be able to transform our triangles and objects in different ways.

There are many classes of transformations.

Rigid body transformations include translation and rotation only.

Add scaling and shearing to this, and we get the class of

Affine transformations.

•Translate (move around)•Rotate•Scale•Shear (can be constructed from scaling and rotation)

Page 17: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Translation

P(x,y)

P’(x’,y’)

x’ = x + dxy’ = y + dy

Simply add a translation vector

Page 18: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Rotationaround the origin

1. P in polar coordinates:

x = r cos(), y = r sin()

2. P’ in polar coordinates:

x’ = r cos( +) = r cos() cos() - r sin() sin()

y’ = r sin( +) = r cos() sin() - r sin() cos()

3. Substitute x, and y in (2)

x’ = x cos() - y sin()

y’ = x sin() + y cos()

Page 19: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Arbitrary rotation

• Translate the rotation axis to the origin

• Rotate

• Translate back

Page 20: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Scalingaround the origin

x’ = sx xy’ = sy y

x

y

x x’

P(x,y)

P’(x’,y’)

Multiply by a scale factor

Page 21: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Affine transformations are linear!

• f(a+b) = f(a) + f(b)

• This implies that we need only to transform the vertices of our objects, as the inner points are built up of linear combinations of the vertex points.

p(p0 + p1 0..1p0

p1

Page 22: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Using homogeneous coordinatesx

y

1

x

y

'

'

1

Translation: p’ = T(dx,dy) p

1 0

0 1

0 0 1

dx

dy

Rotation: p’ = R() p

Scaling: p’ = S(sx,sy) p

Shear: p’ = Hx() p

x

y

'

'

1

x

y

'

'

1

x

y

'

'

1

cos sin

sin cos

0

0

0 0 1

s

sx

y

0 0

0 0

0 0 1

1 0

0 1 0

0 0 1

cot

x

y

1

x

y

1

x

y

1

Page 23: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Concatenation of transformations

p’ = T-1(S(R(T(p))) = (T-1SRT)p

M = T-1SRT

p’ = Mp

Observe: Order (right to left) is important!

Page 24: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Homogeneous coordinates• What about this extra coordinate W?

x

y

W

x

y

W

x W

y W

/

/

1

This is called: To homogenize

Cartesian coordinates:

x

y

x W

y Wc

c

h

h

/

/

W=0: Points at infinity = vectorx

y

0

Page 25: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

The View transformation

• Put the observer in the origin

• Allign the x and y axises with the ones of the screen

• Righthand coordinate system => z-axis pointing backwards

World Coordsys.

View Coordsys.

z

xy

z

x

y

Simplifies light, clip, HSR and perspective calculations.

Page 26: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Change of Frame

• The View transformation is a change of frame.

• A change of frame is a change of coordinate system + change of origin.

• We can split this operation into; change of coordinate system + a translation.

• The change of coordinate system can be seen as a rotation, but is really more general.

e1

e2

f1f2

Page 27: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Change of Coordinate system

We wish to express the same point, with two different sets of basis vectors.

p = x e1 + y e2 = x’ f1 + y’ e2

e1

e2

f1f2

p

x

y

x’

y’

Page 28: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

More change of Coordsys

Assume that we know the basis vectors of the new coordinate system F in terms of the old E.

f1 = a e1 + b e2

f2 = c e1 + d e2

e1

e2

f1f2

a

b

c

d

Page 29: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Change of frame, final

x

yM T P

x

yT

o

'

'( )

1

x

yMT P

x

yo

'

'( )

Iff we are dealing with ON-basises, M is a pure rotation matrix, i.e. M is orthonormal, then MT=M-1 =>

f

f

a b

c d

e

eMe

e1

2

1

2

1

2

Page 30: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

LookAt(eye,at,up)

WC

VC

f3

f1

f2

e3

e1

e2

eyeat

up

feye at

eye at3

fup f

up f13

3

f f f2 3 1

Page 31: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Perspective projection

yy

zz

dz

' '

COP

View plane

z d

y y’x x

dz

'

y ydz

'

z d zdz

'

Page 32: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Homogeneous coordinates

x xdz

'

y ydz

'

z zdz

'

x

y

z

z d d

x

y

z

/ /

1 0 0 0

0 1 0 0

0 0 1 0

0 0 1 0 1

x x W xzd

xdz

' / /

similar for y’ and z’

Use W to fit the perspective transformation into a matrix multiplication

Note: It is not a linear transformation!

Page 33: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Some coordinate systems on the way

p’ = Vp * P * C * Vt * M * p

Object Coordsys.

World Coordsys.

View Coordsys.

Window Coordsys.

Device/screenCoordsys.

Model/object transform

View transform

Projection

Viewporttransform

Optional Clip transf.

Page 34: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

ClippingRemove things which are outside the View volume

Front clipping plane

Back clipping plane

View volume

Page 35: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

2D Cohen - Sutherland clippingFor a line segment with outcode o1 and o2 we have 4 cases.1. o1 = o2 = 0 : Both endpoints inside, draw line. (A) 2. Only one of o1 and o2 is zero : One endpoint inside, shorten non-zero side. (B)3. (o1 & o2) 0 (bitwise and) : Two endpoints on same side outside of window. Do not draw. (C) 4. (o1 & o2) = 0 : Two endpoints outside different edges. We do not know which one of (D & E), so we must test an intersection.

1001

0001

0101 0100 0110

0000

1000 1010

0010A

B

C

DE

Page 36: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Calculating intersections

p1

p2

Parametric representation of lines

p() = (1- )p1 + p2

x() = (1- )x1 + x2

y() = (1- )y1 + y2

p()

xmax

01

2 1

x xx xmax

Page 37: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Liang - Barsky clipping

1

3

2

4

0 < < < < < 1

0 < < < < < 1

41

2 1

x xx xmax

(x2-x1) = (x) = xmax-x1 = xmax

Page 38: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Distortion of the view volumeInstead of writing a general clipper, that works on tilted frustrum shaped view volumes. We distort the view volume to the shape of a cube, that is usually centered around the origin, and alligned with our axises and of size 2x2x2.

Page 39: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Scissoring = Clipping in screen space

When we fill our polygons, we do not want to draw pixels which are outside the screen.

It is quite easy to insert scissoring into our polygon filling routine.

Page 40: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Hidden surface removal /Visible surface determination

Hidden surface

We do not wish to see things which are hidden behind other objects.

Page 41: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

To main types of HSR

• Object space approach– Works on object level, comparing objects with

each other.• Painter algorithm

• Depth sort

• Image/pixel space approach– Works on pixel level, comparing pixel values.

• z-Buffer algorithm

• Ray-casting / ray-tracing

Page 42: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Painters algorithmWorks like a painter does things

• Sort all object according to their z position (VC)• Draw the farthest object first and the closest last (possibly on

top of others).

• Object based, compare objects with each other.• Hard to implement in a pipeline fashion.• Makes quite many errors.

• We draw unnecessary polygons.• Sorting of almost sorted list is fast! (E.g. bubblesort)

Page 43: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

z-Buffer algorithmfill z-buffer with infinite distancefor all polygons

for each pixelcalculate z-value (linear interpolation of q=1/z)if z(x,y) is closer than z-buffer(x,y)

draw pixelz-buffer(x,y)=z(x,y)

endend

end

• Must interpolate q=1/z to get perspective correct result.• Image/pixel space• Easy to implement in a pipeline structure (hardware)• Always correct result!

Page 44: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Back-face culling• We will never see the ”inside” of solid objects. Therefore,

there is no reason to draw the backsides of the face polygons.

• We can check if we see the front side of a polygon by checking if the angle between the normal and the vector pointing towards the observer is smaller than 90 degrees.

• After View transformation and perspective distortion, this simply becomes a check of the z-coordinate of the normal vector.

COPn

vv * n > 0

Page 45: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Adding some light

Lightsource

Ray-tracing = Follow them photons!Global models are too slow!

Page 46: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Local reflection model

Shiny (specular) surface Frosted (diffuse) surface

n n

Transparent surface

n

Page 47: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Ia = ka La

n

Id = kd Ld cos() = kd Ld (nl)

Lamberth’s Law

l

n

l

rv

Id = ks Ls cos() = ks Ls (vr)

The Phong reflection model Ambient + Diffuse + Specular

Page 48: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Phong Reflection model

I = ka La + 1

2a bd cd ( kd Ld (nl) + ks Ls (vr)

For each color (r,g,b) calculate reflected intensity:

All lightsources

Ambient Diffuse SpecularDistance term

Shininess

n

l

rv

Distance to lightsource

Page 49: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Ambient Diffuse

Specular, shininess=20 Ambient+diffuse+specular

Page 50: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Polygonal Shading

Flat Gouraud Phong

To calculate the color at each pixel is computationally heavy,we use interpolation to get color values over the polygon surface.

Page 51: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Flat shadingOne color for the whole polygon.Normal vector is easily calculated from a cross product.Fast, but with rather poor result.Mach bands are very prominent.

a b

c

n = (b-a) (c-a) / |(b-a) (c-a)|

n

Page 52: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Interpolated/Gouraud shadingCalculate one color at each vertex point.Linearly interpolate the color over the surface.Normal vector needed at each vertex point.Medium speed, medium result. Commonly used.

a b

c

na nb

nc

Page 53: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Phong shadingInterpolate the normal vector over the surface.Calculate the color at each pixel.Normal vector needed at each vertex point.Best result. Slow in the original form.

a b

c

na nb

nc

Page 54: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Coordinate systems againStarting object

Object coordsys.Model transf.

World coordsys.View transf.

View coordsys.Clip distortion

Clip coordsys.Persp. distortion

Normalized Device coordsys.Orthographics proj.

Window coordsys.Viewport transf.

Screen/device coordsys.Rasterization!

Cube 2x2x2

NDC

Page 55: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

The Display PipelineThe order may vary somewhat

•Modelling, create objects (this is not really a part of the pipeline)•Transformations, move, scale, rotate…•View transformation, put yourself in the origin of the world•Projection normalization, reshape view volume•Clipping, cut away things outside the view volume•Object based Hidden surface removal, we don’t see through things•Light and illumination, shadows perhaps•Orthographics projection, 3D => 2D•Rasterisation, put things onto our digital screen

Texture, shading, image based HSR...

Transform Clipping HSR Light calculations ...

Polygon in

...

Page 56: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Texture mappingInstead of using a huge number of small polygons to describe the structure and texture of our surfaces, we can map an image onto the polygon. This is called texture mapping and is frequently used to enhance the realism in images without any significant loss of performance.

Texture map Our polygon

Page 57: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Binding the texture mapFor each vertex on our polygon, we assign a texel position (u,v) in a texture map (this is really a part of the modelling).

Page 58: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Texture mappingWhen we take a step rasterizing the polygon, we also take a step in the texture map. The code is just the same linear interpolation as we already have done for color, and z-coordinate interpolation. Just two new coordinates, u and v and new slopes for them.

For each pixel to draw, we check in the texture map, what is the color of that pixel.

Page 59: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Everything maps!The use of mapping has become a commonly used way to store precalculated features to speed up rendering.

Some examples are: • Texture maps (i.e color maps)• Bump maps (i.e. normal displacement maps)• Displacement maps • Reflection maps (environment maps)• Light maps (luminosity maps)• Mapping of other surface properties, e.g. shininess

You name it!

Page 60: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Bump mapsDisplace the normal vector to fool the eye inte 3D thinking.Not the the physical geometry of the object does not change (no change in outline or shadow).

Page 61: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Displacement mapsReal displacement of the pixels along the normal vector.Changes physical geometry, hard to render in real-time, but works nicely in ray traced images.

Page 62: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Reflection maps / environment maps

Page 63: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Light mapsQuake uses light maps in addition to texture maps. Texture maps are used to add detail to surfaces, and light maps are used to store pre-computed illumination.

Textures Only Texture and light map

Light map

Page 64: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Perspective problemsAll our mappings, as well as our Gouraud shading, does interpolation in the screen space (2D). This does not work perfectly together with perspective, which is a non-linear transformation.

The solution to the problem is once again our homogeneous coordinates, and to do the texture interpolation in (u’, v’, q) instead of (u,v).

Page 65: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Parametric cubic curvesIn order to assure C2 continuity our functions must be of

at least degree 3

Here's what a parametric cubic spline function looks like:

x(t) = axt3 + bxt2 + cxt + dx

y(t) = ayt3 + byt2 + cyt + dy

Alternatively, it can be

written in matrix form:

Page 66: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Blending functionsThe contribution of each geometric factor can be considered

separately, this approach gives a so-called blending function associated with each factor.

Beginning with our matrix formulation:

p(t) = t M G

By reordering our multiplications we get:p(t) = b(t) G

or simply

p(t) = bi(t) pi

Page 67: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Bezier curves

Instead of giving gradients as numbers, we can get them from using two more control points.

p(0) = p1

p(1) = p4

p’(0) = (p2-p1)/(1/3)

p’(1) = (p4-p3)/(1/3)

Page 68: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Recursive subdivisionWhen rendering our Bezier curves, one can of course take tiny steps in the parameter, and plot the corresponding points.

p(t) = bi(t) pi

There exists a faster way though, called recursive subdivision, where we cut the curve into smaller and smaller pieces, which we finally aproximate with straight lines.

Page 69: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Cubic B-Splines

Passing through the same mathematic machinery as before we end up with.

a a

b b

c c

d d

x y

x y

x y

x y

x y

x y

x y

x y

i i

i i

i i

i i

16

1 3 3 1

3 6 3 0

3 0 3 0

1 4 1 0

2 2

1 1

1 1

Or using blending polynomials

p t

t

t t

t t t

t

p

p

p

p

i

i

i

i

( )

( )

16

1

4 6 3

1 3 3 3

3

2 3

2 3

3

2

1

1

All control points have the same meaning.We pick four control points at a time with a sliding window.

C2 continuous!

Page 70: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Rendering B-splines by change of basis

As there exists a nice algorithm for rendering Bezier curves, B-splines are usually rendered by first transforming them into Bezier curves.

p(t) = t MS GS = t MB GB => GB = MB-1 MS GS

Page 71: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

SurfacesSurfaces is really just the same thing as curves, we just add another dimension.

Instead of having one parameter t, we use two, t & s.Instead of having curve segments, we have surface patches.

p(s,t) = bi(s) bj(t) pij

The equations are separable both in (x,y,z) space andthe parameter space (s,t).

Page 72: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Fractals and dimension

The fractal dimension of simple self-similar curves can be calculated as (by definition).

D = ln (n) / ln (1/s)

where n is the number of subparts and s is the scale factor in each iteration.

Loosely speaking, the fractal dimension of a curve is the rate at which the length of the curve increases as the measurement scale is reduced.

Page 73: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Ferns and L-systemsLindenmayer SystemsExample: Axiom: X Rewriting rules:

F --> FF X --> F-[[X]+X]+F[+FX]-X ø = 22.5

Character Meaning F Move forward by line length drawing a line + Turn left by turning angle - Turn right by turning angle [ Push current drawing state onto stack ] Pop current drawing state from the stack

Page 74: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

Fractal landscapesIf we are to create a mountain for example, we start with a flat surface, find its midpoint and displace it, by a random distance, in the vertical direction, creating new surfaces. This procedure is repeated a finite number of times using a zero-mean Gaussian random number generator.

The fractal dimension is controlled by the variance of the random number generator.

If the variance is proportional to l*2(2-D) where l is the length of the line segment to be divided, the fractal dimension of the curve will be D.

Page 75: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

75

Multidimensional images

A multidimensional image can be considered as a function f(x,y,z,t,b), where

z: third spatial direction t: time sequences b: different spectral bands

These can be combined in different ways, for example, f(x,y,z,t) is a 4D image representing a time sequence of 3D volume images

Page 76: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

76

Surface versus Volume RenderingSurface rendering+ Standard computer graphics software can be used.

+ Supported by dedicated harware - fast.

+ Normally a high data reduction can be achieved.

- (There is no intensity information.)

- Cutting through the data is meaningless

- Changes in surface definition criteria means recalculation of the data.

Volume rendering+ Arbitrary cuts can be made allowing the user to see inside the data.

+ Allows for display of different aspects such as maximum intensity projections, semi-transparent surfaces etc.

+ Rendering parameters can be changes interactively.

- Slow!

Page 77: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

77

Marching Cubes Algorithm summary

1. Create a cube.

2. Classify each vertex.

3. Build an index.

4. Get edge list.

5. Interpolate triangle vertices.

6. Calculate and interpolate normals.

?

Page 78: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

The OpenGL API is the most widely adopted 3D graphicsAPI in the industry.

Page 79: Computer Graphics I. Images in a computer... 94 100 104 119 125 136 143 153 157 158 103 104 106 98 103 119 141 155 159 160 109 136 136 123 95 78 117 149

THE END

Clipping

View plane

Camera orobserver

Lightsource

Transformation

Projection3D

2D

Rasterization

Shadow

Hidden surface

View volume