Computer Graphics: 7-Polygon Rasterization, Clipping

Similar documents
Computer Graphics: 8-Hidden Surface Removal

Computer Graphics: 6-Rasterization

Clipping Lines. Dr. Scott Schaefer

Computer Graphics (CS 543) Lecture 9 (Part 2): Clipping. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Clipping & Culling. Lecture 11 Spring Trivial Rejection Outcode Clipping Plane-at-a-time Clipping Backface Culling

Examples. Clipping. The Rendering Pipeline. View Frustum. Normalization. How it is done. Types of operations. Removing what is not seen on the screen

CS123 INTRODUCTION TO COMPUTER GRAPHICS. Clipping. Concepts, Algorithms for line clipping. 1 of 16. Andries van Dam. Clipping - 10/12/17

Computer Graphics: 3-Local Illumination Models

From Vertices To Fragments-1

Computer Graphics Geometry and Transform

Clipping and Scan Conversion

3D Rendering Pipeline (for direct illumination)

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

Clipping Points Consider a clip window which is rectangular in shape. P(x, y) is a point to be displayed.

The Traditional Graphics Pipeline

521493S Computer Graphics Exercise 1 (Chapters 1-3)

The Traditional Graphics Pipeline

2D Image Synthesis. 2D image synthesis. Raster graphics systems. Modeling transformation. Vectorization. u x u y 0. o x o y 1

Computer Graphics. - Clipping - Philipp Slusallek & Stefan Lemme

The Traditional Graphics Pipeline

Realtime 3D Computer Graphics Virtual Reality

Computer Graphics Geometry and Transform

Lesson 8 - Practice Problems

Algorithms and Data Structures

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

Overview. Pipeline implementation I. Overview. Required Tasks. Preliminaries Clipping. Hidden Surface removal

(a) rotating 45 0 about the origin and then translating in the direction of vector I by 4 units and (b) translating and then rotation.

Sung-Eui Yoon ( 윤성의 )

Write C++/Java program to draw line using DDA and Bresenham s algorithm. Inherit pixel class and Use function overloading.

Computer Graphics: 5-The Graphics Pipeline

CS184 : Foundations of Computer Graphics Professor David Forsyth Final Examination

RASTERIZING POLYGONS IN IMAGE SPACE

Part IV. 2D Clipping

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

CMSC 435/634: Introduction to Graphics

What is Clipping? Why do we Clip? Lecture 9 Comp 236 Spring Clipping is an important optimization

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

CS184 : Foundations of Computer Graphics Professor David Forsyth Final Examination (Total: 100 marks)

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

Foundations of Math II

Werner Purgathofer

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Topics. From vertices to fragments

Viewing Transformation. Clipping. 2-D Viewing Transformation

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

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

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

CSE328 Fundamentals of Computer Graphics

Clipping. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

(Refer Slide Time 03:00)

2D Viewing. Viewing Pipeline: Window-Viewport Transf.

Clipping Algorithms; 8-5. Computer Graphics. Spring CS4815

Rasterization. MIT EECS Frédo Durand and Barb Cutler. MIT EECS 6.837, Cutler and Durand 1

CS452/552; EE465/505. Clipping & Scan Conversion

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

Chapter. Graph Solve. 9-1 Before Using Graph Solve 9-2 Analyzing a Function Graph 9-3 Graph Solve Precautions

2.3. Graphing Calculators; Solving Equations and Inequalities Graphically

Two-Dimensional Viewing. Chapter 6

CS602 Midterm Subjective Solved with Reference By WELL WISHER (Aqua Leo)

VISIBILITY & CULLING. Don t draw what you can t see. Thomas Larsson, Afshin Ameri DVA338, Spring 2018, MDH

CSCI 4620/8626. Computer Graphics Clipping Algorithms (Chapter 8-5 )

Computer Graphics Viewing Objective

UNIT -8 IMPLEMENTATION

+ b. From this we can derive the following equations:

Windowing And Clipping (14 Marks)

MATH SPEAK - TO BE UNDERSTOOD AND MEMORIZED DETERMINING THE INTERSECTIONS USING THE GRAPHING CALCULATOR

Computer Graphics. Bing-Yu Chen National Taiwan University The University of Tokyo

(Refer Slide Time: 00:02:00)

Institutionen för systemteknik

POLYGON FILLING ALGORITHM

Transformation Pipeline

Binghamton University. EngiNet. Thomas J. Watson. School of Engineering and Applied Science. Computer Graphics. State University of New York.

FUNCTIONS AND MODELS

U.C. Berkeley, EECS, Computer Science TAKE HOME EXAM. Your Class Computer Account: DO NOT OPEN THIS INSIDE SODA HALL -- WAIT UNTIL YOU ARE ALONE!

