mae152 computer graphics for scientists and engineers antialiasing fall 2003

32
MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003

Upload: blaze-fitzgerald

Post on 27-Dec-2015

220 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003

MAE152Computer Graphics for Scientists and

Engineers

Antialiasing

Fall 2003

Page 2: MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003

Antialiasing

Contents “Discretization” and consequences What is aliasing and it’s solution (antialiasing) Antialiasing implemented by OpenGL

Page 3: MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003

Samples

most things in the real world are continuous everything in a computer is discrete the process of mapping a continuous function to a

discrete one is called sampling the process of mapping a discrete function to a

continuous one is called reconstruction the process of mapping a continuous variable to a

discrete one is called discretization rendering an image requires sampling and

discretization displaying an image involves reconstruction

Page 4: MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003

Imaging Devices Area Sample

eye : photoreceptors

J. Liang, D. R. Williams and D. Miller, "Supernormal visionand high- resolution retinal imaging through adaptive optics,"J. Opt. Soc. Am. A 14, 2884- 2892 (1997)

Film is similar : irregular array of receptors.

Page 5: MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003

Images

an image is a 2D function I(x, y) that specifies intensity for each point (x, y)

Page 6: MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003

Imaging Devices Area Sample

video camera : CCD array.

Regular array of imagingsensors. y

x

yx

IdxdykV,

Value sensed is an area integral over a pixel.

Intensity, I

Page 7: MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003

Slide © Rosalee Nerheim-Wolfe

Continuous Luminosity Signal

Page 8: MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003

Slide © Rosalee Nerheim-Wolfe

Sampled Luminosity

Page 9: MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003

Slide © Rosalee Nerheim-Wolfe

Reconstructed Luminosity

Page 10: MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003

Slide © Rosalee Nerheim-Wolfe

Reconstruction Artefact

Page 11: MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003

Line Segments

If we tried to sample a line segment so it would map to a 2D raster display…

we would see stair steps, or jaggies … since we “quantized” the pixel values to 0 or 1.

Page 12: MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003

Line Segments

instead, quantize to many shades but what sampling algorithm is used?

Page 13: MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003

Aliasing

The effect created when rasterization is performed over a discrete series of pixels.

In particular, when lines or edges do not necessarily align directly with a row or column of pixels, that line may appear unsmooth and have a stair-step edge appearance.  

Antialiasing utilizes blending techniques to blur the edges of the lines and provide the viewer with the illusion of a smoother line.

Points, lines or polygons can be antialiased. 

Page 14: MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003

Anti-Aliasing

Two general approaches: Area sampling and super-sampling

Area sampling approaches sample primitives with a box (or Gaussian, or whatever) rather than spikes

Requires primitives that have area (lines with width) Sometimes referred to as pre-filtering

Super-sampling samples at higher resolution, then filters down the resulting image

Sometimes called post-filtering The prevalent form of anti-aliasing in hardware

Page 15: MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003

Unweighted Area Sampling

Consider a line as having thickness (all good drawing programs do this)

Consider pixels as little squares

Fill pixels according to the proportion of their square covered by the line

Other variations weigh the contribution according to where in the square the primitive falls

1/8

1/8

.914

.914

.914

1/8

1/8

1/4

1/4

1/41/40 0

00

0000

0

0

0

0 0 0

Page 16: MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003

Alpha-based Anti-Aliasing

Rather than setting the intensity according to coverage, set the

The pixel gets the line color, but with <=1

This supports the correct drawing of primitives one on top of the other

Draw back to front, and composite each primitive over the existing image

Only some hidden surface removal algorithms support it

1/8

1/8

.914

.914

.914

1/8

1/8

1/4

1/4

1/41/40 0

00

0000

0

0

0

0 0 0

Page 17: MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003

Super-sampling

Sample at a higher resolution than required for display, and filter image down

Issues of which samples to take, and how to average them

4 to 16 samples per pixel is typical

Samples might be on a uniform grid, or randomly positioned, or other variants

Number of samples can be adapted

Page 18: MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003

