CS 248 Assignment 2 Polygon Scan Converter. CS248 Presented by Abe Davis Stanford University October 17, 2008

Similar documents
CS 248 Assignment 2 Polygon Scan Conversion. CS248 Presented by Michael Green Stanford University October 20, 2004

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

Triangle Rasterization

(Refer Slide Time: 00:02:00)

Chapter 8: Implementation- Clipping and Rasterization

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into

Announcements. Midterms graded back at the end of class Help session on Assignment 3 for last ~20 minutes of class. Computer Graphics

Polygon Filling. Can write frame buffer one word at time rather than one bit. 2/3/2000 CS 4/57101 Lecture 6 1

COMP371 COMPUTER GRAPHICS

Scan Conversion. Drawing Lines Drawing Circles

Drawing in 3D (viewing, projection, and the rest of the pipeline)

CS 4620 Program 3: Pipeline

EF432. Introduction to spagetti and meatballs

Sign up for crits! Announcments

Art-based Rendering with Graftals

0. Introduction: What is Computer Graphics? 1. Basics of scan conversion (line drawing) 2. Representing 2D curves

CS 543: Computer Graphics. Rasterization

Last class. A vertex (w x, w y, w z, w) - clipping is in the - windowing and viewport normalized view volume if: - scan conversion/ rasterization

Graphics (Output) Primitives. Chapters 3 & 4

Rasterization and Graphics Hardware. Not just about fancy 3D! Rendering/Rasterization. The simplest case: Points. When do we care?

Drawing in 3D (viewing, projection, and the rest of the pipeline)

CS559: Computer Graphics. Lecture 12: Antialiasing & Visibility Li Zhang Spring 2008

CSC Computer Graphics

Computer Graphics : Bresenham Line Drawing Algorithm, Circle Drawing & Polygon Filling

Renderer Implementation: Basics and Clipping. Overview. Preliminaries. David Carr Virtual Environments, Fundamentals Spring 2005

Drawing in 3D (viewing, projection, and the rest of the pipeline)

Introduction Rasterization Z-buffering Shading. Graphics 2012/2013, 4th quarter. Lecture 09: graphics pipeline (rasterization and shading)

Topic 0. Introduction: What Is Computer Graphics? CSC 418/2504: Computer Graphics EF432. Today s Topics. What is Computer Graphics?

Computer Graphics. - Rasterization - Philipp Slusallek

The Application Stage. The Game Loop, Resource Management and Renderer Design

Scan Conversion of Polygons. Dr. Scott Schaefer

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 14

UNIT -8 IMPLEMENTATION

Scan line algorithm. Jacobs University Visualization and Computer Graphics Lab : Graphics and Visualization 272

CS488 2D Graphics. Luc RENAMBOT

Raster Displays and Scan Conversion. Computer Graphics, CSCD18 Fall 2008 Instructor: Leonid Sigal

In today s lecture we ll have a look at: A simple technique The mid-point circle algorithm

Chapter 3. Sukhwinder Singh

Last Time: Acceleration Data Structures for Ray Tracing. Schedule. Today. Shadows & Light Sources. Shadows

Rendering. Converting a 3D scene to a 2D image. Camera. Light. Rendering. View Plane

CS 325 Computer Graphics

CSCI 420 Computer Graphics Lecture 14. Rasterization. Scan Conversion Antialiasing [Angel Ch. 6] Jernej Barbic University of Southern California

Lets assume each object has a defined colour. Hence our illumination model is looks unrealistic.

CS 4621 PPA3: Animation

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Computer Graphics

Fall CSCI 420: Computer Graphics. 7.1 Rasterization. Hao Li.

Incremental Form. Idea. More efficient if we look at d k, the value of the decision variable at x = k

Rasterization. Rasterization (scan conversion) Digital Differential Analyzer (DDA) Rasterizing a line. Digital Differential Analyzer (DDA)

Computer Graphics Geometry and Transform

Drawing Fast The Graphics Pipeline

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 24 Solid Modelling

CS 465 Program 5: Ray II

Using Flash Animation Basics

Rasterization. CS 4620 Lecture Kavita Bala w/ prior instructor Steve Marschner. Cornell CS4620 Fall 2015 Lecture 16

