MIT EECS 6.837, Durand and Cutler The Graphics Pipeline: Clipping & Line Rasterization.

Slides:



Advertisements
Similar presentations
Computer Graphics - Rasterization -
Advertisements

CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1 Emmanuel Agu.
CS 450: COMPUTER GRAPHICS REVIEW: DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
Graphics Pipeline.
3/2/04© University of Wisconsin, CS559 Spring 2004 Last Time General Perspective –Methods for specifying the view volume As a set of clip planes As a field.
Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 111 Today’s class Clipping Parametric and point-normal form of lines Intersecting.
Implementation Dr. Amy Zhang. Reading 2  Hill, Chapters  Hill, Chapter 10.
Bresenham’s Midpoint Algorithm CS5600 Computer Graphics Rich Riesenfeld Spring 2006 Lecture Set 1.
Vertices and Fragments I CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
Part I: Basics of Computer Graphics Rendering Polygonal Objects (Read Chapter 1 of Advanced Animation and Rendering Techniques) Chapter
CS 325 Introduction to Computer Graphics 03 / 03 / 2010 Instructor: Michael Eckmann.
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.
Basics of Rendering Pipeline Based Rendering –Objects in the scene are rendered in a sequence of steps that form the Rendering Pipeline. Ray-Tracing –A.
1/1/20001 Topic >>>> Scan Conversion CSE Computer Graphics.
WHERE TO DRAW A LINE?? Line drawing is accomplished by calculating intermediate positions along the line path between specified end points. Precise definition.
Scan Conversion Line and Circle
Triangle Scan Conversion. 2 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Rasterization Rasterization (scan conversion) –Determine which.
MIT EECS 6.837, Durand and Cutler Graphics Pipeline: Projective Transformations.
Objectives Introduce basic implementation strategies Clipping Scan conversion.
CS 480/680 Computer Graphics Shading in OpenGL Dr. Frederick C Harris, Jr. Fall 2013.
1Computer Graphics Implementation III Lecture 17 John Shearer Culture Lab – space 2
10/15/02 (c) 2002 University of Wisconsin, CS559 Last Time Clipping.
Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization.
MIT EECS Frédo Durand and Barb Cutler
MIT EECS 6.837, Cutler and Durand 1 Rasterization MIT EECS Frédo Durand and Barb Cutler.
10/19/04© University of Wisconsin, CS559 Fall 2004 Last Time Clipping –Why we care –Sutherland-Hodgman –Cohen-Sutherland –Intuition for Liang-Barsky Homework.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2013 Tamara Munzner Rasterization.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
MIT EECS 6.837, Durand and Cutler The Graphics Pipeline: Projective Transformations.
1Computer Graphics Implementation 1 Lecture 15 John Shearer Culture Lab – space 2
MIT EECS 6.837, Durand and Cutler The Graphics Pipeline: Line Clipping & Line Rasterization.
Lecture 13: Raster Graphics and Scan Conversion
Computer Graphics Inf4/MSc Computer Graphics Lecture 4 Line & Circle Drawing.
Lecture 9 From Vertices to Fragments. Objectives Introduce basic implementation strategies Clipping Rasterization hidden-surface removal.
Scan Conversion of Line Segments. What is Scan conversion? Final step of rasterization (the process of taking geometric shapes and converting them into.
Computer Graphics I, Fall 2010 Scan conversion algorithms.
Rasterization, or “What is glBegin(GL_LINES) really doing?” Course web page: February 23, 2012  Lecture 4.
OUTPUT PRIMITIVES CEng 477 Computer Graphics METU, 2004.
Primitive graphic objects
Scan Conversion or Rasterization
Computer Graphics Drawing Line.
Rendering Pipeline Fall, 2015.
- Introduction - Graphics Pipeline
Transformations contd.
MIT EECS 6.837, Cutler and Durand
Computer Graphics Shading in OpenGL
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1
Scan Conversion or Rasterization
University of New Mexico
Implementation III.
Chapter Three Part I Output Primitives CS 380.
CS451Real-time Rendering Pipeline
Models and Architectures
Implementation I Ed Angel
Graphics Pipeline Clipping
Introduction to Computer Graphics with WebGL
3D Rendering Pipeline Hidden Surface Removal 3D Primitives
Computer Graphics One of the central components of three-dimensional graphics has been a basic system that renders objects represented by a set of polygons.
Rasterization and Antialiasing
Chapter V Vertex Processing
Lecture 13 Clipping & Scan Conversion
Models and Architectures
Computer Graphics Implementation III
Rasterization and Antialiasing
(c) 2002 University of Wisconsin, CS559
Models and Architectures
Chapter 3 Graphics Output Primitives
Implementation I Ed Angel Professor Emeritus of Computer Science
Implementation III Ed Angel Professor Emeritus of Computer Science
Presentation transcript:

MIT EECS 6.837, Durand and Cutler The Graphics Pipeline: Clipping & Line Rasterization

MIT EECS 6.837, Durand and Cutler Last Time? Ray Tracing vs. Scan Conversion Overview of the Graphics Pipeline Projective Transformations Modeling Transformations Illumination (Shading) Viewing Transformation (Perspective / Orthographic) Clipping Projection (to Screen Space) Scan Conversion (Rasterization) Visibility / Display

MIT EECS 6.837, Durand and Cutler Today: Clipping & Line Rasterization Portions of the object outside the view frustum are removed Rasterize objects into pixels Modeling Transformations Illumination (Shading) Viewing Transformation (Perspective / Orthographic) Clipping Projection (to Screen Space) Scan Conversion (Rasterization) Visibility / Display

MIT EECS 6.837, Durand and Cutler Today Why Clip? Line Clipping Polygon clipping Line Rasterization

MIT EECS 6.837, Durand and Cutler Framebuffer Model Raster Display: 2D array of picture elements (pixels) Pixels individually set/cleared (greyscale, color) Window coordinates: pixels centered at integers glBegin(GL_LINES) glVertex3f(...) glEnd();

MIT EECS 6.837, Durand and Cutler 2D Scan Conversion Geometric primitives (point, line, polygon, circle, polyhedron, sphere... ) Primitives are continuous; screen is discrete Scan Conversion: algorithms for efficient generation of the samples comprising this approximation

MIT EECS 6.837, Durand and Cutler Clipping problem How do we clip parts outside window?

MIT EECS 6.837, Durand and Cutler Clipping problem How do we clip parts outside window? Create two triangles or more. Quite annoying.

MIT EECS 6.837, Durand and Cutler Also, what if the p z is < eye z ? (eye x, eye y, eye z ) image plane z axis → +

MIT EECS 6.837, Durand and Cutler The Graphics Pipeline Former hardware relied on full clipping Modern hardware mostly avoids clipping –Only with respect to plane z=0 In general, it is useful to learn clipping because it is similar to many geometric algorithms Modeling Transformations Illumination (Shading) Viewing Transformation (Perspective / Orthographic) Clipping Projection (to Screen Space) Scan Conversion (Rasterization) Visibility / Display

MIT EECS 6.837, Durand and Cutler Full Clipping (eye x, eye y, eye z ) image plane z axis "clip" geometry to view frustum

MIT EECS 6.837, Durand and Cutler One-plane clipping (eye x, eye y, eye z ) image plane z axis "clip" geometry to near plane

MIT EECS 6.837, Durand and Cutler When to clip? Perspective Projection: 2 conceptual steps: –4x4 matrix –Homogenize In fact not always needed Modern graphics hardware performs most operations in 2D homogeneous coordinates x y 1 z / d = xyz1xyz /d x * d / z y * d / z d/z 1 = homogenize

MIT EECS 6.837, Durand and Cutler When to clip? Before perspective transform in 3D space –Use the equation of 6 planes –Natural, not too degenerate In homogeneous coordinates after perspective transform (Clip space) –Before perspective divide (4D space, weird w values) –Canonical,independent of camera –The simplest to implement in fact In the transformed 3D screen space after perspective division –Problem: objects in the plane of the camera

MIT EECS 6.837, Durand and Cutler Working in homogeneous coordinates In general, many algorithms are simpler in homogeneous coordinates before division –Clipping –Rasterization

MIT EECS 6.837, Durand and Cutler Today Why Clip? Line Clipping Polygon clipping Line Rasterization

MIT EECS 6.837, Durand and Cutler Implicit 3D Plane Equation Plane defined by: point p & normal n OR normal n & offset d OR 3 points Implicit plane equation Ax+By+Cz+D = 0

MIT EECS 6.837, Durand and Cutler Homogeneous Coordinates Homogenous point: (x,y,z,w) infinite number of equivalent homogenous coordinates: (sx, sy, sz, sw) Homogenous Plane Equation: Ax+By+Cz+D = 0 → H = (A,B,C,D) Infinite number of equivalent plane expressions: sAx+sBy+sCz+sD = 0 → H = (sA,sB,sC,sD) H = (A,B,C,D)

MIT EECS 6.837, Durand and Cutler Point-to-Plane Distance If (A,B,C) is normalized: d = Hp = H T p (the dot product in homogeneous coordinates) d is a signed distance positive = "inside" negative = "outside" H = (A,B,C,D) d

MIT EECS 6.837, Durand and Cutler Clipping a Point with respect to a Plane If d = Hp  0 Pass through If d = Hp < 0: Clip (or cull or reject) H = (A,B,C,D) d

MIT EECS 6.837, Durand and Cutler Clipping with respect to View Frustum Test against each of the 6 planes –Normals oriented towards the interior Clip (or cull or reject) point p if any Hp < 0

MIT EECS 6.837, Durand and Cutler What are the View Frustum Planes? H near = H far = H bottom = H top = H left = H right = ( 0 0 –1 –near) ( far ) ( 0 near bottom 0 ) ( 0 –near –top 0 ) ( left near 0 0 ) (–right –near 0 0 ) (left, bottom, –near) (right*far/near, top*far/near, –far)

MIT EECS 6.837, Durand and Cutler Recall: When to clip? Before perspective transform in 3D space –Use the equation of 6 planes –Natural, not too degenerate In homogeneous coordinates after perspective transform (Clip space) –Before perspective divide (4D space, weird w values) –Canonical,independent of camera –The simplest to implement in fact In the transformed 3D screen space after perspective division –Problem: objects in the plane of the camera

MIT EECS 6.837, Durand and Cutler Questions? You are now supposed to be able to clip points wrt view frustum Using homogeneous coordinates

MIT EECS 6.837, Durand and Cutler Line – Plane Intersection Explicit (Parametric) Line Equation L(t) = P 0 + t * (P 1 – P 0 ) L(t) = (1-t) * P 0 + t * P 1 How do we intersect? Insert explicit equation of line into implicit equation of plane Parameter t is used to interpolate associated attributes (color, normal, texture, etc.)

MIT EECS 6.837, Durand and Cutler Segment Clipping If H p > 0 and H q < 0 If H p 0 If H p > 0 and H q > 0 If H p < 0 and H q < 0 p q

MIT EECS 6.837, Durand and Cutler Segment Clipping If H p > 0 and H q < 0 –clip q to plane If H p 0 If H p > 0 and H q > 0 If H p < 0 and H q < 0 p q n

MIT EECS 6.837, Durand and Cutler Segment Clipping If H p > 0 and H q < 0 –clip q to plane If H p 0 –clip p to plane If H p > 0 and H q > 0 If H p < 0 and H q < 0 p q n

MIT EECS 6.837, Durand and Cutler Segment Clipping If H p > 0 and H q < 0 –clip q to plane If H p 0 –clip p to plane If H p > 0 and H q > 0 –pass through If H p < 0 and H q < 0 p q n

MIT EECS 6.837, Durand and Cutler Segment Clipping If H p > 0 and H q < 0 –clip q to plane If H p 0 –clip p to plane If H p > 0 and H q > 0 –pass through If H p < 0 and H q < 0 –clipped out p q n

MIT EECS 6.837, Durand and Cutler Clipping against the frustum For each frustum plane H –If Hp > 0 and Hq < 0, clip q to H –If Hp 0, clip p to H –If Hp > 0 and Hq > 0, pass through –If Hp < 0 and Hq < 0, clipped out Result is a single segment. Why?

MIT EECS 6.837, Durand and Cutler Questions? You are now supposed to be able to clip segments wrt view frustum

MIT EECS 6.837, Durand and Cutler Is this Clipping Efficient? For each frustum plane H –If Hp > 0 and Hq < 0, clip q to H –If Hp 0, clip p to H –If Hp > 0 and Hq > 0, pass through –If Hp < 0 and Hq < 0, clipped out

MIT EECS 6.837, Durand and Cutler Is this Clipping Efficient? For each frustum plane H –If Hp > 0 and Hq < 0, clip q to H –If Hp 0, clip p to H –If Hp > 0 and Hq > 0, pass through –If Hp < 0 and Hq < 0, clipped out

MIT EECS 6.837, Durand and Cutler Is this Clipping Efficient? What is the problem? The computation of the intersections, and any corresponding interpolated values is unnecessary Can we detect this earlier? For each frustum plane H –If Hp > 0 and Hq < 0, clip q to H –If Hp 0, clip p to H –If Hp > 0 and Hq > 0, pass through –If Hp < 0 and Hq < 0, clipped out

MIT EECS 6.837, Durand and Cutler Improving Efficiency: Outcodes Compute the sidedness of each vertex with respect to each bounding plane (0 = valid) Combine into binary outcode using logical AND Outcode of p : 1010 Outcode of q : 0110 Outcode of [pq] : 0010 Clipped because there is a 1 p q

MIT EECS 6.837, Durand and Cutler Improving Efficiency: Outcodes When do we fail to save computation? Outcode of p : 1000 Outcode of q : 0010 Outcode of [pq] : 0000 Not clipped p q

MIT EECS 6.837, Durand and Cutler Improving Efficiency: Outcodes It works for arbitrary primitives And for arbitrary dimensions Outcode of p : 1010 Clipped Outcode of q : 1010 Outcode of r : 0110 Outcode of s : 0010 Outcode of t : 0110 Outcode of u : 0010 Outcode : 0010

MIT EECS 6.837, Durand and Cutler Questions? You are now supposed to be able to make clipping efficient using outcodes

MIT EECS 6.837, Durand and Cutler Today Why Clip? Line Clipping Polygon clipping Line Rasterization

MIT EECS 6.837, Durand and Cutler Polygon clipping

MIT EECS 6.837, Durand and Cutler Polygon clipping

MIT EECS 6.837, Durand and Cutler Polygon clipping Clipping is symmetric

MIT EECS 6.837, Durand and Cutler Polygon clipping is complex Even when the polygons are convex

MIT EECS 6.837, Durand and Cutler Polygon clipping is nasty When the polygons are concave

MIT EECS 6.837, Durand and Cutler Naïve polygon clipping? N*m intersections Then must link all segment Not efficient and not even easy

MIT EECS 6.837, Durand and Cutler Weiler-Atherton Clipping Strategy: “Walk" polygon/window boundary Polygons are oriented (CCW)

MIT EECS 6.837, Durand and Cutler Weiler-Atherton Clipping Compute intersection points

MIT EECS 6.837, Durand and Cutler Weiler-Atherton Clipping Compute intersection points Mark points where polygons enters clipping window (green here)

MIT EECS 6.837, Durand and Cutler Clipping While there is still an unprocessed entering intersection Walk" polygon/window boundary

MIT EECS 6.837, Durand and Cutler Walking rules Out-to-in pair: – Record clipped point – Follow polygon boundary (ccw) In-to-out pair: – Record clipped point – Follow window boundary (ccw)

MIT EECS 6.837, Durand and Cutler Walking rules Out-to-in pair: – Record clipped point – Follow polygon boundary (ccw) In-to-out pair: – Record clipped point – Follow window boundary (ccw)

MIT EECS 6.837, Durand and Cutler Walking rules Out-to-in pair: – Record clipped point – Follow polygon boundary (ccw) In-to-out pair: – Record clipped point – Follow window boundary (ccw)

MIT EECS 6.837, Durand and Cutler Walking rules Out-to-in pair: – Record clipped point – Follow polygon boundary (ccw) In-to-out pair: – Record clipped point – Follow window boundary (ccw)

MIT EECS 6.837, Durand and Cutler Walking rules While there is still an unprocessed entering intersection Walk" polygon/window boundary

MIT EECS 6.837, Durand and Cutler Walking rules While there is still an unprocessed entering intersection Walk" polygon/window boundary

MIT EECS 6.837, Durand and Cutler Walking rules While there is still an unprocessed entering intersection Walk" polygon/window boundary

MIT EECS 6.837, Durand and Cutler Walking rules While there is still an unprocessed entering intersection Walk" polygon/window boundary

MIT EECS 6.837, Durand and Cutler Weiler-Atherton Clipping Importance of good adjacency data structure (here simply list of oriented edges)

MIT EECS 6.837, Durand and Cutler Robustness, precision, degeneracies What if a vertex is on the boundary? What happens if it is “almost” on the boundary? –Problem with floating point precision Welcome to the real world of geometry!

MIT EECS 6.837, Durand and Cutler Clipping Many other clipping algorithms: Parametric, general windows, region-region, One-Plane-at-a-Time Clipping, etc.

MIT EECS 6.837, Durand and Cutler Questions?

MIT EECS 6.837, Durand and Cutler Today Why Clip? Line Clipping Polygon clipping Line Rasterization

MIT EECS 6.837, Durand and Cutler Scan Converting 2D Line Segments Given: –Segment endpoints (integers x1, y1; x2, y2) Identify: –Set of pixels (x, y) to display for segment

MIT EECS 6.837, Durand and Cutler Line Rasterization Requirements Transform continuous primitive into discrete samples Uniform thickness & brightness Continuous appearance No gaps Accuracy Speed

MIT EECS 6.837, Durand and Cutler Algorithm Design Choices Assume: –m = dy/dx, 0 < m < 1 Exactly one pixel per column –fewer → disconnected, more → too thick

MIT EECS 6.837, Durand and Cutler Algorithm Design Choices Note: brightness can vary with slope –What is the maximum variation? How could we compensate for this? –Answer: antialiasing

MIT EECS 6.837, Durand and Cutler Naive Line Rasterization Algorithm Simply compute y as a function of x –Conceptually: move vertical scan line from x1 to x2 –What is the expression of y as function of x? –Set pixel (x, round (y(x)))

MIT EECS 6.837, Durand and Cutler Efficiency Computing y value is expensive Observe: y += m at each x step (m = dy/dx)

MIT EECS 6.837, Durand and Cutler Bresenham's Algorithm (DDA) Select pixel vertically closest to line segment –intuitive, efficient, pixel center always within 0.5 vertically Same answer as naive approach

MIT EECS 6.837, Durand and Cutler Bresenham's Algorithm (DDA) Observation: –If we're at pixel P (x p, y p ), the next pixel must be either E (x p +1, y p ) or NE (x p, y p +1) –Why?

MIT EECS 6.837, Durand and Cutler Bresenham Step Which pixel to choose: E or NE? –Choose E if segment passes below or through middle point M –Choose NE if segment passes above M

MIT EECS 6.837, Durand and Cutler Bresenham Step Use decision function D to identify points underlying line L: D(x, y) = y-mx-b –positive above L –zero on L –negative below L D(p x,p y ) = vertical distance from point to line

MIT EECS 6.837, Durand and Cutler Bresenham's Algorithm (DDA) Decision Function: D(x, y) = y-mx-b Initialize: error term e = –D(x,y) On each iteration: update x: update e: if (e ≤ 0.5): if (e > 0.5): x' = x+1 e' = e + m y' = y (choose pixel E) y' = y + (choose pixel NE) e' = e - 1

MIT EECS 6.837, Durand and Cutler Summary of Bresenham initialize x, y, e for (x = x1; x ≤ x2; x++) –plot (x,y) –update x, y, e Generalize to handle all eight octants using symmetry Can be modified to use only integer arithmetic

MIT EECS 6.837, Durand and Cutler Line Rasterization We will use it for ray-casting acceleration March a ray through a grid

MIT EECS 6.837, Durand and Cutler Grid Marching vs. Line Rasterization Ray Acceleration: Must examine every cell the line touches Line Rasterization: Best discrete approximation of the line

MIT EECS 6.837, Durand and Cutler Questions?

MIT EECS 6.837, Durand and Cutler Circle Rasterization Generate pixels for 2nd octant only Slope progresses from 0 → –1 Analog of Bresenham Segment Algorithm

MIT EECS 6.837, Durand and Cutler Circle Rasterization Decision Function: D(x, y) = Initialize: error term e = On each iteration: update x: update e: if (e ≥ 0.5): if (e < 0.5): x' = x + 1 e' = e + 2x + 1 y' = y (choose pixel E) y' = y - 1 (choose pixel SE), e' = e + 1 x 2 + y 2 – R 2 –D(x,y) R

MIT EECS 6.837, Durand and Cutler Philosophically Discrete differential analyzer (DDA): Perform incremental computation Work on derivative rather than function Gain one order for polynomial –Line becomes constant derivative –Circle becomes linear derivative

MIT EECS 6.837, Durand and Cutler Questions?

MIT EECS 6.837, Durand and Cutler Antialiased Line Rasterization Use gray scales to avoid jaggies Will be studied later in the course aliased antialiased

MIT EECS 6.837, Durand and Cutler High-level concepts for Linearity Homogeneous coordinates Convexity Discrete vs. continuous

MIT EECS 6.837, Durand and Cutler Thursday Polygon Rasterization & Visibility