Top Banner
CS 455 – Computer Graphics Antialiasing
20

Lecture15 anti aliasing

Jan 13, 2015

Download

Technology

Siddharth Maloo

helpful for assignment
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Lecture15 anti aliasing

CS 455 – Computer Graphics

Antialiasing

Page 2: Lecture15 anti aliasing

Aliasing• Aliasing: a high-frequency signal masquerading as a low

frequency

Caused by insufficient sampling (sampling interval too large)

SamplingInterval

Actual (high-frequency) signal

Sampled (aliased) signal

Page 3: Lecture15 anti aliasing

• Strobe light on dripping water: Temporal aliasing

• Spokes on a rotating wheel: Temporal aliasing

• Moiré patterns: Spatial aliasing

Examples of Aliasing

Page 4: Lecture15 anti aliasing

Aliasing and Line Drawing• We draw lines by sampling at intervals of one pixel and

drawing the closest pixels

SamplingInterval

SamplingInterval

• Results in stair-stepping (i.e., the dreaded “jaggies”)

Page 5: Lecture15 anti aliasing

Antialiasing Lines• Idea:

Make line “fatter” Fade line out (removes high frequencies) Now sample the line

Page 6: Lecture15 anti aliasing

Antialiasing LinesSolution 1 – Unweighted Area Sampling: Treat line as a single-pixel wide rectangle Color pixels according to the percentage of each pixel that is

“covered” by the rectangle

Page 7: Lecture15 anti aliasing

Solution 1: Unweighted Area Sampling• Pixel area is unit square

• Constant weighting function

• Pixel color is determined by computing the amount of the pixel covered by the line, then shading accordingly

• Easy to compute, gives reasonable results

Line

One Pixel

Page 8: Lecture15 anti aliasing

Solution 2: Weighted Area SamplingTreat pixel area as a circle with a radius of one pixel

Use a radially symmetric weighting function (e.g., cone): Areas closer to the pixel center are weighted more heavily

Better results than unweighted, slightly higher cost

Line

One Pixel

Page 9: Lecture15 anti aliasing

Solution 3: Gupta-Sproull algorithm• Calculate pixel intensity by computing distance from

pixel center to line using the midpoint line algorithm

xp

NE

m

E

xp+1

Line to draw

v

yp

yp+1

D

Page 10: Lecture15 anti aliasing

Gupta-Sproull algorithm (cont)• D is the perpendicular distance from E to the line

• How do we compute it?

a

How does triangle abc compare to triangle ade?

D

c = e, and a = a, so b must equal d

b

c

d e

dx

dy

v

r

r

Page 11: Lecture15 anti aliasing

Gupta-Sproull algorithm (cont)• D is the perpendicular distance from E to the line

• How do we compute it?

a

So:

D

22cos

dydx

vdxbvD

b

c

d e

22coscos

dydx

dxbd

dx

dy

v

r

r

cosb =D

v, then D = v cosb

And:

Then:

Page 12: Lecture15 anti aliasing

Gupta-Sproull algorithm (cont)Recall from the midpoint algorithm:

So

For pixel E:

So:

02),( cbyaxyxF

y

1px

v

xp

NE

m

E xp+1

Line to draw

vyp

yp+1

Db

cax

)(

1py py v 1 pyy1px

pp y

b

cxa

)1(

Page 13: Lecture15 anti aliasing

Gupta-Sproull algorithm (cont)From previous slide:

So

From the midpoint computation,

So:

dxb

pp

yb

cxav

)1(

2/),1()1( pppp yxFcbyxavdx

pp bycxabv )1(

xp

NE

m

E xp+1

Line to draw

vyp

yp+1

D

Page 14: Lecture15 anti aliasing

Gupta-Sproull algorithm (cont)From the midpoint algorithm, we had the decision

variable (remember?)

Going back to our previous equation:

)2

1,()( 1 pp yxFMFd

xp

NE

m

E xp+1

Line to draw

vyp

yp+1

D

),1(2 pp yxFvdx cbyxa pp 22)1(2

cbybxa pp 22/2)2/1(2)1(2 byxF pp )2/1,1(

bMF )( bd dxd

Page 15: Lecture15 anti aliasing

Gupta-Sproull algorithm (cont)So,

And the denominator is constant

Since we are blurring the line, we also need to compute the distances to points yp – 1 and yp + 1

222 dydx

dxdD

vdxdxdxvy

vdxdxdxvy

p

p

22)1(2 1for numerator

22)1(2 1for numerator

Page 16: Lecture15 anti aliasing

Gupta-Sproull algorithm (cont)If the NE pixel had been chosen:

vdxdxdxvy

vdxdxdxvy

p

p

22)1(2 for numerator

22)1(2 2for numerator

dxd

bd

bMF

byxF

cbybxa

cbyxa

yxFvdx

pp

pp

pp

pp

)(

)2/1,1(

22/2)2/1(2)1(2

2)1(2)1(2

)1,1(2

Page 17: Lecture15 anti aliasing

Gupta-Sproull algorithm (cont)• Compute midpoint line algorithm, with the following

alterations:

• At each iteration of the algorithm: If the E pixel is chosen, set numerator = d + dx If the NE pixel is chosen, set numerator = d – dx Update d as in the regular algorithm Compute D = numerator/denominator Color the current pixel according to D Compute Dupper = (2dx-2vdx)/denominator

Compute Dlower = (2dx+2vdx)/denominator

Color upper and lower accordingly

Page 18: Lecture15 anti aliasing

Solution 4: Super-sampling• Divide pixel up into “sub-pixels”: 22, 33, 44, etc.

• Sub-pixel is colored if inside line• Pixel color is the average of its sub-pixel colors• Easy to implement (in software and hardware)

No antialiasing Antialiasing (22 super-sampling)

Page 19: Lecture15 anti aliasing

Solution 5: Sum of Foreground and Background

• Compute percent of pixel covered by line, p

• Line color is cl

• Background color is cb

• Pixel color is the sum of this percent multiplied by the line color, plus the percent of the pixel not covered by the line multiplied by the background color, i.e.,

color = p * cl + (1-p) * cb

Page 20: Lecture15 anti aliasing

Polygon Antialiasing• To antialias a line, we treat it as a polygon (a rectangle)

• Antialiasing a polygon (or any shape primitive) is similar

• Some concerns: Corners: Complicate the coverage

computation

Micro-polygons: smaller than a pixel

Super-sampling: There may still bepolygons that “slip between the cracks”