Computer Graphics. - Clipping - Philipp Slusallek & Stefan Lemme

Similar documents
Two-Dimensional Viewing. Chapter 6

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

From Vertices To Fragments-1

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

Clipping and Scan Conversion

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

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

Sung-Eui Yoon ( 윤성의 )

3D Rendering Pipeline (for direct illumination)

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

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

Realtime 3D Computer Graphics Virtual Reality

Topics. From vertices to fragments

Part IV. 2D Clipping

CS4620/5620: Lecture 14 Pipeline

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

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

MIT EECS 6.837, Teller and Durand 1

The Graphics Pipeline. Interactive Computer Graphics. The Graphics Pipeline. The Graphics Pipeline. The Graphics Pipeline: Clipping

Chapter 8: Implementation- Clipping and Rasterization

Clipping and Intersection

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

Hidden Surfaces II. Week 9, Mon Mar 15

COMP3421. Vector geometry, Clipping

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

Motivation. Culling Don t draw what you can t see! What can t we see? Low-level Culling

CS184 : Foundations of Computer Graphics Professor David Forsyth Final Examination

Efficient Clipping of Arbitrary Polygons

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

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)

Clipping Lines. Dr. Scott Schaefer

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

Computer Graphics. - Rasterization - Philipp Slusallek

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

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

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

CHAPTER 1 Graphics Systems and Models 3

S U N G - E U I YO O N, K A I S T R E N D E R I N G F R E E LY A VA I L A B L E O N T H E I N T E R N E T

Computer Graphics Geometry and Transform

Culling. Computer Graphics CSE 167 Lecture 12

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

Today. CS-184: Computer Graphics. Lecture #10: Clipping and Hidden Surfaces. Clipping. Hidden Surface Removal

3D Polygon Rendering. Many applications use rendering of 3D polygons with direct illumination

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

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

CSE 167: Introduction to Computer Graphics Lecture #4: Vertex Transformation

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

Computer Graphics: 7-Polygon Rasterization, Clipping

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

COMPUTATIONAL GEOMETRY

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI

Rasterization Overview

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

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

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Page 1. Area-Subdivision Algorithms z-buffer Algorithm List Priority Algorithms BSP (Binary Space Partitioning Tree) Scan-line Algorithms

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

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

Aptitude Test Question

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

UNIT 2. Translation/ Scaling/ Rotation. Unit-02/Lecture-01

QUESTION BANK 10CS65 : COMPUTER GRAPHICS AND VISUALIZATION

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

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Hidden surface removal. Computer Graphics

Computer Graphics (CS 543) Lecture 10 (Part 1): 3D Clipping. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Set the Viewport. Set the Viewport Clipping. Set the Viewport. Set the Viewport. Set the Viewport. Resizing the Viewport W = H

COMPUTER GRAPHICS, MULTIMEDIA AND ANIMATION, Second Edition (with CD-ROM) Malay K. Pakhira

CS 112 The Rendering Pipeline. Slide 1

Real-Time Graphics Architecture

CSE528 Computer Graphics: Theory, Algorithms, and Applications

CS 325 Computer Graphics

Computer Graphics Geometry and Transform

CSE328 Fundamentals of Computer Graphics

CHETTINAD COLLEGE OF ENGINEERING & TECHNOLOGY CS2401 COMPUTER GRAPHICS QUESTION BANK

(Refer Slide Time: 00:02:02)

SRM INSTITUTE OF SCIENCE AND TECHNOLOGY

Pipeline Operations. CS 4620 Lecture 10

CS 130 Final. Fall 2015

Hidden Surface Removal

Practical Linear Algebra: A Geometry Toolbox

End-Term Examination

SAZ4C COMPUTER GRAPHICS. Unit : 1-5. SAZ4C Computer Graphics

CSE328 Fundamentals of Computer Graphics: Concepts, Theory, Algorithms, and Applications

CS2401 COMPUTER GRAPHICS ANNA UNIV QUESTION BANK

Triangle Rasterization

CSE 167: Introduction to Computer Graphics Lecture #5: Projection. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2017

Lahore University of Management Sciences. CS 452 Computer Graphics

CS 450: COMPUTER GRAPHICS REVIEW: CLIPPING SPRING 2015 DR. MICHAEL J. REALE

