Transcript
Page 1: Computer Graphics Inf4/MSc Computer Graphics Lecture 6 Rasterisation, Antialiasing, Texture Mapping,

Computer Graphics Inf4/MSc

Computer Graphics

Lecture 6

Rasterisation, Antialiasing, Texture Mapping,

Page 2: Computer Graphics Inf4/MSc Computer Graphics Lecture 6 Rasterisation, Antialiasing, Texture Mapping,

Computer Graphics Inf4/MSc

2

Some Tutorial about the Project

• I have already covered all the topics needed to finish the 1st practical

• Today, I will briefly explain how to start working on it.

• I have already provided you a program to import an obj file.

Page 3: Computer Graphics Inf4/MSc Computer Graphics Lecture 6 Rasterisation, Antialiasing, Texture Mapping,

Computer Graphics Inf4/MSc

3

Steps•Apply transformations to all vertices•Prepare the frame buffer and Z-buffer•For each triangle• Project it to the screen space• Find the 2D bounding box• For each pixel in the bounding box• Check if it is inside the triangle by computing its

barycentric coordinates• If yes, use barycentric coordinates to compute the depth

and colour at the pixel • If (depth < zbuf[pixel]) {

framebuffer[pixel] = colour zbuf[pixel] = depth

}•Export the frame buffer data into a PPM file

Page 4: Computer Graphics Inf4/MSc Computer Graphics Lecture 6 Rasterisation, Antialiasing, Texture Mapping,

Computer Graphics Inf4/MSc

• For each pixel in the bounding box• Check if it is inside the triangle by computing its

barycentric coordinates

• If yes, use barycentric coordinates to compute the depth and colour at the pixel

z = αz1 + β z2 + γ z3

c = αc1 + β c2 + γ c3

• If (z < zbuf[pixel]) { framebuffer[pixel] = colour zbuf[pixel] = c

}

Page 5: Computer Graphics Inf4/MSc Computer Graphics Lecture 6 Rasterisation, Antialiasing, Texture Mapping,

Computer Graphics Inf4/MSc

5

Computing the baricentric coordinates of the interior pixels

(α,β,γ) : barycentric coordinatesOnly if 0<α,β,γ<1, (x,y) is inside the triangleDepth can be computed by αZ0 + βZ1 +γZ2

Can do the same thing for color, normals, textures

• The triangle is composed of 3 points p0 (x0,y0), p1 (x1, y1), p2(x2,y2)

Page 6: Computer Graphics Inf4/MSc Computer Graphics Lecture 6 Rasterisation, Antialiasing, Texture Mapping,

Computer Graphics Inf4/MSc

6

Today

• Anti-aliasing

• Texture mapping– Common texture coordinates mapping– Texture coordinates

Page 7: Computer Graphics Inf4/MSc Computer Graphics Lecture 6 Rasterisation, Antialiasing, Texture Mapping,

Computer Graphics Inf4/MSc

7

Rasterisation• Converts the vertex information output by

the geometry pipeline into pixel information needed by the video display– Anti-aliasing– Z-buffer– Texture mapping – Bump mapping– Transparent objects – Drawing lines

Page 8: Computer Graphics Inf4/MSc Computer Graphics Lecture 6 Rasterisation, Antialiasing, Texture Mapping,

Computer Graphics Inf4/MSc

8

Anti-aliasing • Aliasing: distortion artifacts produced when representing a

high-resolution signal at a lower resolution.• Anti-aliasing : techniques to remove aliasing

Aliased polygons(jagged edges)

Anti-aliased polygons

Page 9: Computer Graphics Inf4/MSc Computer Graphics Lecture 6 Rasterisation, Antialiasing, Texture Mapping,

Computer Graphics Inf4/MSc

Nyquist Limit

• The signal frequency (fsignal) should be no greater than half the sample frequency (fsample)

• fsignal <= 0.5 fsample • In the top, fsignal = 0.8 fsample -> cannot reconstruct the original signal• In the bottom fsignal =0.5 fsample -> the original signal can be reconstructed

by slightly increasing the sampling rate

