38
Antialiasing Antialiasing CAP4730: Computational Structures in Computer Graphics

Antialiasing CAP4730: Computational Structures in Computer Graphics

Embed Size (px)

Citation preview

Page 1: Antialiasing CAP4730: Computational Structures in Computer Graphics

AntialiasingAntialiasing

CAP4730: Computational Structures in Computer Graphics

Page 2: Antialiasing CAP4730: Computational Structures in Computer Graphics

OutlineOutline

What is antialiasing?What is antialiasing? How do we see the affects of How do we see the affects of

antialiasing?antialiasing? What can we do about it?What can we do about it? Math behind antialiasingMath behind antialiasing Antialiasing in modern day graphics Antialiasing in modern day graphics

cardscards Advanced stuff on AAAdvanced stuff on AA

Page 3: Antialiasing CAP4730: Computational Structures in Computer Graphics

Let’s Revisit a pixelLet’s Revisit a pixel

A pixel is which of these things A pixel is which of these things (theoretically)?(theoretically)?– pointpoint– circle/diskcircle/disk– square/rectanglesquare/rectangle– has areahas area– has a locationhas a location– samplesample

Page 4: Antialiasing CAP4730: Computational Structures in Computer Graphics

White Picket White Picket FenceFence

What What happens happens when we back when we back away?away?– 1: with a 1: with a

camera /eyecamera /eye– 2: with 2: with

OpenGLOpenGL– 3: with ray-3: with ray-

tracingtracing What’s the What’s the

cause of the cause of the difference?difference?

A pixel could A pixel could be too BIG!be too BIG!

Page 5: Antialiasing CAP4730: Computational Structures in Computer Graphics

A New Thought about A New Thought about ImagesImages

Images are really a Images are really a 2D function2D function

Here’s an image Here’s an image plotted as a height plotted as a height fieldfield

Now we store this Now we store this image as an “array” image as an “array” of points. What of points. What does that mean?does that mean?

Page 6: Antialiasing CAP4730: Computational Structures in Computer Graphics

We Sample the Image We Sample the Image FunctionFunction

Here is the sampling function. It is Here is the sampling function. It is called the called the deltadelta function function

Page 7: Antialiasing CAP4730: Computational Structures in Computer Graphics

Thus we are “sampling” a Thus we are “sampling” a continuous image functioncontinuous image function We call these samples at We call these samples at

this regular grid of this regular grid of points, points, pixelspixels..

Pixels are a sampling of Pixels are a sampling of the function that the function that describes the image.describes the image.

We store these pixels We store these pixels into memory as an array into memory as an array of colors.of colors.

How densely should we How densely should we sample?sample?

What would govern this?What would govern this?

Page 8: Antialiasing CAP4730: Computational Structures in Computer Graphics

SamplesSamples Continuous - function with values at any input. Most Continuous - function with values at any input. Most

things in the world. Ex. sine and cosinethings in the world. Ex. sine and cosine Discrete - function with values only at specific inputs. Discrete - function with values only at specific inputs.

Computers are discrete. Computers are discrete. What is a 1D example? a 2D example?What is a 1D example? a 2D example? To convert from a continuous function to a discrete one, To convert from a continuous function to a discrete one,

we we discretizediscretize or or samplesample To convert form a continuous variable to a discrete one, To convert form a continuous variable to a discrete one,

we we quantizequantize When we render an image (which is a continuous When we render an image (which is a continuous

function, why?), we sample and quantizefunction, why?), we sample and quantize

Page 9: Antialiasing CAP4730: Computational Structures in Computer Graphics

Let’s get grounded with an Let’s get grounded with an exampleexample

Page 10: Antialiasing CAP4730: Computational Structures in Computer Graphics

Similar examples?Similar examples?

High frequency information, low High frequency information, low sampling.sampling.– Examples?Examples?

Train comes every 2 hours. You go every Train comes every 2 hours. You go every 2:15. How long do you wait?2:15. How long do you wait?

Audio. 44/48 Khz signal. 11 Khz SampleAudio. 44/48 Khz signal. 11 Khz Sample

– What is the result?What is the result?– ImagesImages

8 MP vs 4 MP vs 640 x 4808 MP vs 4 MP vs 640 x 480

Page 11: Antialiasing CAP4730: Computational Structures in Computer Graphics

A quick footnote into A quick footnote into frequency analysisfrequency analysis

A way to understand the sampling question is A way to understand the sampling question is to convert the function into a different “space” to convert the function into a different “space” or domain. or domain.

We use the Fourier Transform to convert the We use the Fourier Transform to convert the function (in our case the image) into the function (in our case the image) into the frequency domain.frequency domain.

Page 12: Antialiasing CAP4730: Computational Structures in Computer Graphics