Windowing And Clipping (14 Marks)

3D Viewing. CS 4620 Lecture 8

Viewing Transformation. Clipping. 2-D Viewing Transformation

Lecture 25 of 41. Spatial Sorting: Binary Space Partitioning Quadtrees & Octrees

CMSC427 Transformations II: Viewing. Credit: some slides from Dr. Zwicker

Perspective Mappings. Contents

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

Direct Rendering of Trimmed NURBS Surfaces

Today. Rendering pipeline. Rendering pipeline. Object vs. Image order. Rendering engine Rendering engine (jtrt) Computergrafik. Rendering pipeline

CS 130 Exam I. Fall 2015

Transcription:

Computer Graphics - Clipping - Philipp Slusallek & Stefan Lemme

Clipping Motivation Projected primitive might fall (partially) outside of the visible display window E.g. if standing inside a building Eliminate non-visible geometry early in the pipeline to process visible parts only Happens after transformation from 3D to 2D Must cut off parts outside the window Cannot draw outside of window (e.g. plotter) Outside geometry might not be representable (e.g. in fixed point) Must maintain information properly Drawing the clipped geometry should give the correct results: e.g. correct interpolation of colors at triangle vertices when one is clipped Type of geometry might change Cutting off a vertex of a triangle produces a quadrilateral Might need to be split into triangle again Polygons must remain closed after clipping

