Now Playing: California Stars Billy Bragg & Wilco from Mermaid Avenue

Slides:



Advertisements
Similar presentations
Computer Graphics - Rasterization -
Advertisements

Rezanje črt in poligonov. World window & viewport window viewport screen window world window.
CS 450: COMPUTER GRAPHICS FILLING POLYGONS SPRING 2015 DR. MICHAEL J. REALE.
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
10/10/02 (c) 2002 University of Wisconsin, CS 559 Last Time Finished viewing: Now you know how to: –Define a region of space that you wish to view – the.
CS 551 / 645: Introductory Computer Graphics Clipping Lines and Polygons.
Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)
Course Website: Computer Graphics 4: Viewing In 2D.
1 Clipping. 2 Transformation Sequence X Y Z X Y Z X Y Z X Y Z Object Coords. Eye Coords. Clip Coords. Normalized Device Coords. Screen Coords. Implementation:
Two-Dimensional Viewing Jehee Lee Seoul National University.
Computer Graphics Viewing.
Viewing & Clipping In 2D. 2 of 44 Contents Windowing Concepts Clipping –Introduction –Brute Force –Cohen-Sutherland Clipping Algorithm Area Clipping –Sutherland-Hodgman.
CMPE 466 COMPUTER GRAPHICS Chapter 8 2D Viewing Instructor: D. Arifler Material based on - Computer Graphics with OpenGL ®, Fourth Edition by Donald Hearn,
Introduction to Computer Graphics Chapter 6 – 2D Viewing Pt 2 1.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Interpolation Clipping.
Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 111 Today’s class Clipping Parametric and point-normal form of lines Intersecting.
Vertices and Fragments I CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
Course Website: Computer Graphics 9: Clipping In 3D.
1 CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai.
Status – Week 231 Victor Moya. Summary Primitive Assembly Primitive Assembly Clipping triangle rejection. Clipping triangle rejection. Rasterization.
Now Playing: Big Bird Eddie Floyd from The Complete Stax-Volt Singles Volume 1 ( ) Released April 30, 1991.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Clipping.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Implementation I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Graphics Pipeline Clipping CMSC 435/634. Graphics Pipeline Object-order approach to rendering Sequence of operations – Vertex processing – Transforms.
2/26/04© University of Wisconsin, CS559 Spring 2004 Last Time General Orthographic Viewing –Specifying cameras in world coordinates –Building world  view.
1 Computer Graphics Assistant Professor Dr. Sana’a Wafa Al-Sayegh 2 nd Semester ITGD3107 University of Palestine.
2-Dimension Viewing and Clipping
Clipping Apart from clipping to the view volume, clipping is a basic operation in many other algorithms –Breaking space up into chunks –2D drawing and.
CGMB 314 Intro to Computer Graphics Fill Area Primitives.
CS 376 Introduction to Computer Graphics 02 / 12 / 2007 Instructor: Michael Eckmann.
Two-Dimensional Viewing
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:
CS 325 Introduction to Computer Graphics 03 / 08 / 2010 Instructor: Michael Eckmann.
Clipping Aaron Bloomfield CS 445: Introduction to Graphics Fall 2006 (Slide set originally by David Luebke)
CS 480/680 Computer Graphics Shading in OpenGL Dr. Frederick C Harris, Jr. Fall 2013.
10/15/02 (c) 2002 University of Wisconsin, CS559 Last Time Clipping.
CSE Real Time Rendering Week 9. Post Geometry Shaders Courtesy: E. Angel and D. Shreiner – Interactive Computer Graphics 6E © Addison-Wesley 2012.
Windows, Viewports, and Clipping
Implementation II.
Basic Perspective Projection Watt Section 5.2, some typos Define a focal distance, d, and shift the origin to be at that distance (note d is negative)
10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.
EEL Introduction to Computer Graphics
Implementation of a Renderer Consider Programs are processd by the system line & polygon, outside the view volume Efficiently Understanding of the implementation.
1Computer Graphics Implementation 1 Lecture 15 John Shearer Culture Lab – space 2
2D Viewing.
Graphics Graphics & Graphical Programming Lecture 23 - Viewing & Clipping.
Computer Graphics Viewing. 2 of 30 Viewing in 2D Window in world coordinates. 45  250  Viewport in Device coords 250 x 250 Pixels.
Lecture 9 From Vertices to Fragments. Objectives Introduce basic implementation strategies Clipping Rasterization hidden-surface removal.
CS552: Computer Graphics Lecture 12: 3D Clipping.
Two-Dimensional Viewing Hearn & Baker Chapter 6
Computer Graphics Clipping.
Computer Graphics CC416 Week 13 Clipping.
Transformations contd.
CS 551 / 645: Introductory Computer Graphics
Computer Graphics Shading in OpenGL
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
Concepts, algorithms for clipping
3D Clipping.
Implementation I Ed Angel
Graphics Pipeline Clipping
Computer Graphics : Viewing In 2D
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai
Lecture 13 Clipping & Scan Conversion
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
Clipping Clipping Sutherland-Hodgman Clipping
Computer Graphics Viewing. 2 of 30 Viewing in 2D Window in world coordinates. 45  250  Viewport in Device coords 250 x 250 Pixels.
Clipping University of British Columbia CPSC 314 Computer Graphics
Implementation I Ed Angel Professor Emeritus of Computer Science
COMPUTER GRAPHICS Clipping
Presentation transcript:

Now Playing: California Stars Billy Bragg & Wilco from Mermaid Avenue Released June 23, 1998

Vertex Processing: Clipping Rick Skarbez, Instructor COMP 575 October 2, 2007 Some slides and images courtesy Jeremy Wendt (2005)

Announcements Assignment 2 is out today Due next Tuesday by the end of class

Last Time Reviewed the OpenGL pipeline Discussed classical viewing and presented a taxonomy of different views Talked about how projections and viewport transforms are used in OpenGL

Today Discuss clipping Points Lines Polygons

Rendering Pipeline OpenGL rendering works like an assembly line Each stage of the pipeline performs a distinct function on the data flowing by Each stage is applied to every vertex to determine its contribution to output pixels Geometry (Vertices) Vertex Processing Fragment Processing Rasterizer Pixels

Clipping & Primitive Assembly Vertex Processing Vertices Modelview Transform Projection Transform Vertex Processing Lighting Viewport Transform Clipping & Primitive Assembly

Determining What’s in the Viewport Not all primitives map to inside the viewport Some are entirely outside Need to cull Some are partially inside and partially outside Need to clip There must be NO DIFFERENCE to the final rendered image

Why Clip? Rasterization is very expensive Approximately linear with number of fragments created Math and logic per pixel If we only rasterize what is actually viewable, we can save a lot A few operations now can save many later

Clipping Primitives Different primitives can be handled in different ways Points Lines Polygons

Point Clipping This one is easy How to determine if a point (x, y, z) is in the viewing volume (xnear, ynear, znear), (xfar, yfar, zfar)? Who wants to tell me how? if ((x > xfar II x < xnear) || (y > yfar II y < ynear) || (z > zfar II z < znear)) cull the point else keep it

Line Clipping What happens when a line passes out of the viewing volume/plane? Part is visible, part is not Need to find the entry/exit points, and shorten the line The shortened line is what gets passed to rasterization

Line Clipping Example Let’s do 2D first Clip a line against 1 edge of the viewport What do we know? Similar triangles A / B = C / D B = (x2 - x1) A = (y2 - y1) C = (y1 - ymax) D = BC / A (x’, y’) = (x1 - D, ymax) (x1, y1) C D A B (x’, y’) ??? (x2, y2)

Line Clipping The other cases are handled similarly The algorithm extends easily to 3D The problem? Too expensive! (these numbers are for 2D) 3 floating point subtracts 2 floating point multiplies 1 floating point divide 4 times! (once for each edge) We need to do better

Cohen-Sutherland Line Clipping Split plane into 9 regions Assign each a 4-bit tag (above, below, right, left) Assign each endpoint a tag 1001 1000 1010 0001 0000 0010 Viewport 0101 0100 0100

Cohen-Sutherland Line Clipping Algorithm: if (tag1 == tag2 == 0000) accept the line if ((tag1 & tag2) != 0) reject the line Clip the line against an edge (where both bits are nonzero) Assign the new vertex a 4-bit value Return to 1 1001 1000 1010 0001 0000 0010 Viewport 0101 0100 0110 N.B.: & is the bitwise AND operator

Cohen-Sutherland Example What are the vertex codes for these lines? G = 1001, H = 1000 (REJECT); I = 0001, J = 1000 (CLIP) A = 0000, B = 0000 (ACCEPT); C = 0000, B = 0010 (CLIP) E = 0100, F = 0100 (REJECT)

Cohen-Sutherland Line Clipping Lets us eliminate many edge clips early Extends easily to 3D 27 regions 6 bits Similar triangles still works in 3D Just have to do it for 2 sets of similar triangles

Liang-Barsky Line Clipping Consider the parametric definition of a line: x = x1 + u∆x y = y1 + u∆y ∆x = (x2 - x1), ∆y = (y2 - y1), 0 ≤ (u, v) ≤ 1 What if we could find the range for u and v in which both x and y are inside the viewport?