What does sampling What does sampling mean?mean?

What happens if we don’t sample What happens if we don’t sample enough?enough?

Page 13: Antialiasing CAP4730: Computational Structures in Computer Graphics

AliasingAliasing

If we sample at too low a rate, the high If we sample at too low a rate, the high frequencies in the image appear as lower frequencies in the image appear as lower frequencies.frequencies.

How do we fix it?How do we fix it? Increase samplingIncrease sampling Remove high frequenciesRemove high frequencies

Page 14: Antialiasing CAP4730: Computational Structures in Computer Graphics

Aliasing Aliasing ManifestationsManifestations

Pixels Pixels approximating a approximating a signalsignal

Pixels aren’t small Pixels aren’t small enough and MISS enough and MISS informationinformation

Page 15: Antialiasing CAP4730: Computational Structures in Computer Graphics

AliasingAliasing

Aliasing manifests itself as “jaggies” in Aliasing manifests itself as “jaggies” in graphics. Thus we don’t have enough pixels to graphics. Thus we don’t have enough pixels to accurately represent the underlying function. accurately represent the underlying function. Check out what happens when we increase our Check out what happens when we increase our sampling.sampling.

Page 16: Antialiasing CAP4730: Computational Structures in Computer Graphics

AliasingAliasing Aliasing also Aliasing also

manifests itself in manifests itself in repeating patternsrepeating patterns

Car wheelsCar wheels Big picture:Big picture:

– Continuous signalContinuous signal– Discrete sampling Discrete sampling

(pixels, frames, etc.)(pixels, frames, etc.)– Aliasing represents Aliasing represents

misrepresentation misrepresentation (hence the name) (hence the name) involvedinvolved

How do we fix it?How do we fix it?

Page 17: Antialiasing CAP4730: Computational Structures in Computer Graphics

Fixing AliasingFixing Aliasing

Increase ResolutionIncrease Resolution What’s wrong with this approach?What’s wrong with this approach? Filtering is another possibilityFiltering is another possibility

– We want to remove the high frequency We want to remove the high frequency areasareas

– How would we do that?How would we do that? Let’s re-examine what a pixel is in Let’s re-examine what a pixel is in realityreality..

Page 18: Antialiasing CAP4730: Computational Structures in Computer Graphics

Pixels are pointsPixels are points

But when we display the points, what happens?But when we display the points, what happens? Each pixel is actually a “blob” on the CRT. This Each pixel is actually a “blob” on the CRT. This

blob has energy that falls off close to a Gaussian.blob has energy that falls off close to a Gaussian. Thus the CRT has a built in “blurring” system. Thus the CRT has a built in “blurring” system.

Think about how this works with resolution of your Think about how this works with resolution of your monitor.monitor.

Page 19: Antialiasing CAP4730: Computational Structures in Computer Graphics

(0,0)

(4,2)

(4,0)

2

2

1

10

0

3 4

Let’s recallLet’s recall

Page 20: Antialiasing CAP4730: Computational Structures in Computer Graphics

Point SamplingPoint Sampling

Thus for each pixel, we are “sampling” a Thus for each pixel, we are “sampling” a specific point. In the frequency domain we specific point. In the frequency domain we get:get:

To convert from frequency to spatial domains, To convert from frequency to spatial domains, we do an integration.we do an integration.

To get around point sampling we should come To get around point sampling we should come up with another sampling techniqueup with another sampling technique

Page 21: Antialiasing CAP4730: Computational Structures in Computer Graphics

BiLinear SamplingBiLinear Sampling

What we will do is use a bilinear What we will do is use a bilinear filter.filter.

This reduces the high frequencies This reduces the high frequencies (which cause aliasing)(which cause aliasing)

Interpolate between samples.Interpolate between samples.

Page 22: Antialiasing CAP4730: Computational Structures in Computer Graphics

BiLinear SamplingBiLinear Sampling

Page 23: Antialiasing CAP4730: Computational Structures in Computer Graphics

What are we doing?What are we doing?

(0,0)

(4,2)

(4,0)

2

2

1

10

0

3 4

Page 24: Antialiasing CAP4730: Computational Structures in Computer Graphics

BlurringBlurring

Remember, blurring removes high frequencies, Remember, blurring removes high frequencies, which cause aliasing.which cause aliasing.

We can do other filtering besides bilinear, and We can do other filtering besides bilinear, and we would like to to avoid artifacts.we would like to to avoid artifacts.

http://graphics.lcs.mit.edu/classes/6.837/F98/http://graphics.lcs.mit.edu/classes/6.837/F98/Lecture11/Slide27.htmlLecture11/Slide27.html