Line Clipping Definition of clipping Cut off parts of objects which lie outside/inside of a defined region Often clip against viewport (2D) or canonical view-volume (3D) Let`s focus first on lines only p e p b

Brute-Force Method Brute-force line clipping at the viewport If both end points p b and p e are inside viewport Accept the whole line Otherwise, clip the line at each edge p intersection = p b + t line p e p b = e b + t edge (e e e b ) Solve for t line and t edge Intersection within segment if both 0 t line, tedge 1 Replace suitable end points for the line by the intersection point e e p e p b e b

Cohen-Sutherland (1974) Advantage: divide and conquer Efficient trivial accept and trivial reject Non-trivial case: divide and test Outcodes of points Bit encoding (outcode, OC) Each viewport edge defines a half space Set bit if vertex is outside w.r.t. that edge 1001 0001 0101 1000 1010 0000 0100 Trivial cases Trivial accept: both are in viewport (OC(p b ) OR OC(p e )) == 0 Trivial reject: both lie outside w.r.t. at least one common edge (OC(p b ) AND OC(p e )) 0 Line has to be clipped to all edges where XOR bits are set, i.e. the points lies on different sides of that edge OC(p b ) XOR OC(p e ) 0010 0110 Bit order: top, bottom, right, left Viewport (x min, y min, x max, y max )

Cohen-Sutherland Clipping of line (p1, p2) oc1 = OC(p1); oc2 = OC(p2); edge = 0; do { if ((oc1 AND oc2)!= 0) // trivial reject of remaining segment return REJECT; else if ((oc1 OR oc2) == 0) // trivial accept of remaining segment return (ACCEPT, p1, p2); if ((oc1 XOR oc2)[edge]) { if (oc1[edge]) // p1 outside {p1 = cut(p1, p2, edge); oc1 = OC(p1);} else // p2 outside {p2 = cut(p1, p2, edge); oc2 = OC(p2);} } } while (++edge < 4); return ((oc1 OR oc2) == 0)? (ACCEPT, p1, p2) : REJECT; 1000 1010 Intersection calculation for x = x min y y a = x min x a y e y a x e x a y = y a + ( x min x a ) y e y a x e x a 0001 0101

Cyrus-Beck (1978) Parametric line-clipping algorithm Only convex polygons: max 2 intersection points p t out b Use edge orientation p e Idea: clipping against polygons Clip line p = p b + t i (p e p b ) with each edge Intersection points sorted by parameter t i t out Select t in : entry point ((p e p b ) N i < 0) with largest t i t out : exit point ((p e p b ) N i > 0) with smallest t i t in N i p b If t out < t in, line lies completely outside (akin to ray-box intersect.) Intersection calculation p p N i = 0 t in p e p b p edge p N i p e t i p e p b N i + p b p N i = 0 t i = p p b N i p e p b N i

Liang-Barsky (1984) Cyrus-Beck for axis-aligned rectangles Using window-edge coordinates (with respect to an edge T) T (p) = (p p T ) N T ܥܧ Example: top (y = y max ) y p e p b N T ݔ x N T = 0 1,p b p T = x b ݔ y y b t T = p b p T N T ܥܧ T p b = ݔ y = y b p b p e N T ܥܧ T p b ܥܧ T p e y b y e x Window-edge coordinate (WEC): decision function for an edge Directed distance to edge Only sign matters, similar to Cohen-Sutherland outcodes Sign of the dot product determines whether the point is in or out Normalization unimportant

Line Clipping - Summary Cohen-Sutherland, Cyrus-Beck, and Liang-Barsky algorithms readily extend to 3D Cohen-Sutherland algorithm + Efficient when majority of lines can be trivially accepted / rejected Very large clip rectangles: almost all lines inside Very small clip rectangles: almost all lines outside Repeated clipping for remaining lines Testing for 2D/3D point coordinates Cyrus-Beck (Liang-Barsky) algorithms + Efficient when many lines must be clipped + Testing for 1D parameter values Testing intersections always for all clipping edges (in the Liang- Barsky trivial rejection testing possible)

Polygon Clipping Extended version of line clipping Condition: polygons have to remain closed Filling, hatching, shading,...

Sutherland-Hodgeman (1974) Idea Iterative clipping against each edge in sequence Local operations on p i-1 and p i p i-1 p i-1 p p i-1 p i-1 p i p i inside outside inside outside inside output: p i output: p output: - p i outside p i inside p outside 1 st output: p 2 nd output: p i

Enhancements Recursive polygon clipping Pipelined Sutherland-Hodgeman p 0, p 1,... Top Bottom Left Right p 0, p 1,... Problems Degenerated polygons/edges Elimination by post-processing, if necessary

Other Clipping Algorithms Weiler & Atherton ( 77) Arbitrary concave polygons with holes against each other Vatti ( 92) Also with self-overlap Greiner & Hormann (TOG 98) Simpler and faster as Vatti Also supports Boolean operations Idea: Odd winding number rule Non-zero WN: in Even WN: out Intersection with the polygon leads to a winding number 1 Walk along both polygons Alternate winding number value Mark point of entry and point of exit Combine results

Greiner & Hormann A in B B in A (A in B) U (B in A)

3D Clipping agst. View Volume Requirements Avoid unnecessary rasterization Avoid overflow on transformation at fixed point! Clipping against viewing frustum Enhanced Cohen-Sutherland with 6-bit outcode After perspective division -1 < y < 1-1 < x < 1-1 < z < 0 Clip against side planes of the canonical viewing frustum Works analogously with Liang-Barsky or Sutherland-Hodgeman

3D Clipping agst. View Volume Clipping in homogeneous coordinates Use canonical view frustum, but avoid costly division by W Inside test with a linear distance function (WEC) Left: X / W > -1 W + X = WEC L (p) > 0 Top: Y / W < 1 W Y = WEC T (p) > 0 Back: Z / W > -1 W + Z = WEC B (p) > 0 Intersection point calculation (before homogenizing) Test: WEC L (p b ) > 0 and WEC L (p e ) < 0 Calculation: WEC L p b + t p e p b = 0 W b + t W e W b + X b + t X e X b = 0 W b + X b t = (W b +X b ) (W e + X e ) = WEC L (p b ) WEC L p b WEC L (p e )

Problems with Homogen. Coord. Negative w Points with w < 0 or lines with w b < 0 and w e < 0 Negate and continue Lines with w b w e < 0 (NURBS) Line moves through infinity External line Clipping two times Original line Negated line Generates up to two segments p b w -p e x W=1 p e -p b

Practical Implementations Combining clipping and scissoring Clipping is expensive and should be avoided Intersection calculation Variable number of new points, new triangles Enlargement of clipping region Larger than viewport, but Still avoiding overflow due to fixed-point representation Result Less clipping Applications should avoid drawing objects that are outside of the viewport/viewing frustum Objects that are partially outside will be implicitly clipped during rasterization Slight penalty because they will still be processed (triangle setup) Clipping region Viewport