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

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

From Vertices To Fragments-1

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

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

Topics. From vertices to fragments

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

Two-Dimensional Viewing. Chapter 6

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

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

Clipping and Intersection

3D Rendering Pipeline (for direct illumination)

Realtime 3D Computer Graphics Virtual Reality

? Which intermediate. Recall: Line drawing algorithm. Programmer specifies (x,y) of end pixels Need algorithm to determine pixels on line path

CS 325 Computer Graphics

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

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

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

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

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

COMP3421. Vector geometry, Clipping

Computer Graphics. - Clipping - Philipp Slusallek & Stefan Lemme

Computer Graphics CS 543 Lecture 13a Curves, Tesselation/Geometry Shaders & Level of Detail

Clipping and Scan Conversion

Painter s HSR Algorithm

7. 3D Viewing. Projection: why is projection necessary? CS Dept, Univ of Kentucky

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

Chapter 8: Implementation- Clipping and Rasterization

Clipping Lines. Dr. Scott Schaefer

Sung-Eui Yoon ( 윤성의 )

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

Introduction to Computer Graphics 5. Clipping

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

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

CS 543: Computer Graphics. Rasterization

Computer Graphics CS 543 Lecture 11 (Part 1) Polygon Filling & Antialiasing

Part IV. 2D Clipping

CS 563 Advanced Topics in Computer Graphics Lecture 2: Bare-Bones Raytracer. by Emmanuel Agu

Computer Graphics (CS 543) Lecture 13b Ray Tracing (Part 1) Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Viewing Transformation. Clipping. 2-D Viewing Transformation

CSE452 Computer Graphics

Chap 7, 2008 Spring Yeong Gil Shin

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

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 Viewing Objective

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

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

Computer Graphics (CS 543) Lecture 2c: Fractals. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

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

CS184 : Foundations of Computer Graphics Professor David Forsyth Final Examination

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI

Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology

Geometry. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

Computer Graphics: Two Dimensional Viewing

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

Computer Graphics (CS 4731) Lecture 16: Lighting, Shading and Materials (Part 1)

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

Computer Graphics (CS 543) Lecture 7b: Intro to lighting, Shading and Materials + Phong Lighting Model

Rasterization, Depth Sorting and Culling

MODULE - 9. Subject: Computer Science. Module: Line Clipping. Module No: CS/CGV/9

3D Rendering. Course Syllabus. Where Are We Now? Rendering. 3D Rendering Example. Overview. Rendering. I. Image processing II. Rendering III.

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

Windowing And Clipping (14 Marks)

CS123 INTRODUCTION TO COMPUTER GRAPHICS. Describing Shapes. Constructing Objects in Computer Graphics 1/15

Recall: Indexing into Cube Map

Geometry. Prof. George Wolberg Dept. of Computer Science City College of New York

Computer Graphics 4731 Lecture 5: Fractals. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Computer Graphics (CS 543) Lecture 10: Soft Shadows (Maps and Volumes), Normal and Bump Mapping

Lab Manual. Computer Graphics. T.E. Computer. (Sem VI)

CS337 INTRODUCTION TO COMPUTER GRAPHICS. Describing Shapes. Constructing Objects in Computer Graphics. Bin Sheng Representing Shape 9/20/16 1/15

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

Lecture 4: Planes, Interior Point Testing, Duality

SUMMARY. CS380: Introduction to Computer Graphics Varying Variables Chapter 13. Min H. Kim KAIST School of Computing 18/04/26.

3D convex hulls. Computational Geometry [csci 3250] Laura Toma Bowdoin College

3D convex hulls. Computational Geometry [csci 3250] Laura Toma Bowdoin College

Computer Graphics (CS 543) Lecture 8 (Part 1): Physically-Based Lighting Models

Chap 7, 2009 Spring Yeong Gil Shin

Objectives. Geometry. Basic Elements. Coordinate-Free Geometry. Transformations to Change Coordinate Systems. Scalars

Curves and Surfaces Computer Graphics I Lecture 9

Scanline Rendering 1 1/42

Geometric Queries for Ray Tracing

Computer Graphics with OpenGL ES (J. Han) Chapter IV Spaces and Transforms

Curves and Surfaces Computer Graphics I Lecture 10

CS 543: Computer Graphics. Projection

MIT EECS 6.837, Teller and Durand 1

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

Clipping. CSC 7443: Scientific Information Visualization

Practical Linear Algebra: A Geometry Toolbox

Clipping Algorithms; 8-5. Computer Graphics. Spring CS4815

Fast Algorithms for Line Segment and Line Clipping in E 2

A Procedure to Clip Line Segment

COMP30019 Graphics and Interaction Rendering pipeline & object modelling

Lecture outline. COMP30019 Graphics and Interaction Rendering pipeline & object modelling. Introduction to modelling

12.5 Lines and Planes in 3D Lines: We use parametric equations for 3D lines. Here s a 2D warm-up:

