mae152 computer graphics for scientists and engineers antialiasing fall 2003

Post on 27-Dec-2015

220 Views

Category:

Documents

3 Downloads

Preview:

Click to see full reader

TRANSCRIPT

MAE152Computer 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

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

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.

Images

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

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

Slide © Rosalee Nerheim-Wolfe

Continuous Luminosity Signal

Slide © Rosalee Nerheim-Wolfe

Sampled Luminosity

Slide © Rosalee Nerheim-Wolfe

Reconstructed Luminosity

Slide © Rosalee Nerheim-Wolfe

Reconstruction Artefact

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.

Line Segments

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

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. 

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

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

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

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

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

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)

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.

Antialiasing (Cont.)

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

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)

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.

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();

}

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.

Demo Intersecting lines

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.

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.

Fog Equations

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);

}

End of Antialiasing and Fog

top related