Page 10: Computer Graphics Inf4/MSc Computer Graphics Lecture 6 Rasterisation, Antialiasing, Texture Mapping,

Computer Graphics Inf4/MSc

10

Each pixel is subdivided (sub-sampled) into n regions, and each sub-pixel has a color;Compute the average color value

Screen-based Anti-aliasing

weight:

color sample:),,(

y)(x,at color pixel:),(

),,(),(1

i

n

ii

w

yxi

yx

yxiwyx

c

p

cp

Page 11: Computer Graphics Inf4/MSc Computer Graphics Lecture 6 Rasterisation, Antialiasing, Texture Mapping,

Computer Graphics Inf4/MSc

Accumulation Buffer (A-Buffer)• Use a buffer that has the same resolution as

the original image• To obtain a 2x2 sampling of a scene, 4

images are made by shifting the buffer horizontally/vertically for half a pixel

• The results are accumulated and the final results are obtained by averaging

• Various sampling schemes are available

Pixel center

Subsampled point

Page 12: Computer Graphics Inf4/MSc Computer Graphics Lecture 6 Rasterisation, Antialiasing, Texture Mapping,

Computer Graphics Inf4/MSc

Different Sampling Schemes

Page 13: Computer Graphics Inf4/MSc Computer Graphics Lecture 6 Rasterisation, Antialiasing, Texture Mapping,

Computer Graphics Inf4/MSc

Page 14: Computer Graphics Inf4/MSc Computer Graphics Lecture 6 Rasterisation, Antialiasing, Texture Mapping,

Computer Graphics Inf4/MSc

Accumulation Buffer (A-Buffer)• The lighting computation is usually done

only once per vertex• Not doing the lighting computation at each

sample point• The A-buffer’s focus is on the edge anti-

aliasing • Also useful for rendering transparent

objects, motion blur (will be covered later in the course)

Edges

Page 15: Computer Graphics Inf4/MSc Computer Graphics Lecture 6 Rasterisation, Antialiasing, Texture Mapping,

Computer Graphics Inf4/MSc

Stochastic Sampling• A scene can be produced of objects that are

arbitrarily small• A regular pattern of sampling will always

exhibit some sort of aliasing• One approach to solve this is to randomly

sample over the pixel– Jittering : subdivide into n regions of equal size

and randomly sample inside each region

Page 16: Computer Graphics Inf4/MSc Computer Graphics Lecture 6 Rasterisation, Antialiasing, Texture Mapping,

Computer Graphics Inf4/MSc

The oversamplingrate is 1 and 2 from left to right

Page 17: Computer Graphics Inf4/MSc Computer Graphics Lecture 6 Rasterisation, Antialiasing, Texture Mapping,

Computer Graphics Inf4/MSc

17

Today

• Anti-aliasing

• Texture mapping– Common texture coordinates mapping– Texture coordinates

Page 18: Computer Graphics Inf4/MSc Computer Graphics Lecture 6 Rasterisation, Antialiasing, Texture Mapping,

Computer Graphics Inf4/MSc

Texture Mapping : Why needed?

• We don't want to represent all this detail with geometry

Page 19: Computer Graphics Inf4/MSc Computer Graphics Lecture 6 Rasterisation, Antialiasing, Texture Mapping,

Computer Graphics Inf4/MSc

19

Texture mapping.

• Method of improving surface appearance by adding details on surface.

Page 20: Computer Graphics Inf4/MSc Computer Graphics Lecture 6 Rasterisation, Antialiasing, Texture Mapping,

Computer Graphics Inf4/MSc

20

Texture mapping.

• Image is ‘pasted’ onto a polygon.• Image is called a Texture map, it’s pixels are often

referred as a Texels and have coordinates (u,v)• Texture coordinates are defined for each vertex of

the polygon and interpolated across the polygon.

v

u

v

u

y

x

Page 21: Computer Graphics Inf4/MSc Computer Graphics Lecture 6 Rasterisation, Antialiasing, Texture Mapping,

Computer Graphics Inf4/MSc

Photo-textures

Page 22: Computer Graphics Inf4/MSc Computer Graphics Lecture 6 Rasterisation, Antialiasing, Texture Mapping,

Computer Graphics Inf4/MSc

Texture Interpolation• Specify a texture coordinate (u,v) at each vertex• Can we just linearly interpolate the values in screen

space?

(0,0) (1,0)

(0,1)

Page 23: Computer Graphics Inf4/MSc Computer Graphics Lecture 6 Rasterisation, Antialiasing, Texture Mapping,

Computer Graphics Inf4/MSc

Interpolating the uv coordinates

Again, we use baricentric coordinates

u= α u1 + β u2 + γ u3

v = α v1 + β v2 + γ v3

u1 v1

u2 v2

u3 v3

Page 24: Computer Graphics Inf4/MSc Computer Graphics Lecture 6 Rasterisation, Antialiasing, Texture Mapping,

Computer Graphics Inf4/MSc Interpolation - What Goes

Wrong?

texture source what we get| what we want

• Linear interpolation in screen space:

Page 25: Computer Graphics Inf4/MSc Computer Graphics Lecture 6 Rasterisation, Antialiasing, Texture Mapping,

Computer Graphics Inf4/MSc

Why does it happen?

• Uniform steps on the image plane does not correspond to uniform steps along the edge

Page 26: Computer Graphics Inf4/MSc Computer Graphics Lecture 6 Rasterisation, Antialiasing, Texture Mapping,

Computer Graphics Inf4/MSc

How do we deal with it?

• Use hyperbolic interpolation– (u,v) cannot be linearly interpolated, but 1/w and

(u/w, v/w) can– w is the last component after the canonical view

transformation

10100

200

02

0

002

z

y

x

nf

fn

nf

nfbt

bt

bt

nlr

lr

lr

n

w

wz

wy

wx

p

p

p

Page 27: Computer Graphics Inf4/MSc Computer Graphics Lecture 6 Rasterisation, Antialiasing, Texture Mapping,

Computer Graphics Inf4/MScTexture Mapping Examples

• Linear interpolation vs. Hyperbolic interpolation• Two triangles per square

Page 28: Computer Graphics Inf4/MSc Computer Graphics Lecture 6 Rasterisation, Antialiasing, Texture Mapping,

Computer Graphics Inf4/MScComputing the uv coordinates at the

internal points• For three points of the triangle, get

• Compute at the internal points of the triangle by interpolation

• Compute wi by inverting 1/wi, and multiply them to (ui /wi, ,vi /wi) to compute (ui,vi)

],,1

