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

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

Computing Visibility. Backface Culling for General Visibility. One More Trick with Planes. BSP Trees Ray Casting Depth Buffering Quiz

Sung-Eui Yoon ( 윤성의 )

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

Culling. Computer Graphics CSE 167 Lecture 12

3D Rendering Pipeline (for direct illumination)

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

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

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

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

CSE 167: Introduction to Computer Graphics Lecture #11: Visibility Culling

Computer Graphics. Bing-Yu Chen National Taiwan University

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

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

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

Hidden surface removal. Computer Graphics

CSE 167: Introduction to Computer Graphics Lecture #10: View Frustum Culling

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

MIT EECS 6.837, Teller and Durand 1

The Traditional Graphics Pipeline

Class of Algorithms. Visible Surface Determination. Back Face Culling Test. Back Face Culling: Object Space v. Back Face Culling: Object Space.

Spatial Data Structures and Speed-Up Techniques. Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology

Clipping and Scan Conversion

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

Computer Graphics. - Clipping - Philipp Slusallek & Stefan Lemme

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

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

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

Computer Graphics. Lecture 9 Hidden Surface Removal. Taku Komura

CSE528 Computer Graphics: Theory, Algorithms, and Applications

The Traditional Graphics Pipeline

Visibility: Z Buffering

CSE328 Fundamentals of Computer Graphics

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

Clipping and Intersection

The Traditional Graphics Pipeline

CSE528 Computer Graphics: Theory, Algorithms, and Applications

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

Hidden Surface Removal

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

Computer Graphics: 7-Polygon Rasterization, Clipping

Hidden Surfaces II. Week 9, Mon Mar 15

From Vertices To Fragments-1

Visibility and Occlusion Culling

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

Hidden Surface Elimination: BSP trees

Triangle Rasterization

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

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

Computer Graphics Geometry and Transform

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

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

Determination (Penentuan Permukaan Tampak)

Visible-Surface Detection Methods. Chapter? Intro. to Computer Graphics Spring 2008, Y. G. Shin

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

Graphics and Interaction Rendering pipeline & object modelling

Performance OpenGL Programming (for whatever reason)

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

Visible Surface Detection. (Chapt. 15 in FVD, Chapt. 13 in Hearn & Baker)

Advanced 3D-Data Structures

Midterm Exam Fundamentals of Computer Graphics (COMP 557) Thurs. Feb. 19, 2015 Professor Michael Langer

Chapter 8: Implementation- Clipping and Rasterization

Two-Dimensional Viewing. Chapter 6

CS184 : Foundations of Computer Graphics Professor David Forsyth Final Examination

9. Visible-Surface Detection Methods

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

Realtime 3D Computer Graphics Virtual Reality

CS559: Computer Graphics. Lecture 12: Antialiasing & Visibility Li Zhang Spring 2008

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

Real-Time Rendering (Echtzeitgraphik) Dr. Michael Wimmer

Two basic types: image-precision and object-precision. Image-precision For each pixel, determine which object is visable Requires np operations

COMPUTATIONAL GEOMETRY

Illumination Models III: Ray Tracing (View Dependent Global Illumination)

8. Hidden Surface Elimination

Computer Science 474 Spring 2010 Viewing Transformation

Spatial Data Structures and Speed-Up Techniques. Ulf Assarsson Department of Computer Science and Engineering Chalmers University of Technology

CS488. Visible-Surface Determination. Luc RENAMBOT

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

INTRODUCTION TO COMPUTER GRAPHICS. It looks like a matrix Sort of. Viewing III. Projection in Practice. Bin Sheng 10/11/ / 52

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

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

CS 563 Advanced Topics in Computer Graphics Culling and Acceleration Techniques Part 1 by Mark Vessella

CS 130 Exam I. Fall 2015

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

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

Ray Tracing Basics I. Computer Graphics as Virtual Photography. camera (captures light) real scene. photo. Photographic print. Photography: processing

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Ray tracing. Computer Graphics COMP 770 (236) Spring Instructor: Brandon Lloyd 3/19/07 1

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Spatial Data Structures

Shadows in the graphics pipeline

Spatial Data Structures

CS 498 VR. Lecture 18-4/4/18. go.illinois.edu/vrlect18

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

Viewing Transformation. Clipping. 2-D Viewing Transformation

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

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

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

Drawing in 3D (viewing, projection, and the rest of the pipeline)

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

Transcription:

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

What is Clipping? Clipping is a procedure for spatially partitioning geometric primitives, according to their containment within some region. Clipping can be used to: Distinguish whether geometric primitives are inside or outside of a viewing frustum Distinguish whether geometric primitives are inside or outside of a picking frustum Detecting intersections between primitives 2