How would we blur using our traditional How would we blur using our traditional graphics pipeline?graphics pipeline?

Page 25: Antialiasing CAP4730: Computational Structures in Computer Graphics

Two ways to AntialiasTwo ways to Antialias

Increase resolution (increase Increase resolution (increase sampling)sampling)– oror

SupersamplingSupersampling

Page 26: Antialiasing CAP4730: Computational Structures in Computer Graphics

Increase Rendering Increase Rendering ResolutionResolution

Render the image at a higher resolution and Render the image at a higher resolution and downsample.downsample.

Really, you are letting your eye do some Really, you are letting your eye do some filtering for you.filtering for you.

Page 27: Antialiasing CAP4730: Computational Structures in Computer Graphics

SupersamplingSupersampling

For each pixel, we would like to For each pixel, we would like to figure out what “percentage” is figure out what “percentage” is covered.covered.

(0,0)

(4,0)

2

1

10

0

3 4

Page 28: Antialiasing CAP4730: Computational Structures in Computer Graphics

SupersamplingSupersampling

For each pixel, sample at multiple For each pixel, sample at multiple points.points.– What is the distribution of these points?What is the distribution of these points?

Uniform GridUniform Grid RandomRandom Psuedo-randomPsuedo-random How many?How many? How far away from center should I try?How far away from center should I try?

– How would I program this?How would I program this?

Page 29: Antialiasing CAP4730: Computational Structures in Computer Graphics

Line AntialiasingLine Antialiasing

Page 30: Antialiasing CAP4730: Computational Structures in Computer Graphics

Full Screen AntialiasingFull Screen Antialiasing Another way to do the supersampling is to do full Another way to do the supersampling is to do full

screen antialiasingscreen antialiasing We want to draw the image with several camera We want to draw the image with several camera

jitter positions and average the answersjitter positions and average the answers Can you see why this would give us near similar Can you see why this would give us near similar

answers?answers? That’s what they mean by 2-tap, 4-tap antialiasingThat’s what they mean by 2-tap, 4-tap antialiasing What does this require?What does this require?

– Memory-wiseMemory-wise– Computation-wiseComputation-wise

How would you implement this?How would you implement this?

Page 31: Antialiasing CAP4730: Computational Structures in Computer Graphics

Full Screen Antialiasing Full Screen Antialiasing Example (Exaggerated)Example (Exaggerated)

Page 32: Antialiasing CAP4730: Computational Structures in Computer Graphics

Antialiasing in OpenGLAntialiasing in OpenGL

To do this in OpenGL, use the To do this in OpenGL, use the Accumulation bufferAccumulation buffer– glAccum(GL_ACCUM, FRAMES_TO_AVERAGE);glAccum(GL_ACCUM, FRAMES_TO_AVERAGE);– glAccum(GL_LOAD, 1);glAccum(GL_LOAD, 1);– glAccum(GL_RETURN);glAccum(GL_RETURN);

VERY SLOW! What does this mean VERY SLOW! What does this mean memory wise?memory wise?

Other approahces: graphics cards, quincuxOther approahces: graphics cards, quincux

Page 33: Antialiasing CAP4730: Computational Structures in Computer Graphics

Aliasing ExamplesAliasing Examples

From: From: http://www.os2ezihttp://www.os2ezine.com/v1n7/colone.com/v1n7/colorwks.htmlrwks.html

Page 34: Antialiasing CAP4730: Computational Structures in Computer Graphics
Page 35: Antialiasing CAP4730: Computational Structures in Computer Graphics

Hardware AntialiasingHardware Antialiasing

Don’t just Don’t just generate 1 generate 1 answer to answer to write to a pixelwrite to a pixel

nVidia nVidia Quincunx AA Quincunx AA (2000 – (2000 – GeForce3)GeForce3)

ResultResult

Page 36: Antialiasing CAP4730: Computational Structures in Computer Graphics

Results from Results from http://www.techreport.com/etc/2005http://www.techreport.com/etc/2005

q3/sli-aa/index.x?pg=4q3/sli-aa/index.x?pg=4

Page 37: Antialiasing CAP4730: Computational Structures in Computer Graphics

DifferenceDifference

Page 38: Antialiasing CAP4730: Computational Structures in Computer Graphics

OpenGL AntialiasingOpenGL Antialiasing

Points and LinesPoints and Lines– glEnable(GL_POINT_SMOOTH);glEnable(GL_POINT_SMOOTH);– glEnable(GL_LINE_SMOOTH);glEnable(GL_LINE_SMOOTH);

TrianglesTriangles– glEnable(GL_POLYGON_SMOOTH);glEnable(GL_POLYGON_SMOOTH);

Provides blend alpha at edges of a Provides blend alpha at edges of a triangletriangle