Topic #1: Rasterization (Scan Conversion)

INFOGR Computer Graphics. J. Bikker - April-July Lecture 11: Visibility. Welcome!

Computer Graphics II

CMSC 435 Introductory Computer Graphics Pipeline. Announcements

Chpt 1. Functions and Graphs. 1.1 Graphs and Graphing Utilities 1 /19

Visible Surface Detection Methods

CS602- Computer Graphics Solved MCQS From Midterm Papers. MIDTERM EXAMINATION Spring 2013 CS602- Computer Graphics

Identifying those parts of a scene that are visible from a chosen viewing position, and only process (scan convert) those parts

Points and lines. x x 1 + y 1. y = mx + b

Triangle Rasterization

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

Scan Conversion of Polygons. Dr. Scott Schaefer

Computer Graphics. Bing-Yu Chen National Taiwan University

Box It Up (A Graphical Look)

Computational Geometry [csci 3250]

An angle that has a measure less than a right angle.

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

Module 5: Creating Sheet Metal Transition Piece Between a Square Tube and a Rectangular Tube with Triangulation

Part 3: 2D Transformation

From Vertices to Fragments: Rasterization. Reading Assignment: Chapter 7. Special memory where pixel colors are stored.

(Refer Slide Time 05:03 min)

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

Section 1.6. Inverse Functions

Lesson 4 Exponential Functions I

(Refer Slide Time: 00:02:02)

Transcription:

Computer Graphics: 7-Polygon Rasterization, Clipping Prof. Dr. Charles A. Wüthrich, Fakultät Medien, Medieninformatik Bauhaus-Universität Weimar caw AT medien.uni-weimar.de

Filling polygons (and drawing them) In general, except if we are dealing with wireframes, we would want to draw a filled polygon on our screen. The advantage is clear: the polygon acquires thickness and can be use to render surfaces The simplest way one would do that is to draw the polygon border and then fill the region delimited by the polygon In fact, this is the start point for the real algorithm, the scanline algorithm The scanline algorithm combines the advantages of filling algorithms and of line tracing at the borders in a complex but very fast way As input one takes an ordered list of points representing the polygon

Scanline algorithm The basic idea is very simple: A polygon can be filled one scanline at a time, from top to bottom Order therefore polygon corners according to their highest y coordinate Order each horizonal line according to the x coordinate of the edge intersections Fill between pairs of edges, stop drawing until the next edge, and then restart filling again till the next one once finished the edges at current line, restart at next y value Of course, one can also draw upwards

Scanline algorithm Notice that the number of edges remains constant between starting and ending points in the horizontal bands. Notice also that segments have only a limited contiguous range where they are active Notice that while proceeding downwards, borders can use a mirrored DDA to be drawn In this way, one can draw line borders and fill between them, after having ordered the border intersections with the current line WRT current coordinate

Scanline algorithm Polygon drawing starts at the bottom. Out of the edges list the ones with lowest starting point are chosen. These will remain part of the active edge list until their end is met When they end, they are removed and replaced by new starting edges This until there is no edge left among the active edge At each value of the y variable, the edge rasterization is computed, and edges are ordered by growing x Colour is then filled between sorted pairs of edge rasterizations.

Triangle rasterization Modern graphics cards accept only triangles at the rasterization step Polygons with more edges are simply triangularized Obviously, the rasterization of a triangle is much easier This because a triangle is convex, and therefore a horizontal line has just the left and the right hand borders Filling is then done between the left side and the right side

Clipping: motivation Often in 2D we have drawings that are bigger than a screen To save drawing complexity, it is good to be able to cut the drawings so that only screen objects are drawn Also, one needs to protect other (invisible) regions while working on a complex drawing The question is how is this done Problem: Given a segment in the plane, clip it to a rectangular segment

Line clipping Let B be the screen, and let be the endpoints of the segment to be drawn There are four possible cases available: d a) Whole line is visible", B b) Line is partially visible" B, B, intersects screen borders c) Line partially visible", B, but intersects screen borders d) Line not visible", B b a c

Line clipping Algorithm IF (, B) /* a */ DrawLine(, ) ELSE IF /* b */ ((( B)AND NOT( B)) OR (( B)AND NOT( B))) compute I=( borders) IF( ÎB) Drawline(I, ) ELSE DrawLine(I, ) ELSE /* c,d */ compute I 1,I 2 = ( borders) IF I 1,I 2 exist Drawline (I 1,I 2 ) d b a c END