What is Clipping? Clipping is a procedure for subdividing geometric primitives. This view of clipping admits several other potential applications. Binning geometric primitives into spatial data structures. Computing analytical shadows. Computing intersections between primitives 3

Clipping is an important optimization Why do we Clip? Clipping is a visibility preprocess. In real-world scenes clipping can remove a substantial percentage of the environment from consideration. Assures that only potentially visible primitives are rasterized. What advantage does this have over twodimensional clipping. Are there cases where you have to clip? 4

Where do we Clip? There are at least 3 different stages in the rendering pipeline where we do various forms of clipping. In the trivial rejection stage we remove objects that can not be seen. The clipping stage removes objects and parts of objects that fall outside of the viewing frustum. And, when rasterizing, clipping is used to remove parts of objects outside of the view port. xmin = (int) (v[sort[xflag][0]].x); xmax = (int) (v[sort[xflag][1]].x + 1); ymin = (int) (v[sort[yflag][1]].y); ymax = (int) (v[sort[yflag][0]].y + 1); /* clip triangle's bounding box to raster */ xmin = (xmin < 0)? 0 : xmin; xmax = (xmax >= width)? width - 1 : xmax; ymin = (ymin < 0)? 0 : ymin; ymax = (ymax >= height)? height - 1 : ymax; 5

Trivial Rejection Clipping One of the keys to all clipping algorithms is the notion of half-space partitioning. We ve seen this before when we discussed how edge equations partition the image plane into two regions, one negative the other nonnegative. The same notion extends to 3-dimensions, but partitioning elements are planes rather than lines. The equation of a plane in 3D is given as: x y z 1 n n n 0 d x A vector dotted with a point. The vector is the plane s normal. The points of the plane are a fixed distance, d, from the origin, after projection onto the normal. y z 6

Here is a simple Example: Trivial Rejection Clipping If we orient a plane so that it passes through our viewing position and our look-at direction is aligned with its normal. Then we can easily partition objects into three classes, those behind our viewing frustum, those in front, and those that are partially in both half-spaces. 7

Outcode Clipping (a.k.a. Cohen-Sutherland Clipping) The extension of plane partitioning to multiple planes, gives a simple form of clipping called Cohen-Sutherland Clipping. This is a rough approach to clipping in that it only classifies each of it's input primitives, rather than forces them to conform to the viewing window. A simple 2-D example is shown on the right. This technique classifies each vertex of a primitive, by generating an outcode. An outcode identifies the appropriate half space location of each vertex relative to all of the clipping planes. Outcodes are usually stored as bit vectors. By comparing the bit vectors from all of the vertices associated with a primitive we can develop conclusions about the whole primitive. 8

Outcode Clipping of Lines First, let's consider line segments. if (outcode1 == '0000' && outcode2 == 0000) then line segment is inside else if ((outcode1 & outcode2) == 0000) then line segment potentially crosses clip region else line is entirely outside of clip region endif endif Notice that the test cannot conclusively state whether the segment crosses the clip region. This might cause some segments that are located entirely outside of the clipping volume to be subsequently processed. Is there a way to modify this test so that it can eliminate these false positives? 9

Outcode Clipping of Triangles For triangles we need only modify the tests so that all vertices are considered: if (outcode1 == '0000' && outcode2 == '0000' && outcode3 == '0000') then triangle is inside else if ((outcode1 & outcode2 & outcode3) == '0000') then line segment potentially crosses clip region else line is entirely outside of clip region endif endif This form of clipping is not limited to triangles or convex polygons. It is simple to implement. But, it won t handle all of our problems... 10

Dealing with Crossing Cases The hard part of clipping is handling objects and primitives that straddle clipping planes. In some cases we can ignore these problems because the combination of screen-space clipping and outcode clipping will handle most cases. However, there is one case in general that cannot be handled this way. This is the case when parts of a primitive lies both in front of and behind the viewpoint. This complication is caused by our projection stage. It has the nasty habit of mapping objects behind the viewpoint to positions in front of it. 11

One-Plane-at-a-Time Clipping (a.k.a. Sutherland-Hodgeman Clipping) The Sutherland-Hodgeman triangle clipping algorithm uses a divide-and-conquer strategy. It first solves the simple problem of clipping a triangle against a single plane. There are four possible relationships that a triangle can have relative to a clipping plane as shown in the figures on the right. Each of the clipping planes are applied in succession to every triangle. There is minimal storage requirements for this algorithm, and it is well suited to pipelining. As a result it is often used in hardware implementations. 12