CS 4731: Computer Graphics Lecture 21: Raster Graphics: Drawing Lines. Emmanuel Agu

CS 498 VR. Lecture 18-4/4/18. go.illinois.edu/vrlect18

Shading Techniques Denbigh Starkey

Topic #1: Rasterization (Scan Conversion)

How to draw and create shapes

Graphics Hardware and Display Devices

Rasterization, or What is glbegin(gl_lines) really doing?

Rasterization: Geometric Primitives

EF432. Introduction to spagetti and meatballs

Surface shading: lights and rasterization. Computer Graphics CSE 167 Lecture 6

Real-Time Shadows. Last Time? Textures can Alias. Schedule. Questions? Quiz 1: Tuesday October 26 th, in class (1 week from today!

CS1114 Assignment 5, Part 1

Texture Mapping. Texture (images) lecture 16. Texture mapping Aliasing (and anti-aliasing) Adding texture improves realism.

CS 4731/543: Computer Graphics Lecture 7 (Part I): Raster Graphics: Polygons & Antialiasing. Emmanuel Agu

Shadows in the graphics pipeline

Hidden surface removal. Computer Graphics

(Refer Slide Time: 00:03:51)

Open GL Framework For A Computer Graphics Course

Cs602-computer graphics MCQS MIDTERM EXAMINATION SOLVED BY ~ LIBRIANSMINE ~

Adobe Flash CS3 Reference Flash CS3 Application Window

Rasterization. CS4620 Lecture 13

2D Graphics Primitives II. Additional issues in scan converting lines. 1)Endpoint order. Want algorithms to draw the same pixels for each line

4.5 VISIBLE SURFACE DETECTION METHODES

Lecture 2 October 31, 2005

Flash offers a way to simplify your work, using symbols. A symbol can be

Sliding and Rotating Objects. Appendix 1: Author s Notes

CS602 MCQ,s for midterm paper with reference solved by Shahid

CHAPTER 1 Graphics Systems and Models 3

Smoother Graphics Taking Control of Painting the Screen

CS 283: Assignment 1 Geometric Modeling and Mesh Simplification

Principles of Computer Graphics. Lecture 3 1

animation, and what interface elements the Flash editor contains to help you create and control your animation.

Graphics Pipeline 2D Geometric Transformations

Graphic Design & Digital Photography. Photoshop Basics: Working With Selection.

Drawing Fast The Graphics Pipeline

Lecture 6 of 41. Scan Conversion 1 of 2: Midpoint Algorithm for Lines and Ellipses

Lecture 6 of 41. Scan Conversion 1 of 2: Midpoint Algorithm for Lines and Ellipses

CSC 418/2504 Computer Graphics, Winter 2012 Assignment 1 (10% of course grade)

POWERVR MBX. Technology Overview

CS 130 Final. Fall 2015

CS 4620 Program 4: Ray II

Rasterizing triangles

The graphics pipeline. Pipeline and Rasterization. Primitives. Pipeline

3D Rendering Pipeline (for direct illumination)

Computer Graphics (CS 543) Lecture 10: Rasterization and Antialiasing

Transcription:

CS 248 Assignment 2 Polygon Scan Converter CS248 Presented by Abe Davis Stanford University October 17, 2008

Announcements First thing: read README.animgui. It should tell you everything you need to know about the GUI. Post questions first to the newsgroup (su.class.cs248) and check there for answers to common questions.

Getting Started Read the project handout carefully! http://graphics.stanford.edu/courses/cs248-08/proj2.html Look at the code README.files talks about what different source files do, and where to find examples. Ignore the part about testing on the myth machines we will test using the VM. README.animgui explains what to do once the program is running. How to create polygons, load/save object files, and create animations (we ll go over most of this today too).

Development The interface is built using a cross platform library called GLUI. You won t need to change the interface unless you add features (extra credit). In that case, see the GLUI manual in assignments/assignment2/docs. You can develop and test this program on Windows or Mac, just make sure it works on the VM! When we give you the sample images, don t worry about matching them exactly. Use the images to get an idea of correct behavior.