Examples: Cohen-Sutherland algo. Code points according to characteristics: Bit 0=1 if x P <x min else 0 Bit 1=1 if x P >x max else 0 Bit 2=1 if y P <y min else 0 Bit 3=1 if y P >y max else 0 Use bitwise operations: code( ) AND code( )!= 0 trivial case, line not on screen code( ) OR code( ) == 0 trivial case, line on screen ELSE - compute line-borders intersection (one at time) and set their code as above - redo clipping with shortened line Note: before new intersection, at least one endpoint is outside WRT the border you clipped against, thus one subseg is trivially out (all left or right or up or down of screen) 1 2 3 code=1001 4 code=0001 code=1000 code=1010 code=0010 7 8 9 code=0101 5 code=0000 code=0100 6 code=0110

Algorithm Examples 1001 0001 0101 1000 1 P 4 2 3 4 P 3 5 6 Q 0000 2 R 2 Q R R 3 3 4 R 1 P 7 2 Q 1 8 9 0100 1010 0010 0110

Algorithm examples : =0001, =1000 AND = 0000 OR =1001 Subdivide against left, Pick, find P 4 new line P 4 P 4 : =1000, P 4 =1000 AND P 4 : 1000 outside! Draw nothing Q 1 Q 2 : Q 1 =0100, Q 2 =0000 Q 1 AND Q 2 :0000 Q 1 OR Q 2 : 0100 Subdivide, Pick Q 2, find Q 3 new line Q 2 Q 3 Q 2 Q 3 : Q 2 =0000, Q 3 =0000 Q 2 AND Q 3 : 0000 Q 1 OR Q 3 : 0000 inside! Draw Q 3 Q 2 Q 3 Q 2 : Q 3 =0100 ~ R 1 R 2 : R 1 =0100, R 2 =0010 R 1 AND R 2 = 0000 R 1 OR R 2 = 0110 Subdivide, Pick R 1, find R 4 new line R 1 R 4 R 1 =0100, R 4 =0000 R 1 AND R 4 = 0000 R 1 OR R 4 = 0100 Subdivide, Pick R 4, find R 3 new line R 3 R 4 R 3 =0000 R 4 =0000 R 3 AND R 4 =0000 draw R 3 R 4 1001 0001 0101 1000 1 P 4 2 3 4 P 3 5 6 Q 0000 2 R 2 Q R R 3 3 4 R 1 P 7 2 Q 1 8 9 0100 1010 0010 0110

Clipping polygons The task is similar, but it is more complicated to achieve Polygon clipping may result into disjunct polys xmin xmax xmin xmax ymax ymax ymin ymin

Sutherland Hodgeman Algorithm Clearly, drawing polygons is a more complicated issue Idea: one could follow the polygon border, and switch to following the border when the polygon leaves the screen until it re-enters it xmin xmax ymax This means creating a new polygon, which is trimmed to the ymin screen While following an edge, four cases are possible: 1 3 2 4

Sutherland-Hodgeman Algorithm The algorithm works considering polygons as lists of edges Input is a list L of polygon edges Output wil be a new list L of polygon edges The polygon is clipped against ALL screen borders one at a time 1 FOR all screen borders DO: FOR all lines in polygons DO: FOR all points P in L DO END END END Compute intersection I of line with current border IF (case 1): Do Nothing IF (case 2): Add (I,Succ(P))to L IF (case 3): Add (I) to L IF (case 4): Add (succ(p)) to L

Example xmin V 2 xmax V 1 I 1 V 3 V 5 I 2 V 4 ymin

Example Left border Input: {V 1,V 2,V 3,V 4,V 5 } Output: {I 1,V 2,V 3,V 4,Í 2 } Top Border Input: {I 1,V 2,V 3,V 4,I 2 } Output: {I 1,I 3,I 4,V 3,V 4,I 2 } xmin V 2 xmax xmin V 2 xmax V 1 I 1 V 1 I 1 I 3 I 4 V 3 V 3 V 5 I 2 V 4 ymin V 5 I 2 V 4 ymin

Clipping in 3D Remember the near and far clipping planes of the view frustum? How do I clip a polygon against them? Viewpoint

Clipping in 3D Remember the near and far clipping planes of the view frustum? How do I clip a polygon against them? As a matter of fact, it is not so different! The problem can be reduced to the same as in 2D, with a few differences Viewpoint

Clipping in 3D Let us consider a the far plane and a polygon Substitute the coordinates of the vertices of the triangle into the plane equation: Front: <0 Back: >0 Plane: =0 So we can follow the vertices exactly like in Cohen-Sutherland to clip against the plane A similar method can be applied for an arbitrary plane For the frustum planes one can do clipping one plane at a time, like in 2D (except they are 6 now) <0 >0

End +++ Ende - The end - Finis - Fin - Fine +++ Ende - The end - Finis - Fin - Fine +++