Clipping and Scan Conversion

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

Realtime 3D Computer Graphics Virtual Reality

Rasterization Computer Graphics I Lecture 14. Scan Conversion Antialiasing Compositing [Angel, Ch , ]

Topics. From vertices to fragments

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

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

3D Rendering Pipeline (for direct illumination)

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

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

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

COMP371 COMPUTER GRAPHICS

Chapter 8: Implementation- Clipping and Rasterization

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

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

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

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

Computer Graphics. - Clipping - Philipp Slusallek & Stefan Lemme

Two-Dimensional Viewing. Chapter 6

Computer Graphics Geometry and Transform

From Vertices To Fragments-1

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

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

The Traditional Graphics Pipeline

Computer Graphics. - Rasterization - Philipp Slusallek

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

The Traditional Graphics Pipeline

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Pipeline implementation II

Rasterization: Geometric Primitives

Implementation III. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

CHAPTER 1 Graphics Systems and Models 3

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

CSE328 Fundamentals of Computer Graphics

CS4620/5620: Lecture 14 Pipeline

Line Drawing. Foundations of Computer Graphics Torsten Möller

From Ver(ces to Fragments: Rasteriza(on

Line Drawing. Introduction to Computer Graphics Torsten Möller / Mike Phillips. Machiraju/Zhang/Möller

Computer Graphics I Lecture 11

The Traditional Graphics Pipeline

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

Topic #1: Rasterization (Scan Conversion)

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

EECE 478. Learning Objectives. Learning Objectives. Rasterization & Scenes. Rasterization. Compositing

Computer Graphics Geometry and Transform

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

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

UNIT -8 IMPLEMENTATION

Z- Buffer Store the depth for each pixel on the screen and compare stored value with depth of new pixel being drawn.

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

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Graphics System. Processor. Output Display. Input Devices. Frame Buffer. Memory. Array of pixels. Resolution: # of pixels Depth: # of bits/pixel

Lecture 7 of 41. Viewing 4 of 4: Culling and Clipping Lab 1b: Flash Intro

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Clipping Lines. Dr. Scott Schaefer

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

Rasterization, Depth Sorting and Culling

OpenGL Graphics System. 2D Graphics Primitives. Drawing 2D Graphics Primitives. 2D Graphics Primitives. Mathematical 2D Primitives.

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

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

Interactive Computer Graphics A TOP-DOWN APPROACH WITH SHADER-BASED OPENGL

QUESTION BANK 10CS65 : COMPUTER GRAPHICS AND VISUALIZATION

Rasterization Overview

Painter s HSR Algorithm

From 3D World to 2D Screen. Hendrik Speleers

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

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

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

Height Fields and Contours Scalar Fields Volume Rendering Vector Fields [Angel Ch. 12] April 23, 2002 Frank Pfenning Carnegie Mellon University

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

GLOBAL EDITION. Interactive Computer Graphics. A Top-Down Approach with WebGL SEVENTH EDITION. Edward Angel Dave Shreiner

Visualization Computer Graphics I Lecture 20

Scan Conversion. Drawing Lines Drawing Circles

Sung-Eui Yoon ( 윤성의 )

Einführung in Visual Computing

15. Clipping. Projection Transformation. Projection Matrix. Perspective Division

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

Computer Graphics. The Two-Dimensional Viewing. Somsak Walairacht, Computer Engineering, KMITL

Projection and viewing. Computer Graphics CSE 167 Lecture 4

UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4620/8626 Computer Graphics Spring 2014 Homework Set 1 Suggested Answers

Pipeline Operations. CS 4620 Lecture 10

Rasterization. COMP 575/770 Spring 2013

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

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

CS 543: Computer Graphics. Rasterization

Computer Graphics: 7-Polygon Rasterization, Clipping

Computer Graphics and GPGPU Programming

RASTERISED RENDERING

CS184 : Foundations of Computer Graphics Professor David Forsyth Final Examination

Game Architecture. 2/19/16: Rasterization

Chapter 4-3D Camera & Optimizations, Rasterization

Curves and Surfaces Computer Graphics I Lecture 9

Institutionen för systemteknik

Drawing Fast The Graphics Pipeline

Course Title: Computer Graphics Course no: CSC209

Models and The Viewing Pipeline. Jian Huang CS456

CSE 167: Lecture #5: Rasterization. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

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

SRM INSTITUTE OF SCIENCE AND TECHNOLOGY

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11

CS 130 Final. Fall 2015

Transcription:

15-462 Computer Graphics I Lecture 14 Clipping and Scan Conversion Line Clipping Polygon Clipping Clipping in Three Dimensions Scan Conversion (Rasterization) [Angel 7.3-7.6, 7.8-7.9] March 19, 2002 Frank Pfenning Carnegie Mellon University http://www.cs.cmu.edu/~fp/courses/graphics/

The Graphics Pipeline, Revisited Must eliminate objects outside viewing frustum Tied in with projections Clipping: object space (eye coordinates) Scissoring: image space (pixels in frame buffer) Introduce clipping in stages 2D (for simplicity) 3D (as in OpenGL) In a later lecture: scissoring 03/19/2002 15-462 Graphics I 2

Transformations and Projections Sequence applied in many implementations 1. Object coordinates to 2. Eye coordinates to 3. Clip coordinates to 4. Normalized device coordinates to 5. Screen coordinates 03/19/2002 15-462 Graphics I 3

Clipping Against a Frustum General case of frustum (truncated pyramid) y x clipped line z image plane near far Clipping is tricky because of frustum shape 03/19/2002 15-462 Graphics I 4

Perspective Normalization Solution: Implement perspective projection by perspective normalization and orthographic projection Perspective normalization is a homogeneous tfm. y x clipped line 1 y 1 x clipped line z near 0 1 z far image plane near far See [Angel Ch. 5.8] 03/19/2002 15-462 Graphics I 5

The Normalized Frustum OpenGL uses -1 x,y,z 1 (others possible) Clip against resulting cube Clipping against programmer-specified planes is different and more expensive Often a useful programming device 03/19/2002 15-462 Graphics I 6

The Viewport Transformation Transformation sequence again: 1. Camera: From object coordinates to eye coords 2. Perspective normalization: to clip coordinates 3. Clipping 4. Perspective division: to normalized device coords. 5. Orthographic projection (setting z p = 0) 6. Viewport transformation: to screen coordinates Viewport transformation can distort Often in OpenGL: resize callback 03/19/2002 15-462 Graphics I 7

Line-Segment Clipping General: 3D object against cube Simpler case: In 2D: line against square or rectangle Before scan conversion (rasterization) Later: polygon clipping Several practical algorithms Avoid expensive line-rectangle intersections Cohen-Sutherland Clipping Liang-Barsky Clipping Many more [see Foley et al.] 03/19/2002 15-462 Graphics I 8

Clipping Against Rectangle Line-segment clipping: modify endpoints of lines to lie within clipping rectangle Could calculate intersections of line (segments) with clipping rectangle (expensive) 03/19/2002 15-462 Graphics I 9

Cohen-Sutherland Clipping Clipping rectangle as intersection of 4 halfplanes ymax interior = y < ymax y > ymin ymin xmin xmax x > xmin x < xmax Encode results of four half-plane tests Generalizes to 3 dimensions (6 half-planes) 03/19/2002 15-462 Graphics I 10

Outcodes Divide space into 9 regions 4-bit outcode determined by comparisons ymax 1001 0001 1000 0000 1010 0010 b o : y > y max b 1 : y < y min b 2 : x > x max b 3 : x < x min ymin 0101 0100 0110 xmin xmax o 1 = outcode(x 1,y 1 ) and o 2 = outcode(x 2,y 2 ) 03/19/2002 15-462 Graphics I 11

Cases for Outcodes Outcomes: accept, reject, subdivide 1001 1000 1010 ymax 0001 ymin 0000 0010 o 1 = o 2 = 0000: accept o 1 & o 2 0000: reject o 1 = 0000, o 2 0000: subdiv o 1 0000, o 2 = 0000: subdiv o 1 & o 2 = 0000: subdiv 0101 0100 0110 xmin xmax 03/19/2002 15-462 Graphics I 12

Cohen-Sutherland Subdivision Pick outside endpoint (o 0000) Pick a crossed edge (o = b 0 b 1 b 2 b 3 and b k 0) Compute intersection of this line and this edge Replace endpoint with intersection point Restart with new line segment Outcodes of second point are unchanged Must converge (roundoff errors?) 03/19/2002 15-462 Graphics I 13

Liang-Barsky Clipping Starting point is parametric form Compute four intersections with extended clipping rectangle Will see that this can be avoided 03/19/2002 15-462 Graphics I 14

Ordering of intersection points Order the intersection points Figure (a): 1 > α 4 > α 3 > α 2 > α 1 > 0 Figure (b): 1 > α 4 > α 2 > α 3 > α 1 > 0 03/19/2002 15-462 Graphics I 15

Liang-Barsky Efficiency Improvements Efficiency improvement 1: Compute intersections one by one Often can reject before all four are computed Efficiency improvement 2: Equations for α 3, α 2 Compare α 3, α 2 without floating-point division 03/19/2002 15-462 Graphics I 16

Line-Segment Clipping Assessment Cohen-Sutherland Works well if many lines can be rejected early Recursive structure (multiple subdiv) a drawback Liang-Barsky Avoids recursive calls (multiple subdiv) Many cases to consider (tedious, but not expensive) Used more often in practice (?) 03/19/2002 15-462 Graphics I 17

Outline Line-Segment Clipping Cohen-Sutherland Liang-Barsky Polygon Clipping Sutherland-Hodgeman Clipping in Three Dimensions Scan Conversion DDA algorithm Bresenham s algorithm 03/19/2002 15-462 Graphics I 18

Polygon Clipping Convert a polygon into one ore more polygons Their union is intersection with clip window Alternatively, we can first tesselate concave polygons (OpenGL supported) 03/19/2002 15-462 Graphics I 19

Concave Polygons Approach 1: clip and join to a single polygon Approach 2: tesselate and clip triangles 03/19/2002 15-462 Graphics I 20

Sutherland-Hodgeman I Subproblem: Input: polygon (vertex list) and single clip plane Output: new (clipped) polygon (vertex list) Apply once for each clip plane 4 in two dimensions 6 in three dimension Can arrange in pipeline 03/19/2002 15-462 Graphics I 21

Sutherland-Hodgeman II To clip vertex list (polygon) against half-plane: Test first vertex. Output if inside, otherwise skip. Then loop through list, testing transitions In-to-in: output vertex In-to-out: output intersection out-to-in: output intersection and vertex out-to-out: no output Will output clipped polygon as vertex list May need some cleanup in concave case Can combine with Liang-Barsky idea 03/19/2002 15-462 Graphics I 22

Other Cases and Optimizations Curves and surfaces Analytically if possible Through approximating lines and polygons otherwise Bounding boxes Easy to calculate and maintain Sometimes big savings 03/19/2002 15-462 Graphics I 23

Outline Line-Segment Clipping Cohen-Sutherland Liang-Barsky Polygon Clipping Sutherland-Hodgeman Clipping in Three Dimensions Scan Conversion DDA algorithm Bresenham s algorithm 03/19/2002 15-462 Graphics I 24

Clipping Against Cube Derived from earlier algorithms Can allow right parallelepiped 03/19/2002 15-462 Graphics I 25

Cohen-Sutherland in 3D Use 6 bits in outcode b 4 : z > z max b 5 : z < z min Other calculations as before 03/19/2002 15-462 Graphics I 26

Liang-Barsky in 3D Add equation z(α) = (1- α) z 1 + α z 2 Solve, for p 0 in plane and normal n: Yields Optimizations as for Liang-Barsky in 2D 03/19/2002 15-462 Graphics I 27

Perspective Normalization Intersection simplifies for orthographic viewing One division only (no multiplication) Other Liang-Barsky optimizations also apply Otherwise, use perspective normalization Reduces to orthographic case Applies to oblique and perspective viewing Normalization of oblique projections 03/19/2002 15-462 Graphics I 28

Summary: Clipping Clipping line segments to rectangle or cube Avoid expensive multiplications and divisions Cohen-Sutherland or Liang-Barsky Clipping to viewing frustum Perspective normalization to orthographic projection Apply clipping to cube from above Client-specific clipping Use more general, more expensive form Polygon clipping Sutherland-Hodgeman pipeline 03/19/2002 15-462 Graphics I 29

Outline Line-Segment Clipping Cohen-Sutherland Liang-Barsky Polygon Clipping Sutherland-Hodgeman Clipping in Three Dimensions Scan Conversion DDA algorithm Bresenham s algorithm 03/19/2002 15-462 Graphics I 30

Rasterization Final step in pipeline: rasterization (scan conv.) From screen coordinates (float) to pixels (int) Writing pixels into frame buffer Separate z-buffer, display, shading, blending Concentrate on primitives: Lines Polygons (Thursday) 03/19/2002 15-462 Graphics I 31

DDA Algorithm DDA ( Digital Differential Analyzer ) Represent Assume 0 m 1 Exploit symmetry Distinguish special cases 03/19/2002 15-462 Graphics I 32

DDA Loop Assume write_pixel(int x, int y, int value) For (ix = x1; ix <= x2; ix++) { y += m; write_pixel(ix, round(y), color); } Slope restriction needed Easy to interpolate colors 03/19/2002 15-462 Graphics I 33

Bresenham s Algorithm I Eliminate floating point addition from DDA Assume again 0 m 1 Assume pixel centers halfway between ints 03/19/2002 15-462 Graphics I 34

Bresenham s Algorithm II Decision variable a b If a b > 0 choose lower pixel If a b 0 choose higher pixel Goal: avoid explicit computation of a b Step 1: re-scale d = (x 2 x 1 )(a b) = x(a b) d is always integer 03/19/2002 15-462 Graphics I 35

Bresenham s Algorithm III Compute d at step k +1 from d at step k! Case: j did not change (d k > 0) a decreases by m, b increases by m (a b) decreases by 2m = 2( y/ x) x(a-b) decreases by 2 y 03/19/2002 15-462 Graphics I 36

Bresenham s Algorithm IV Case: j did change (d k 0) a decreases by m-1, b increases by m-1 (a b) decreases by 2m 2 = 2( y/ x 1) x(a-b) decreases by 2( y - x) 03/19/2002 15-462 Graphics I 37

Bresenham s Algorithm V So d k+1 = d k 2 y if d k > 0 And d k+1 = d k 2( y x) if d k 0 Final (efficient) implementation: void draw_line(int x1, int y1, int x2, int y2) { int x, y = y0; int dx = 2*(x2-x1), dy = 2*(y2-y1); int dydx = dy-dx, D = (dy-dx)/2; } for (x = x1 ; x <= x2 ; x++) { write_pixel(x, y, color); if (D > 0) D -= dy; else {y++; D -= dydx;} } 03/19/2002 15-462 Graphics I 38

Bresenham s Algorithm VI Need different cases to handle other m Highly efficient Easy to implement in hardware and software Widely used 03/19/2002 15-462 Graphics I 39

Summary Line-Segment Clipping Cohen-Sutherland Liang-Barsky Polygon Clipping Sutherland-Hodgeman Clipping in Three Dimensions Scan Conversion DDA algorithm Bresenham s algorithm 03/19/2002 15-462 Graphics I 40

Preview Scan conversion of polygons Anti-aliasing Other pixel-level operations Assignment 5 due Thursday Assignment 6 (written) out Thursday 03/19/2002 15-462 Graphics I 41