Unweighted Area Sampling

primitive cannot affect intensity of pixel if it does not intersect the pixel

equal areas cause equal intensity, regardless of distance from pixel center to area

unweighted sampling colors two pixels identically when the primitive cuts the same area through the two pixels

intuitively, pixel cut through the center should be more heavily weighted than one cut along corner

Page 19: MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003

Weighted Area Sampling

weighting function, W(x,y) specifies the contribution of primitive passing through

the point (x, y) from pixel center

x

IntensityW(x,y)

Page 20: MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003

Antialiasing in OpenGL

OpenGL calculates a coverage value for each fragment based on the fraction of the pixel square on the screen that it would cover. In RGBA mode, OpenGL multiplies the

fragment’s alpha value by its coverage. Resulting alpha value is used to blend the

fragment with the corresponding pixel already in the frame buffer.

Page 21: MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003

Antialiasing (Cont.)

Page 22: MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003

Hints

With OpenGL, you can control the behavior of anti-aliasing effects by using the glHint() function:void glHint(GLenum target, GLenum hint);

target: parameter indicates which behavior is to be controlled. Specifies the desired sampling quality of points, lines or polygons during antialiasing operations

target parameter can be GL_POINT_SMOOTH_HINT GL_LINE_SMOOTH_HINT GL_POLYGON_SMOOTH_HINT GL_FOG_HINT GL_PERSPECTIVE_CORRECTION_HINT

Page 23: MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003

glHint(target, hint)

hint: parameter specifies the approach

hint parameter can be GL_FASTEST (the most efficient option) GL_NICEST (the highest-quality option) GL_DONT_CARE (no preference)

Page 24: MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003

Enabling Antialiasing

Anti aliasing is enabled using the glEnable() command, We can enable GL_POINT_SMOOTH or GL_LINE_SMOOTH modes.

With RGBA mode, you must also enable blending to utilize GL_SRC_ALPHA as the source factor and GL_ONE_MINUS_SRC_ALPHA as the destination factor.

Using a destination factor of GL_ONE will make intersection points a little brighter.

Page 25: MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003

Antialiasing Lines

init() {

glEnable (GL_LINE_SMOOTH);

glEnable (GL_BLEND);

glBlendFunc (GL_SRC_ALPHA,

GL_ONE_MINUS_SOURCE_ALPHA);

glHint (GL_LINE_SMOOTH_HINT,

GL_NICEST);

draw_lines_here();

}

Page 26: MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003

Antialiasing Polygons

Study OpenGL Book

We can also use accumulation buffer

Using accumulation buffer is easier to understand than using blending, but computationally more expensive.

Page 27: MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003

Demo Intersecting lines

Page 28: MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003

Fog

General term that describes similar forms of atmospheric effects Haze, mist, smoke, or pollution

Can make an entire image appear more natural by adding fog, which makes objects fade into the distance.

Fog is applied after matrix transformations, lighting, and texturing are performed.

With large simulation programs, fog can improve performance.

Page 29: MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003

Defining Fog in OpenGL

glFogf(GL_FOG_MODE, GL_EXP); GL_EXP2 GL_LINEAR

glFogf(GL_FOG_DENSITY, 0.5); glFogf(GL_FOG_START, 0.0); glFogf(GL_FOG_DENSITY, 1.0);

In RGBA mode, the fog factor f isC = fCi + (1-f)Cf

Ci is incoming fragment’s RGBA value, Cf is fog-color value.

Page 30: MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003

Fog Equations

Page 31: MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003

Sample Code

init() {

Glfloat fogcolor[4] = {0.5, 0.5, 0.5, 1.0};

glEnable(GL_FOG);

glFogi (GL_FOG_MODE, GL_EXP);

glFogfv (GL_FOG_COLOR, fogColor);

glFogf (GL_FOG_DENSITY, 0.35);

glFogf (GL_FOG_HINT, GL_NICEST);

glFogf (GL_FOG_START, 1.0);

glFogf (GL_FOG_END, 5.0);

}

Page 32: MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003

End of Antialiasing and Fog