,[i

i

i

i

i w

v

w

u

wii pr

],,1

[i

i

i

i

i w

v

w

u

w

Page 29: Computer Graphics Inf4/MSc Computer Graphics Lecture 6 Rasterisation, Antialiasing, Texture Mapping,

Computer Graphics Inf4/MSc Common Texture Coordinate

Mappings• Orthogonal• Cylindrical• Spherical

Page 30: Computer Graphics Inf4/MSc Computer Graphics Lecture 6 Rasterisation, Antialiasing, Texture Mapping,

Computer Graphics Inf4/MSc

Texture Mapping & Illumination

• Texture mapping can be used to alter some or all of the constants in the illumination equation: – pixel color, diffuse color ….

Phong’s Illumination Model

Constant Diffuse Color Diffuse Texture Color Texture used as Label Texture used as Diffuse Color

Page 31: Computer Graphics Inf4/MSc Computer Graphics Lecture 6 Rasterisation, Antialiasing, Texture Mapping,

Computer Graphics Inf4/MSc

Readings

• Chapter 5.1-2 of Real-Time Rendering Second edition – http://books.google.co.uk/books?id=mOKEfBT

w4x0C&printsec=frontcover&source=gbs_v2_summary_r&cad=0#v=onepage&q=&f=false

• “Hyperbolic Interpolation” IEEE Computer Graphics and Applications, vol12, no.4, 89-94, 1992

• Demoed Softwarehttp://www-ui.is.s.u-tokyo.ac.jp/~takeo/java/smoothteddy/index.html


Recommended