The Interface (The interface is described in detail in README.animgui) A few key points: (Shift + Left click) : add vertices. (Left click) : completes the polygon you re editing, or allows you to select and drag vertices. (Right click) : drag the whole polygon The program we give you already handles all the editing functionality, you just need to work on the rendering. When you re ready to see the scene, hit the Render button.

Scan Conversion (Rasterization) The Algorithm (page 98 in Computer Graphics FvDFH second ed.) Create an Edge Table for the polygon being rendered, sorted on y. Don t include horizontal edges, they are handled by the edges they connect to (see page 95 in text). Note: xmin is the x at the minimum y for the edge, not necessarily the minimum x of the edge. Hence xmin = 7 for edge AB. (FvDFH, pages 92, 98)

Scan Conversion (cont.) Once you have your Edge Table (ET) for the polygon, you re ready to step through y coordinates and render scan lines: 1. Set y to the first non-empty bucket in the ET. This is bucket 1 in the example. 2. Initialize the Active Edge Table (AET) to be empty. The AET keeps track of which edges cross the current y scan line. 3. Repeat the following until the AET and ET are empty: 3.1 Add to the AET the ET entries for the current y. (edges AB, BC in example) 3.2 Remove from the AET entries where y = ymax. (none at first in example) Then sort the AET on x. (order: {AB, BC}) 3.3 Fill in pixel values on the y scan line using the x coordinates from the AET. Be wary of parity use the even/odd test to determine whether to fill (see next slide). 3.4 Increment y by 1 (to the next scan line). 3.5 For every non-vertical edge in the AET update x for the new y (calculate the next intersection of the edge with the scan line). Note: the algorithm in the book (presented here and in course lecture notes) attempts to fix the problems that occur when polygons share an edge, by not rasterizing the top-most row of pixels along an edge.

Active Edge Table Example Example of an AET containing edges {FA, EF, DE, CD} on scan line 8: 3.1: (y = 8) Get edges from ET bucket y (none in this case, y = 8 has no entry) 3.2: Remove from the AET any entries where ymax = y (none here) 3.3: Draw scan line. To handle multiple edges, group in pairs: {FA,EF}, {DE,CD} 3.4: y = y+1 (y = 8+1 = 9) 3.5: Update x for non-vertical edges, as in simple line drawing. Y val Current X Slope (FvDFH pages 92, 99)

Active Edge Table Example (cont.) 3.1: (y = 9) Get edges from ET bucket y (none in this case, y = 9 has no entry in ET) Scan line 9 shown in fig 3.28 below 3.2: Remove from the AET any entries with ymax = y (remove FA, EF) 3.3: Draw scan line between {DE, CD} 3.4: y = y+1 = 10 3.5: Update x in {DE, CD} 3.1: (y = 10) (Scan line 10 shown in fig 3.28 below) And so on Y val Current X Slope (FvDFH pages 92, 99)

Test Images Some cases you should test: (vertices added for illustration) Self-intersecting polygons, to test parity. Horizontal and Vertical edges. Edges that cross.

Antialiasing Scan conversion with super-sampling. How can we achieve this? Two possibilities: 1. Scan convert once to a super-sampled grid, then average down. Cost: 1 scan conversion s 2 x p 2 storage, where there are (s x s) samples per pixel, (p x p) image s 2 x p 2 pixel writes 2. Perform many normal scan conversions at super-sampled locations, and additively combine them. You will implement this method using an accumulation buffer. Cost: s 2 scan conversions 2p 2 storage (not exactly for this assignment) s 2 x p 2 pixel writes (demo: overheads)

Motion Blur Your goal is to reduce temporal aliasing, NOT to produce an artistic effect. Accomplished by interpolating between keyframes, meaning you define certain positions at certain times, and for times in between you calculate the position and direction of motion. Multiple images at different sample times are blurred (using the accumulation buffer), creating the illusion of motion.

