Pattern filling in scan-conversion Antialiasing

Slides:



Advertisements
Similar presentations
Visible-Surface Detection(identification)
Advertisements

CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1 Emmanuel Agu.
Line and Curve Drawing Algorithms. Line Drawing x0x0 y0y0 x end y end.
2006 by Jim X. Chen: 1.1. Review –Graphics commands specify straight lines or other geometric primitives that are scan-converted.
+ CPCS 391 Computer Graphics 1 Instructor: Dr. Sahar Shabanah Lecture 3.
Line Drawing Algorithms. Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen. Scan Conversion-Digitizing.
Computer Graphics Tz-Huan Huang National Taiwan University (Slides are based on Prof. Chen’s)
CP411 polygon Lecture 6 1. Scan conversion algorithm for circle 2. Draw polygons 3. Antialiasing.
Chapter 3 Drawing and Composing an Illustration. Objectives Draw straight lines Draw curved lines Draw elements of an illustration Apply attributes to.
© 2001 By Default! A Free sample background from Slide 1 Attributes of Output Primitives Definition Parameter that affects.
CS 376 Introduction to Computer Graphics 04 / 09 / 2007 Instructor: Michael Eckmann.
CST 494/598 Computer Graphics Anshuman Razdan i3dea.asu.edu/razdan.
Aliasing and Anti-Aliasing Copyright Zachary Wartell, University of North Carolina at Charlotte, All Rights Reserved Revision: 10/24/2007 3:38:00 AM ©Zachary.
CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Scan Conversion CS123 1 of 44Scan Conversion - 10/14/2014.
March Shape Drawing Algorithms Shmuel Wimer Bar Ilan Univ., Engineering Faculty.
Geometric Objects Computer Graphics Lab. Sun-Jeong Kim.
CGMB214: Introduction to Computer Graphics
Tools for Raster Displays CVGLab Goals of the Chapter To describe pixmaps and useful operations on them. To develop tools for copying, scaling, and rotating.
3/4/04© University of Wisconsin, CS559 Spring 2004 Last Time Clipping Lines –Cohen-Sutherland: The use of outcodes and early reject/accept tests –Liang-Barsky:
Graphics Graphics Korea University cgvr.korea.ac.kr Raster Graphics 고려대학교 컴퓨터 그래픽스 연구실.
2002 by Jim X. Chen George Mason University Transformation and Viewing.1. Plane Example: J2_0_2DTransform.
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.
1 Introduction Line attribute Color and gray scale Area filled attribute Anti-aliasing.
Graphics Graphics & Graphical Programming Lecture 14 - Lines & Circles.
Line Drawing and Generalization. Outline  overview  line drawing  circle drawing  curve drawing.
2D Output Primitives Points Lines Circles Ellipses Other curves Filling areas Text Patterns Polymarkers.
Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization.
Introduction to OpenGL. OpenGL is a low-level graphics library specification. It makes available to the programmer  a small set of geometric primitives.
Computer Graphics Rendering 2D Geometry CO2409 Computer Graphics Week 2.
Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
In the name of God Computer Graphics. Today Introduction Sampling Graphic Output Primitives 1.Line 2.Circle 3.Curve 4.polygon.
UniS CS297 Graphics with Java and OpenGL Blending.
2D Output Primitives Points Lines Circles Ellipses Other curves Filling areas Text Patterns Polymarkers.
Scan Conversion.
Lecture 13: Raster Graphics and Scan Conversion
2002 by Jim X. Chen: Drawing Geometric Models.1. Objectives –OpenGL drawing primitives and attributes –OpenGL polygon face.
CS552: Computer Graphics Lecture 17: Scan Conversion (Special Cases)
Lecture 2: 19/4/1435 Graphical algorithms Lecturer/ Kawther Abas CS- 375 Graphics and Human Computer Interaction.
Rasterization Overview Raster Display Device. Scan Conversion / Rasterization: converting vector graphics into raster graphics (determining pixels in.
Attributes of Graphics Primitives Chapter 4
ATTRIBUTE OF OUTPUT PRIMITIVES. Attribute of Output Primitives 30/9/2008 A.Aruna/Assistant professor/IT/SNSCE 2 Definition Line Attribute Curve Attribute.
10/10/2006TCSS458A Isabelle Bichindaritz1 Line and Circle Drawing Algorithms.
Computer Graphics I, Fall 2010 Scan conversion algorithms.
OUTPUT PRIMITIVES CEng 477 Computer Graphics METU, 2004.
Computer Graphics Drawing Line.
CSCE 441 Lecture 2: Scan Conversion of Lines
Attributes of Graphics Primitives Hearn & Baker Chapter 4
- Introduction - Graphics Pipeline
Basic Raster Graphics Algorithms for Drawing 2D Primitives
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1
ATCM 3310 Procedural Animation
University of New Mexico
Implementation III.
Introduction to Computer Graphics with WebGL
Objectives OpenGL drawing primitives and attributes
3D Rendering Pipeline Hidden Surface Removal 3D Primitives
o عَلَّمَهُ الْبَيَانَ
Lecture 13 Clipping & Scan Conversion
Line and Curve Drawing Algorithms
Computer Graphics Implementation III
Edited from The Rasterization Problem: Idealized Primitives Map to Discrete Display Space Edited from.
Plane 2D GEOMETRICAL TRANSFORMATIONS Example: J2_0_2DTransform
Chapter 3 Graphics Output Primitives
Primitive Drawing Algorithm
Basic Raster Graphics Algorithms for Drawing 2D Primitives
Primitive Drawing Algorithm
Implementation III Ed Angel Professor Emeritus of Computer Science
Presentation transcript:

Pattern filling in scan-conversion Antialiasing Attributes and Animation Pattern filling in scan-conversion Antialiasing Double-buffering and animation Copyright @ 2002 by Jim X. Chen: jchen@cs.gmu.edu .1.

Copyright @ 2002 by Jim X. Chen: jchen@cs.gmu.edu ATTRIBUTES Any parameter that affects a primitive displayed is an attribute parameter. Polygon Attributes pattern, color, anti-aliasing Line Attributes type (solid, dashed, dotted), width, cap (butt, round, square), join (miter, round, etc.), pattern, color, anti-aliasing Copyright @ 2002 by Jim X. Chen: jchen@cs.gmu.edu .2.

Copyright @ 2002 by Jim X. Chen: jchen@cs.gmu.edu PATTERN FILLING (bitmap patterns) The 1s & 0s select foreground and background color, respectively. For transparent mode, only 1s are written with foreground color. Anchor the pattern at a vertex of a primitive; this choice allows the pattern to move with the primitive Anchor the pattern at the corner of the drawing area; the pattern does not move with the primitive Generating patterns while scan-converting, or scan converting a primitive first into a rectangular work area, and then copy pixels from the rectangular bitmap to the appropriate space in the background. Copyright @ 2002 by Jim X. Chen: jchen@cs.gmu.edu .3.

Copyright @ 2002 by Jim X. Chen: jchen@cs.gmu.edu Triangle Pattern Generating color patterns on a span (horizontal line) void span(int x2, int x1, int y) { for (int x = x1; x<x2; x++) { if (cnt % 100 < 50) // triangle pattern anchored on frame gl.glColor3d(Math.sin(x/5), Math.cos(x/5), 1); else // triangle pattern anchored on triangle coordinates gl.glColor3d(Math.sin((x-x1)/5), Math.cos((x-x1)/5), 1); drawPoint(x, y); } Copyright @ 2002 by Jim X. Chen: jchen@cs.gmu.edu .4.

Drawing Geometric Models SPECIFYING A COLOR glColor3f(0.0, 0.0, 0.0); draw_object(A); In OpenGL 4.x, we use VBO to specify colors for the vertices, so glColor is getting obsolete. draw_object(B); glColor3f(1.0, 0.0, 0.0); draw_object(C); glColor3f(0.0, 0.0, 0.0); black glColor3f(1.0, 0.0, 0.0); red glColor3f(0.0, 1.0, 0.0); green glColor3f(1.0, 1.0, 0.0); yellow glColor3f(0.0, 0.0, 1.0); blue glColor3f(1.0, 0.0, 1.0); magenta glColor3f(0.0, 1.0, 1.0); cyan glColor3f(1.0, 1.0, 1.0); white Copyright @ 2002 by Jim X. Chen: jchen@cs.gmu.edu .5.

Copyright @ 2002 by Jim X. Chen: jchen@cs.gmu.edu Line Anti-aliasing Demo Antialiasing Copyright @ 2002 by Jim X. Chen: jchen@cs.gmu.edu .6.

Copyright @ 2002 by Jim X. Chen: jchen@cs.gmu.edu Supersampling (postfiltering) Increase sampling rate, each pixel area is covered by a finer grid We can then use multiple sample points in a pixel that is within a line to determine an appropriate intensity level for the pixel. Supersampling algorithms often choose more weight to subpixels near the center of a pixel area: pixel- wighting masks Copyright @ 2002 by Jim X. Chen: jchen@cs.gmu.edu .7.

Copyright @ 2002 by Jim X. Chen: jchen@cs.gmu.edu Area sampling (prefiltering) Determine pixel intensity by calculating the areas of overlap of each pixel with the objects to be displayed Unweighted Area Sampling determines the pixel intensity by the overlap area only Weighted Area Sampling an area closer to the pixel’s center has greater influence on the pixel’s intensity than an equal area further away from the pixel’s center. Copyright @ 2002 by Jim X. Chen: jchen@cs.gmu.edu .8.

Copyright @ 2002 by Jim X. Chen: jchen@cs.gmu.edu FILTER FUNCTIONS Cone filter , Gaussian filter, Intensity table, etc. A simple equation for 3-pixel wide line Given the current pixel’s color (r, g, b), we can modify the intensity by: (r, g, b)*(1-D/1.5). Therefore, the pixels have different intensity levels depending on their distances from the center of the line. For a foreground color F and background color B: F*(1-D/1.5) + B*D/1.5. We can read the current pixel color from the framebuffer. gl.glReadPixels(x, y,1,1, GL.GL_RGB,GL.GL_UNSIGNED_BYTE, buffer); How to calculate D? Copyright @ 2002 by Jim X. Chen: jchen@cs.gmu.edu .9.

Copyright @ 2002 by Jim X. Chen: jchen@cs.gmu.edu Antialiasing a straight line DNE = DE – cos a = D + sin a – cos a Copyright @ 2002 by Jim X. Chen: jchen@cs.gmu.edu .10.

Copyright @ 2002 by Jim X. Chen: jchen@cs.gmu.edu Antialiasing void IntensifyPixel(int x,int y, double D) { float d, r1, g1, b1; if (D<0) D = -D; r1=r*(1-D/1.5); g1=g*(1-D/1.5); b1=b*(1-D/1.5); glColor3f(r1, g1, b1); writepixel(x,y); } Example: J1_4_Line Example: J1_4_Line_Background Copyright @ 2002 by Jim X. Chen: jchen@cs.gmu.edu .11.

Copyright @ 2002 by Jim X. Chen: jchen@cs.gmu.edu void antialiasedLine(int x0,int y0,int xn,int yn) { int dx, dy, incrE, incrNE, d, x, y; float D=0, sin_a, cos_a, smc_a, Denom; dy=yn-y0; dx=xn-x0; x=x0; y=y0; d=2*dy-dx; incrE=2*dy; incrNE=2*(dy-dx); Denom = sqrt(dx*dx + dy*dy); sin_a = dy / Denom; cos_a = dx / Denom; smc_a = sin_a - cos_a; while (x<xn+1) { IntensifyPixel(x,y,D); // current pixel IntensifyPixel(x,y+1,D-cos_a); // North IntensifyPixel(x,y-1,D+cos_a); // South x++; if (d<=0) { D+=sin_a; d+=incrE; } else { D+=smc_a; y++; d+=incrNE; }; } } /* AntiAliased Midpoint Algorithm */ Antialiasing Copyright @ 2002 by Jim X. Chen: jchen@cs.gmu.edu .12.

Frame Rate and Refresh Rate If the display refreshes at 60 times per second (f/s), this means that the fastest image frame rate you can achieve is 60 f/s; it is about 17 millisecond a frame; What often happens is that the frame is too complicated to draw in 1/60 second, so each frame is displayed more than once Notice the difference between the image frame rate and display refresh rate. animator = new FPSAnimator(canvas, 40); the thread display() has a target frame rate: to repeat at 40 f/s; to avoid rendering images too fast, to save CPU time You can use try {Thread.sleep(17);} catch (Exception ignore) {} to wait for 17 millisecond; Copyright @ 2002 by Jim X. Chen: jchen@cs.gmu.edu

Drawing Geometric Models Circle depth=0, draw 4 triangles. depth=1, each triangle is subdivided into two and we draw 8 triangles. consider v1, v2, and v12 as vectors. Then, v12 is in the direction of (v1 + v2)=(v1x+v2x, v1y+v2y, v1z+v2z) and |v1| = |v2| = |v12|. v12 = normalize(v1 + v2). Normalizing a vector is equivalent to scaling the vector to a unit vector. recursively subdivides depth times and draws 2depth triangles. Copyright @ 2002 by Jim X. Chen: jchen@cs.gmu.edu : .14.

Copyright @ 2002 by Jim X. Chen: jchen@cs.gmu.edu Example: J1_5_Circle subdivideCircle(int radius, float[] v1, float[] v2, int depth) { float v11[] = new float[3]; float v22[] = new float[3]; float v00[] = { 0, 0, 0 }; float v12[] = new float[3]; if (depth == 0) { for (int i = 0; i < 3; i++) { v11[i] = v1[i] * radius; v22[i] = v2[i] * radius; } drawtriangle(v11, v22, v00); return; v12[0] = v1[0]+v2[0]; v12[1] = v1[1]+v2[1]; v12[2] = v1[2]+v2[2]; normalize(v12); // subdivide a triangle recursively, and draw them subdivideCircle(radius, v1, v12, depth - 1); subdivideCircle(radius, v12, v2, depth - 1); Copyright @ 2002 by Jim X. Chen: jchen@cs.gmu.edu