MAE 152 Computer Graphics for Scientists and Engineers

  • Slides: 32
Download presentation
MAE 152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003

MAE 152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003

Antialiasing n Contents n n n “Discretization” and consequences What is aliasing and it’s

Antialiasing n Contents n n n “Discretization” and consequences What is aliasing and it’s solution (antialiasing) Antialiasing implemented by Open. GL

Samples n n n n most things in the real world are continuous everything

Samples n n n n 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 n eye : photoreceptors Film is similar : irregular array

Imaging Devices Area Sample n eye : photoreceptors Film is similar : irregular array of receptors. J. Liang, D. R. Williams and D. Miller, "Supernormal vision and high- resolution retinal imaging through adaptive optics, " J. Opt. Soc. Am. A 14, 2884 - 2892 (1997)

Images n an image is a 2 D function I(x, y) that specifies intensity

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

Imaging Devices Area Sample n video camera : CCD array. Regular array of imaging

Imaging Devices Area Sample n video camera : CCD array. Regular array of imaging sensors. y Intensity, I Value sensed is an area integral over a pixel. x

Continuous Luminosity Signal Slide © Rosalee Nerheim-Wolfe

Continuous Luminosity Signal Slide © Rosalee Nerheim-Wolfe

Sampled Luminosity Slide © Rosalee Nerheim-Wolfe

Sampled Luminosity Slide © Rosalee Nerheim-Wolfe

Reconstructed Luminosity Slide © Rosalee Nerheim-Wolfe

Reconstructed Luminosity Slide © Rosalee Nerheim-Wolfe

Reconstruction Artefact Slide © Rosalee Nerheim-Wolfe

Reconstruction Artefact Slide © Rosalee Nerheim-Wolfe

Line Segments n n n If we tried to sample a line segment so

Line Segments n n n If we tried to sample a line segment so it would map to a 2 D raster display… we would see stair steps, or jaggies … since we “quantized” the pixel values to 0 or 1.

Line Segments n n instead, quantize to many shades but what sampling algorithm is

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

Aliasing n n The effect created when rasterization is performed over a discrete series

Aliasing n n 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 n n Two general approaches: Area sampling and supersampling Area sampling approaches sample

Anti-Aliasing n n Two general approaches: Area sampling and supersampling Area sampling approaches sample primitives with a box (or Gaussian, or whatever) rather than spikes n n n 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 n n Sometimes called post-filtering The prevalent form of anti-aliasing in hardware

Unweighted Area Sampling n n Consider a line as having thickness (all good drawing

Unweighted Area Sampling n n Consider a line as having thickness (all good drawing 1/8 0 0 programs do this) Consider pixels as little squares 0 0 1/4. 914 1/8 Fill pixels according to the 0 1/4. 914 1/4 0 proportion of their square covered by the line 1/8. 914 0 1/4 0 Other variations weigh the contribution according to 0 1/8 0 0 0 where in the square the primitive falls

Alpha-based Anti-Aliasing n Rather than setting the intensity according to coverage, set the n

Alpha-based Anti-Aliasing n Rather than setting the intensity according to coverage, set the n n The pixel gets the line color, but with <=1 This supports the correct drawing of primitives one on top of the other n n Draw back to front, and composite each primitive over the existing image Only some hidden surface removal algorithms support it 0 0 0 1/8 0 0 . 914 1/8 0 1/4 . 914 1/8. 914 1/4 0 1/8 0 0 0 0

Super-sampling n n n Sample at a higher resolution than required for display, and

Super-sampling n n n 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 n n primitive cannot affect intensity of pixel if it does

Unweighted Area Sampling n n 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 n weighting function, W(x, y) n specifies the contribution of primitive

Weighted Area Sampling n weighting function, W(x, y) n specifies the contribution of primitive passing through the point (x, y) from pixel center Intensity W(x, y) x

Antialiasing in Open. GL calculates a coverage value for each fragment based on the

Antialiasing in Open. GL calculates a coverage value for each fragment based on the fraction of the pixel square on the screen that it would cover. n n In RGBA mode, Open. GL 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. )

Antialiasing (Cont. )

Hints n n n With Open. GL, you can control the behavior of antialiasing

Hints n n n With Open. GL, you can control the behavior of antialiasing effects by using the gl. Hint() function: void gl. Hint(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 n GL_POINT_SMOOTH_HINT n GL_LINE_SMOOTH_HINT n GL_POLYGON_SMOOTH_HINT n GL_FOG_HINT n GL_PERSPECTIVE_CORRECTION_HINT

gl. Hint(target, hint) n n hint: parameter specifies the approach hint parameter can be

gl. Hint(target, hint) n n hint: parameter specifies the approach hint parameter can be n GL_FASTEST (the most efficient option) n GL_NICEST (the highest-quality option) n GL_DONT_CARE (no preference)

Enabling Antialiasing n n n Anti aliasing is enabled using the gl. Enable() command,

Enabling Antialiasing n n n Anti aliasing is enabled using the gl. Enable() 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() { gl. Enable (GL_LINE_SMOOTH); gl. Enable (GL_BLEND); gl. Blend. Func (GL_SRC_ALPHA,

Antialiasing Lines init() { gl. Enable (GL_LINE_SMOOTH); gl. Enable (GL_BLEND); gl. Blend. Func (GL_SRC_ALPHA, GL_ONE_MINUS_SOURCE_ALPHA); gl. Hint (GL_LINE_SMOOTH_HINT, GL_NICEST); draw_lines_here(); }

Antialiasing Polygons n Study Open. GL Book n We can also use accumulation buffer

Antialiasing Polygons n Study Open. GL Book n We can also use accumulation buffer n Using accumulation buffer is easier to understand than using blending, but computationally more expensive.

n n Demo Intersecting lines

n n Demo Intersecting lines

Fog n General term that describes similar forms of atmospheric effects n n Haze,

Fog n General term that describes similar forms of atmospheric effects n n 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 Open. GL n gl. Fogf(GL_FOG_MODE, GL_EXP); GL_EXP 2 GL_LINEAR gl. Fogf(GL_FOG_DENSITY,

Defining Fog in Open. GL n gl. Fogf(GL_FOG_MODE, GL_EXP); GL_EXP 2 GL_LINEAR gl. Fogf(GL_FOG_DENSITY, 0. 5); gl. Fogf(GL_FOG_START, 0. 0); gl. Fogf(GL_FOG_DENSITY, 1. 0); n In RGBA mode, the fog factor f is n n C = f. Ci + (1 -f)Cf Ci is incoming fragment’s RGBA value, Cf is fog-color value.

Fog Equations

Fog Equations

Sample Code init() { Glfloat fogcolor[4] = {0. 5, 1. 0}; gl. Enable(GL_FOG); gl.

Sample Code init() { Glfloat fogcolor[4] = {0. 5, 1. 0}; gl. Enable(GL_FOG); gl. Fogi (GL_FOG_MODE, GL_EXP); gl. Fogfv (GL_FOG_COLOR, fog. Color); gl. Fogf (GL_FOG_DENSITY, 0. 35); gl. Fogf (GL_FOG_HINT, GL_NICEST); gl. Fogf (GL_FOG_START, 1. 0); gl. Fogf (GL_FOG_END, 5. 0); }

End of Antialiasing and Fog

End of Antialiasing and Fog