Accumulation Buffer Algorithm Allows us to successively render multiple scenes and have them additively blend as we go. Each image ends up with an equal weighting of 1/n, where n is the number of samples taken. (Appendix A in project 2 handout) Let "canvas" be a 16x3=48-bit pixel array, temp be a 8x3=24-bit pixel array, and polygon color be a 8x3=24-bit color value. 1 clear canvas to black; 2 n = 0 (number of samples taken so far) 3 for (i=1; i<=s; i++) (for s subpixel positions) 4 for (j=1; j<=t; j++) (for t fractional frame times) 5 clear temp to black 6 n = n + 1 7 for each polygon 8 translate vertices for this subpixel position and fractional frame time 9 for each pixel in polygon (using your scan converter) 10 temp color <-- polygon color 11 for each pixel in canvas 12 canvas color <-- canvas color + temp color 13 canvas color <-- canvas color / n 14 convert canvas to 8x3 bits and display on screen (by exiting from your rasterizer)

Accumulation Buffer (cont.) Example (with overlap):

Accumulation Buffer (cont.) Question: Why should we render all polygons at once per frame (lines 7-10), why not antialias the objects separately and then blend their images together? Answer: Polygons on a perfect mesh over a colored background will show some of the background color. Rendering the polygons together prevents any unwanted blending.

Rasterization Notes Question: Which pixels do we paint in edge cases? Follow this general rule: If a sample lies within the ideal polygon, paint it. If a sample lies outside the ideal polygon, don t paint it. If a sample lies exactly on an edge/vertex, your choice. This can result in gaps, which is a form of aliasing. Don t fix it! Antialiasing will fill in the gap Slivers:

Floating Point Issues Discussed in FvD 19.2.3 The book presents 2 different schemes: Multiply to get rid of floating points, but by how much? Store and calculate in floating point. Slower, but recommended. The edge table algorithm already uses floating points when calculating slopes and adjusting edge x values. Our rasterizer allows floating point vertices. Generally, the algorithm doesn t change, but: The edge table still has integer buckets, so you must round to find the correct bucket, and adjust x min as appropriate.

Floating Point Issues (cont.) Helpful Hint: Work through the edge table algorithm on a piece of lined paper, with each line representing a horizontal scan line. Try various rounding strategies, and see which gives the correct results.

Extra Credit (Extra Credit is fun!!!) 1. Extend the interface to allow interactive scaling and rotations of polygons around a chosen point. Using matrices is one way 2. Extend the interface to allow insertion and deletion of vertices in an already-defined polygon. Not hard mathematically, but think of usability as well. 3. Allow the number of vertices in a polygon to be different at any keyframe. Example: square to house.

Extra Credit (cont.) 4. Extend the interface to allow the input of polygons with curved boundaries. Curve is approximated by lots of closely spaced vertices that are still linearly connected. Not too tough, add vertices along mouse path while mouse button is down. 5. Combine #3 and #4 to allow different curved boundaries for each keyframe. Calculate approximate locations for vertices when the number changes. For example, going from a curve with 10 vertices to one with 4, calculate points along the 4-vertex curve at 1/10 intervals. Or come up with a better scheme. 6. Replace linear interpolation with splined interpolation to create smoother transitions between keyframes. Refer to section 21.1.3 in text for more info. Consider cubic B-splines (section 11.2.3).

Extra Credit (cont.) 7. Implement polygon clipping. Scissoring means not sending pixel values to the canvas when they would be out of bounds (this is the required functionality). Full clipping means trimming the edge of the polygon so it fits within the screen, which can greatly reduce the time spent performing rasterization. scissoring clipping

Extra Credit (cont.) 8. Implement unweighted area sampling (section 3.17.2 and earlier slide) as a user selectable alternative to accumulation buffer antialiasing (you must still implement accumulation buffer). For even more fun, implement weighted area sampling (section 3.17.3). 9. Create a cool animation and show it at the demo! Highly recommended!

Development Tips Your canvas has (0,0) at the top left, with (canvaswidth-1, canvasheight-1) at bottom right. Examples in book have (0,0) at bottom left. Doesn t change too much, just be aware. If you are comfortable using them, you might find the C++ standard templates useful (especially sorted lists) for handling lists in your edge table. Alternatively, you might want to write your own class or functions to handle this. You only need to implement the Rasterize function in objects.cpp, unless you re doing extra credit.

Questions?