MAE152 Computer Graphics for Scientists and Engineers Antialiasing Fall 2003.

Slides:



Advertisements
Similar presentations
Compositing and Blending Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics.
Advertisements

CS 445 / 645 Introduction to Computer Graphics Lecture 18 Antialiasing Antialiasing.
CP411 polygon Lecture 6 1. Scan conversion algorithm for circle 2. Draw polygons 3. Antialiasing.
Graphics Pipeline.
RealityEngine Graphics Kurt Akeley Silicon Graphics Computer Systems.
Computer Graphics(Fall 2003) COMS 4160, Lecture 7: OpenGL 3 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
CS 4363/6353 BASIC RENDERING. THE GRAPHICS PIPELINE OVERVIEW Vertex Processing Coordinate transformations Compute color for each vertex Clipping and Primitive.
1. 2 Blending: tells you how to specify a blending function that combines color values from a source and a destination. The final effect is that parts.
CS 551 / CS 645 Antialiasing. What is a pixel? A pixel is not… –A box –A disk –A teeny tiny little light A pixel is a point –It has no dimension –It occupies.
Compositing and Blending Mohan Sridharan Based on slides created by Edward Angel 1 CS4395: Computer Graphics.
Blending MAE152 Computer Graphics for Engineers and Scientists Fall 03.
Compositing and Blending - Chapter 8 modified by Ray Wisman Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Image Compositing Angel 8.11 Angel: Interactive Computer Graphics5E © Addison-Wesley
CSC 461: Lecture 51 CSC461 Lecture 5: Simple OpenGL Program Objectives: Discuss a simple program Discuss a simple program Introduce the OpenGL program.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Computer Science,
University of British Columbia CPSC 414 Computer Graphics © Tamara Munzner 1 Scan Conversion Week 6, Fri 10 Oct 2003 sampling.
09/18/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Bump Mapping Multi-pass algorithms.
Using Graphics Libraries Lecture 3 Mon, Sep 1, 2003.
Image Synthesis Rabie A. Ramadan, PhD 3. 2 Our Problem.
Computer Graphics, KKU. Lecture 131 Transformation and Viewing in OpenGL.
Lecture 12 Blending, Anti-aliasing, Fog, Display Lists.
10/26/04© University of Wisconsin, CS559 Fall 2004 Last Time Drawing lines Polygon fill rules Midterm Oct 28.
Graphics Systems and OpenGL. Business of Generating Images Images are made up of pixels.
Lecture 14 Shading models 1.Shading Constant Shading (to be implemented) Gouraud Shading Phong Shading 2.Light and shading with OpenGL 1.
1 Chapter 6 Blending, Antialiasing, Fog, and Polygon Offset Guihua Yang Jan 14, 2004.
Week 6 - Wednesday.  What did we talk about last time?  Light  Material  Sensors.
DREAM PLAN IDEA IMPLEMENTATION Introduction to Computer Graphics Dr. Kourosh Kiani
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Introduction to OpenGL (part 2)
OpenGL Lighting Jian-Liang Lin 2002 Hidden-Surface Removal -1 Original Code: while (1) { get_viewing_point_from_mouse_position(); glClear(GL_COLOR_BUFFER_BIT);
Draw a Simple Object. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture blending.
Compositing and Blending
Viewing and Transformation. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture.
Introduction to Computer Graphics EEL
CGGM Lab. Tan-Chi Ho 2001 Viewing and Transformation.
Projections. Viewports Windows can have separate viewports void glViewport(GLint x, GLint y, GLsizei width, GLsizei height ) x, y - Specify the lower.
UniS CS297 Graphics with Java and OpenGL Blending.
OpenGL Special Effects Jian-Liang Lin 2002 Blending: Alpha Channel Alpha value can be specify by glColor* When blending is enabled, the alpha value is.
Chap 3 Viewing and Transformation
OpenGL Basic Drawing 2003 Spring Keng Shih-Ling
CS559: Computer Graphics Lecture 12: Antialiasing & Visibility Li Zhang Spring 2008.
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Chapter 4 -- Color1 Color Open GL Chapter 4. Chapter 4 -- Color2 n The goal of almost all OpenGL applications is to draw color pictures in a window on.
CS559: Computer Graphics Lecture 12: OpenGL - Transformation Li Zhang Spring 2008.
CS559: Computer Graphics Lecture 12: OpenGL: ModelView Li Zhang Spring 2010.
OpenGL Basic Drawing Jian-Liang Lin A Smidgen of OpenGL Code #include main() { InitializeAWindowPlease(); glClearColor (0.0, 0.0, 0.0, 0.0); glClear.
Compositing and Blending Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
Computer Graphics I, Fall 2008 Compositing and Blending.
OpenGL LAB III.
CS380 LAB II OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
Computer Graphics Lecture 41 Viewing Using OpenGL Taqdees A. Siddiqi
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Chapter 6. Blending, Antialiasing, Fog, and Polygon Offset Computer Graphics (spring, 2009) School of Computer Science University of Seoul.
CS 4722 Made by Dr. Jeffrey Chastine Modified by Dr. Chao Mei
Attributes of Graphics Primitives Hearn & Baker Chapter 4
Programming with OpenGL Part 2: Complete Programs
Advanced Graphics Algorithms Ying Zhu Georgia State University
OpenGL API 2D Graphic Primitives
Programming with OpenGL Part 2: Complete Programs
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
I = a I + ( ) 1 – a I BLENDING, ANTIALIASING, AND FOG l l 1 l 2 Earth
CSc4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University Fog and Transparency.
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Introduction to OpenGL
Computer Graphics Practical Lesson 7
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Presentation transcript:

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

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 vision and high- resolution retinal imaging through adaptive optics," J. Opt. Soc. Am. A 14, (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 imaging sensors. y x 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

Area Sampling shade pixels according to the area covered by thickened line this is unweighted area sampling a rough approximation formulated by dividing each pixel into a finer grid of pixels

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/

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/

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 Intensity W(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

Antialiasing Example The following example demonstrates the use of anti aliasing techniques using the blending and line smoothing. The program renders a wired dodecahedron and then allows the user to view through the standard model viewing capabilities using the keyboard for axis positioning and the arrow and page up/down keys for incrementing or decrementing eye point positions. Depressing an 'a' will toggle antialiasing. Depressing a b toggles between two different alpha blending settings and depressing an "l" will vary the thickness of the objects lines.

Antialiasing Example Without anti-aliasing:

Antialiasing Example With anti-aliasing:

Antialiasing Example #include #ifdef __FLAT__ #include #endif #include static float rotAngle = 0; static GLbooleanantialiasFlag = GL_FALSE; GLfloat nearClip, farClip; GLdouble eyex=0.0, eyey=0.0, eyez=15.0; void init() { GLfloat maxObjectSize = 3.0; glClearColor( 0.0, 0.0, 0.0, 0.0); glShadeModel( GL_FLAT); nearClip = 1.0; farClip = nearClip + 80*maxObjectSize; glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glLineWidth(4.5); glEnable( GL_DEPTH_TEST); }

Antialiasing Example void blendFuncCycle( GLvoid) { static int whichBlendFunc = 0; whichBlendFunc = (whichBlendFunc + 1) %2; switch(whichBlendFunc) { case 0:glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);break; case 1:glBlendFunc( GL_SRC_ALPHA, GL_ONE); break; default:break; } void drawAntialiasedObjects() { static GLfloatyellow[] = { 1.0, 1.0, 0.0, 1.0 }; if ( antialiasFlag == GL_TRUE){ glEnable( GL_LINE_SMOOTH); glEnable( GL_BLEND); } glPushMatrix(); glColor4fv( yellow ); glScalef( 2.0, 2.0, 2.0 ); glutWireDodecahedron(); glPopMatrix(); if ( antialiasFlag == GL_TRUE ) { glDisable( GL_LINE_SMOOTH); glDisable( GL_BLEND); }

Antialiasing Example void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glLoadIdentity(); gluLookAt(eyex, eyey, eyez, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); drawAntialiasedObjects(); glFlush(); } void reshape (int width, int height) { GLdouble aspect; glViewport( 0, 0, width, height ); aspect = (GLdouble) width / (GLdouble) height; glMatrixMode( GL_PROJECTION); glLoadIdentity(); gluPerspective( 45.0, aspect, nearClip, farClip ); glMatrixMode( GL_MODELVIEW ); } void setEyePoint(void) { eyex=0.0; eyey=0.0; eyez = 15.0; return; }

Antialiasing Example void specialkeys( int key, int x, int y ) { switch (key) { case GLUT_KEY_LEFT:eyex--; break; case GLUT_KEY_RIGHT:eyex++; break; case GLUT_KEY_DOWN:eyey--; break; case GLUT_KEY_UP:eyey++; break; case GLUT_KEY_PAGE_UP:eyez++; break; case GLUT_KEY_PAGE_DOWN:eyez--;break; case GLUT_KEY_HOME:setEyePoint(); break; case GLUT_KEY_END: exit(0);break; default: break; } glutPostRedisplay(); } void keyboard(unsigned char key, int x, int y ) { static float lineWidth = 0.5; switch(key) { case 'a': case 'A': antialiasFlag = ! antialiasFlag; if (antialiasFlag == GL_TRUE) { glEnable( GL_POINT_SMOOTH ); glEnable ( GL_LINE_SMOOTH ); }

Antialiasing Example else { glDisable( GL_POINT_SMOOTH ); glDisable( GL_LINE_SMOOTH ); } break; case 'b': blendFuncCycle(); break; case 'l': lineWidth += 0.5; if (lineWidth >= 8.0) lineWidth = 0.5; glLineWidth(lineWidth); break; case 'x': eyex=12.0; eyey=0.0; eyez=0.0; break; case 'y': eyex=0.05; eyey=12.0; eyez=0.0; break; case 'z': eyex=0.0; eyey=0.0; eyez=12.0; break; case 27: case 'e': case 'E': exit(0);break; default: break; } glutPostRedisplay(); }

Antialiasing Example int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(500, 500); glutCreateWindow( argv[0]); init(); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutDisplayFunc(display); glutSpecialFunc( specialkeys ); glutMainLoop(); return 0; }

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 is C = fC i + (1-f)C f C i is incoming fragment’s RGBA value, C f 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); }

Polygon Offset Because lines and filled polygons are not rasterized in exactly the same way, the depth values generated for pixels on a line are usually not the same as the depth values for a polygon edge. To eliminate visual artifacts (stiches), adds an appropriate offset to force coincident z values apart to cleanly separate a polygon edge. Three ways to turn on polygon offset GL_FILL, GL_LINE, GL_POINT Must also call glPolygonMode() to set the current polygon rasterization method.

Polygon Offset (Cont.) The Offset value o is calculated by m : maximum depth slope r : the smallest value guaranteed to produce a resolvable difference in window coordinate depth value When enabled, the depth value of each fragment is added to a calculated offset value. glPolygonOffset(GLfloat factor, GLfloat units)

Sample Code glEnable (GL_LIGHTING); glEnable (GL_LIGHT0); glEnable (GL_POLYGON_OFFSET_FILL); glPolygonOffset(1.0, 1.0); glCallList (list); glDisable (GL_POLYGON_OFFSET_FILL); // To highlight the edges of the object, the object is rendered as an unlit wireframe with the offset disabled. glDisable (GL_LIGHTING); glDisable (GL_LIGHT0); glColor3f (1.0, 1.0, 1.0); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glCallList (list); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

End of Antialiasing and Fog