Liang-Barsky Line Clipping Mathematically, this means xmin ≤ x1 + u∆x ≤ xmax ymin ≤ y1 + u∆y ≤ ymax Rearranging, we get -u∆x ≤ (x1 - xmin) u∆x ≤ (xmax - x1) -v∆y ≤ (y1 - ymin) v∆y ≤ (ymax - y1) In general: u * pk ≤ qk

Liang-Barsky Line Clipping Cases: pk = 0 Line is parallel to boundaries If for the same k, qk < 0, reject Else, accept pk < 0 Line starts outside this boundary rk = qk / pk u1 = max(0, rk, u1)

Liang-Barsky Line Clipping Cases: (cont’d) pk > 0 Line starts outside this boundary rk = qk / pk u2 = min(1, rk, u2) If u1 > u2, the line is completely outside

Liang-Barsky Line Clipping Also extends to 3D Just add equations for z = z1 + u∆z 2 more p’s and q’s

Liang-Barsky Line Clipping In most cases, Liang-Barsky is slightly more efficient According to the Hearn-Baker textbook Avoids multiple shortenings of line segments However, Cohen-Sutherland is much easier to understand (I think) An important issue if you’re actually implementing

Nicholl-Lee-Nicholl Line Clipping This is a theoretically optimal clipping algorithm (at least in 2D) However, it only works well in 2D More complicated than the others Just do an overview here

Nicholl-Lee-Nicholl Line Clipping Partition the region based on the first point (p1): Case 1: p1 inside region Case 2: p1 across edge Case 3: p1 across corner L T R B p1 Case 1 T TR LB p1 L TB Case 3 L LT LR LB p1 Case 2

Nicholl-Lee-Nicholl Line Clipping Can use symmetry to handle all other cases “Algorithm” (really just a sketch): Find slopes of the line and the 4 region bounding lines Determine what region p2 is in If not in a labeled region, discard If in a labeled region, clip against the indicated sides

A Note on Redundancy Why am I presenting multiple forms of clipping? Why do you learn multiple sorts? Fastest can be harder to understand / implement Best for the general case may not be for the specific case Bubble sort is really great on mostly sorted lists “History repeats itself” You may need to use a similar algorithm for something else; grab the closest match

Polygon Inside/Outside Polygons have a distinct inside and outside How do you tell, just from a list of vertices/edges? Even/odd Winding number

Polygon Inside/Outside: Even / Odd Count edge crossings If the number is even, that area is outside If odd, it is inside 2 1 1 2 3 4

Polygon Inside/Outside: Winding Number Each line segment is assigned a direction by walking around the edges in some pre-defined order OpenGL walks counter-clockwise Count right->left edge crossings and left->right edge crossings If equal, the point is outside

Polygon Clipping Polygons are just composed of lines. Why do we need to treat them differently? Need to keep track of what is inside NOTE: Lines Polygons

Polygon Clipping Many tricky bits Maintaining inside/outside Introduces variable number of vertices Need to handle screen corners correctly

Sutherland-Hodgeman Polygon Clipping Simplify via separation Clip the entire polygon with one edge Clip the output polygon against the next edge Repeat for all edges Extends easily to 3D (6 edges instead of 4) Can create intermediate vertices that get thrown out later

Sutherland-Hodgeman Polygon Clipping Example 1: Out -> In Save new clip vertex and ending vertex In -> In Save ending vertex Out -> Out Save nothing In -> Out Save new clip vertex

Sutherland-Hodgeman Polygon Clipping Example 2: NOTE: Clip Left Clip Right Start Clip Bottom Clip Top

Weiler-Atherton Polygon Clipping When using Sutherland-Hodgeman, concavities can end up linked A different clipping algorithm, the Weiler-Atherton algorithm, creates separate polygons Remember this?

Weiler-Atherton Polygon Clipping Example: Out -> In Add clip vertex Add end vertex In -> In Add end vertex In -> Out Add clip vertex Cache old direction Follow clip edge until (a) new crossing found (b) reach vertex already added

Weiler-Atherton Polygon Clipping Example (cont’d): Continue from cached vertex and direction Out -> In Add clip vertex Add end vertex In -> Out Add clip vertex Cache old direction Follow clip edge until (a) new crossing found (b) reach vertex already added

Weiler-Atherton Polygon Clipping Example (cont’d): Final Result: 2 unconnected polygons Continue from cached vertex and direction Nothing added Finished

Weiler-Atherton Polygon Clipping Difficulties: What if the polygon recrosses an edge? How big should your cache be? Geometry step must be able to create new polygons Not 1 in, 1 out

Done with Clipping Point Clipping (really just culling) Line Clipping Easy, just do inequalities Line Clipping Cohen-Sutherland Liang-Barsky Nicholl-Lee-Nicholl Polygon Clipping Sutherland-Hodgeman Weiler-Atherton Any Questions?

Next Time Moving on down the pipeline Rasterization Line drawing