Plane-at-a-Time Clipping The results of Sutherland-Hodgeman clipping can get complicated very quickly once multiple clip-planes are considered. However, the algorithm is still very simple. Each clip plane is treated independently, and each triangle is treated by on of the four cases mentioned previously. It is straightforward to extend this algorithm to 3D. 13

Advantages: Recap of Plane-at-a-time Clipping Elegant (few special cases) Robust (handles boundary and edge conditions well) Well suited to hardware Canonical clipping makes fixed-point implementations manageable Disadvantages: Hard to fix into O-O paradigm (Reentrant, objects spawn new short-lived objects) Only works for convex clipping volumes Often generates more than the minimum number of triangles needed Requires a divide per clipped edge 14

Alternatives to Plane-at-a-time Over the years there have been several improvements to plane-at-a-time clipping. Clipping against concave volumes (Wieler-Atherton clipping) Can clip arbitrary polygons against arbitrary polygons Maintains more state than plane-at-a-time clipping Handle all planes at once (Nicholle-Lee-Nicholle clipping) It waits before generating triangles to reduce the number of clip sections generated. Tracks polygon through the 27 sub-regions relative to the clip volume Might need to generate a "corner vertex" 15

Back-Face Culling Back-face culling addresses a special case of occlusion called convex self-occlusion. Basically, if an object is closed (having a well defined inside and outside) then some parts of the outer surface must be blocked by other parts of the same surface. We'll be more precise with our definitions in a minute. On such surfaces we need only consider the normals of surface elements to determine if they are visible. 16

Idea: Compare the normal of each face with the viewing direction Given n, the outward-pointing normal of F foreach face F of object if (n. v > 0) throw away the face Does it work? Removing Back-Faces 17

Fixing the Problem We can t do view direction clipping just anywhere! Downside: Projection comes fairly late in the pipeline. It would be nice to cull objects sooner. Upside: Computing the dot product is simpler. You need only look at the sign of the plane s z component. 18

Culling Technique #2 Detect a change in screen-space orientation. If all face vertices are ordered in a consistent way, back-facing primitives can be found by detecting a reversal in this order. One choice is a counterclockwise ordering when viewed from outside of the manifold. This is consistent with computing face normals (Why?). If, after projection, we ever see a clockwise face, it must be back facing. This approach will work for all cases, but it comes even later in the pipe, at triangle setup. We already do this calculation in our triangle rasterizer. It is equivalent to determining a triangle with negative area. 19

Culling Plane-Test Here is a culling test that will work anywhere in the pipeline. Remove faces that have the eye in their negative half-space. This requires computing a plane equation for each face considered. x y z 1 n n n 0 d 0 x y z We will still need to compute the normal (How?). But, we don t have to normalize it. (How do we go about computing a value for d?) 20

Culling Plane-Test Once we have the plane equation, we substitute the coordinate of the viewing point (the eye coordinate in our viewing matrix). If it is negative, then the surface is backfacing. Example: 21

Back Face Culling in OpenGL Back Face Culling is available as a mode setting in OpenGL. very flexible (can cull fronts as well as backs) it can double your performance! depends on consistent models public void backfacecull(bool turnon) { if (turnon) { glfrontface(gl_ccw); // define the orientation of front faces glenable(gl_cull_face); // enable Culling glcullface(gl_back); // tell which faces to cull } else { gldisable(gl_cull_face); // disable Culling } } 22

I think that I shall never see A Binary Space Partition (BSP) tree is a simple spatial data structure: 1. Select a partitioning plane/face. 2. Partition the remaining planes/faces according to the side of the partitioning plane that they fall on (+ or -). 3. Repeat with each of the two new sets. Partitioning facets: Partitioning requires testing all facets in the active set to find if they 1) lie entirely on the positive side of the partition plane, 2) lie entirely on the negative side, or 3) if they cross it. In the 3 rd case of a crossing face we clip the offending face into two halves (using our plane-at-a-time clipping algorithm). Lecture 13

Computing Visibility with BSP trees Starting at the root of the tree. 1. Classify viewpoint as being in the positive or negative halfspace of our plane 2. Call this routine with the negative child (if it exists) 3. Draw the current partitioning plane 4. Call this routine with the positive child (if it exists) Intuitively, at each partition, we first draw the stuff further away than the current plane, then we draw the current plane, and then we draw the closer stuff. BSP traversal is called a "hidden surface elimination" algorithm, but it doesn t really "eliminate" anything; it simply orders the drawing of primitive in a back-to-front order. Lecture 13

BSP Tree Example Computing visibility or depth-sorting with BSP trees is both simple and fast. It resolves visibility at the primitive level. Visibility computation is independent of screen size Requires considerable preprocessing of the scene primitives Primitives must be easy to subdivide along planes Supports Constructive Solid Geometry (CSG) modeling Lecture 13