Computer Graphics (CS 543) Lecture 4a: Linear Algebra for Graphics (Points, Scalars, Vectors)

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

Projection Matrix Tricks. Eric Lengyel

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

Temporal Resolution. Flicker fusion threshold The frequency at which an intermittent light stimulus appears to be completely steady to the observer

3D Modeling Parametric Curves & Surfaces. Shandong University Spring 2013

Transcription:

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

Liang Barsky 3D Clipping Goal: Clip object edge-by-edge against Canonical View volume (CVV) Problem: 2 end-points of edge: A = (Ax, Ay, Az, Aw) and C = (Cx, Cy, Cz, Cw) If edge intersects with CVV, compute intersection point I =(Ix,Iy,Iz,Iw)

Determining if point is inside CVV y = 1 Problem: Determine if point (x,y,z) is inside or outside CVV? y= -1 x = -1 x = 1 Point (x,y,z) is inside CVV if (-1 <= x <= 1) and (-1 <= y <= 1) and (-1 <= z <= 1) else point is outside CVV CVV == 6 infinite planes (x= 1,1; y= 1,1; z= 1,1)

Determining if point is inside CVV y/w = 1 If point specified as (x,y,z,w) - Test (x/w, y/w, z/w)! x/w = -1 y/w = -1 x /w = 1 Point (x/w, y/w, z/w) is inside CVV if (-1 <= x/w <= 1) and (-1 <= y/w <= 1) and (-1 <= z/w <= 1) else point is outside CVV

Modify Inside/Outside Tests Slightly Our test: (-1 < x/w < 1) y/w = 1 Point (x,y,z,w) inside plane x = 1 if x/w < 1 => w x > 0 y/w = -1 x/w = -1 x /w = 1 Point (x,y,z,w) inside plane x = -1 if -1 < x/w => w + x > 0

Numerical Example: Inside/Outside CVV Test Point (x,y,z,w) is inside plane x=-1 if w+x > 0 inside plane x=1 if w x > 0-1 1 x/w Example Point (0.5, 0.2, 0.7) inside planes (x = -1,1) because - 1 <= 0.5 <= 1 If w = 10, (0.5, 0.2, 0.7) = (5, 2, 7, 10) Can either divide by w then test: 1 <= 5/10 <= 1 OR To test if inside x = - 1, w + x = 10 + 5 = 15 > 0 To test if inside x = 1, w - x = 10-5 = 5 > 0

3D Clipping Do same for y, z to form boundary coordinates for 6 planes as: Boundary coordinate (BC) Homogenous coordinate Clip plane Example (5,2,7,10) BC0 w+x x=-1 15 BC1 w-x x=1 5 BC2 w+y y=-1 12 BC3 w-y y=1 8 BC4 w+z z=-1 17 BC5 w-z z=1 3 Consider line that goes from point A to C Trivial accept: 12 BCs (6 for pt. A, 6 for pt. C) > 0 Trivial reject: Both endpoints outside (-ve) for same plane

Edges as Parametric Equations Implicit form F( x, y) 0 Parametric forms: points specified based on single parameter value Typical parameter: time t Some algorithms work in parametric form Clipping: exclude line segment ranges Animation: Interpolate between endpoints by varying t Represent each edge parametrically as A + (C A)t at time t=0, point at A at time t=1, point at C P t) P ( P P )* t 0 t 1 ( 0 1 0

Inside/outside? Test A, C against 6 walls (x=-1,1; y=-1,1; z=-1,1) There is an intersection if BCs have opposite signs. i.e. if either A is outside (< 0), C is inside ( > 0) or A inside (> 0), C outside (< 0) Edge intersects with plane at some t_hit between [0,1] A t = 0 t_hit C t = 1 A t = 0 t_hit C t = 1

Calculating hit time (t_hit) How to calculate t_hit? Represent an edge t as: Edge( t) (( Ax ( Cx Ax) t,( Ay ( Cy Ay) t,( Az ( Cz Az) t,( Aw ( Cw Aw) t) E.g. If x = 1, Solving for t above, Ax ( Cx Ax) t Aw ( Cw Aw) t 1 t Aw Ax ( Aw Ax) ( Cw Cx)

Inside/outside? t_hit can be entering (t_in) or leaving (t_out) Define: entering if A outside, C inside Why? As t goes [0 1], edge goes from outside (at A) to inside (at C) Define leaving if A inside, C outside Why? As t goes [0-1], edge goes from inside (at A) to inside (at C) Entering Leaving A t = 0 t_in C A t = 1 t = 0 t_out C t = 1

Chop step by Step against 6 planes Initially C t = 1 t_in = 0, t_out = 1 Candidate Interval (CI) = [0 to 1] A t = 0 Chop against each of 6 planes t_in = 0, t_out = 0.74 Candidate Interval (CI) = [0 to 0.74] A t = 0 t_out = 0.74 Plane y = 1 C Why t_out?

Chop step by Step against 6 planes Initially t_out = 0.74 C A t = 0 t_in = 0, t_out = 0.74 Candidate Interval (CI) = [0 to 0.74] Then Plane x = -1 t_in= 0.36 Why t_in? A t_out = 0.74 C t_in = 0.36, t_out = 0.74 Candidate Interval (CI) CI = [0.36 to 0.74]

Candidate Interval Candidate Interval (CI): time interval during which edge might still be inside CVV. i.e. CI = t_in to t_out Initialize CI to [0,1] For each of 6 planes, calculate t_in or t_out, shrink CI CI 0 1 t_in t_out t Conversely: values of t outside CI = edge is outside CVV

Shortening Candidate Interval Algorithm: Test for trivial accept/reject (stop if either occurs) Set CI to [0,1] For each of 6 planes: Find hit time t_hit If t_in, new t_in = max(t_in,t_hit) If t_out, new t_out = min(t_out, t_hit) If t_in > t_out => exit (no valid intersections) CI 0 t_in t_out 1 Note: seeking smallest valid CI without t_in crossing t_out t

Calculate choppped A and C If valid t_in, t_out, calculate adjusted edge endpoints A, C as A_chop = A + t_in ( C A) (calculate for Ax,Ay, Az) C_chop = A + t_out ( C A) (calculate for Cx,Cy,Cz) CI 0 A_chop C_chop 1 t_in t_out t

3D Clipping Implementation Function clipedge( ) Input: two points A and C (in homogenous coordinates) Output: 0, if AC lies complete outside CVV 1, complete inside CVV Returns clipped A and C otherwise Calculate 6 BCs for A, 6 for C A C ClipEdge () 0 1 A_chop, C_chop

Store BCs as Outcodes Use outcodes to track in/out Number walls x = +1, 1; y = +1, 1, and z = +1, 1 as 0 to 5 Bit i of A s outcode = 1 if A is outside ith wall 1 otherwise Example: outcode for point outside walls 1, 2, 5 Wall no. OutCode 0 1 2 3 4 5 0 1 1 0 0 1

Trivial Accept/Reject using Outcodes Trivial accept: inside (not outside) any walls Wall no. A Outcode C OutCode 0 1 2 3 4 5 0 0 0 0 0 0 0 0 0 0 0 0 Logical bitwise test: A C == 0 Trivial reject: point outside same wall. Example Both A and C outside wall 1 Wall no. A Outcode C OutCode 0 1 2 3 4 5 0 1 0 0 1 0 0 1 1 0 0 0 Logical bitwise test: A & C!= 0

3D Clipping Implementation Compute BCs for A,C store as outcodes Test A, C outcodes for trivial accept, trivial reject If not trivial accept/reject, for each wall: Compute thit Update t_in, t_out If t_in > t_out, early exit

3D Clipping Pseudocode int clipedge(point4& A, Point4& C) { double tin = 0.0, tout = 1.0, thit; double abc[6], cbc[6]; int aoutcode = 0, coutcode = 0;..find BCs for A and C..form outcodes for A and C if((aoutcode & coutcode)!= 0) // trivial reject return 0; if((aoutcode coutcode) == 0) // trivial accept return 1;

3D Clipping Pseudocode for(i=0;i<6;i++) // clip against each plane { if(cbc[i] < 0) // C is outside wall i (exit so tout) { thit = abc[i]/(abc[i] cbc[i]); // calculate thit tout = MIN(tOut, thit); } else if(abc[i] < 0) // A is outside wall I (enters so tin) { thit = abc[i]/(abc[i] cbc[i]); // calculate thit tin = MAX(tIn, thit); } if(tin > tout) return 0; // CI is empty: early out } Aw Ax t ( Aw Ax) ( Cw Cx)

3D Clipping Pseudocode Point4 tmp; // stores homogeneous coordinates If(aOutcode!= 0) // A is outside: tin has changed. Calculate A_chop { tmp.x = A.x + tin * (C.x A.x); // do same for y, z, and w components } If(cOutcode!= 0) // C is outside: tout has changed. Calculate C_chop { C.x = A.x + tout * (C.x A.x); // do same for y, z and w components } A = tmp; Return 1; // some of the edges lie inside CVV }

Polygon Clipping Not as simple as line segment clipping Clipping a line segment yields at most one line segment Clipping a polygon can yield multiple polygons Clipping a convex polygon can yield at most one other polygon 24

Clipping Polygons Need more sophisticated algorithms to handle polygons: Sutherland Hodgman: any a given polygon against a convex clip polygon (or window) Weiler Atherton: Both subject polygon and clip polygon can be concave

Tessellation and Convexity One strategy is to replace nonconvex (concave) polygons with a set of triangular polygons (a tessellation) Also makes fill easier 26

References Angel and Shreiner, Interactive Computer Graphics, 6 th edition Hill and Kelley, Computer Graphics using OpenGL, 3 rd edition