+ All Categories
Home > Documents > 18.clipping1 - Clarkson University · Cohen-Sutherland Clipping ! Liang-Barsky Clipping ! There are...

18.clipping1 - Clarkson University · Cohen-Sutherland Clipping ! Liang-Barsky Clipping ! There are...

Date post: 24-May-2020
Category:
Upload: others
View: 3 times
Download: 0 times
Share this document with a friend
35
CS452/552; EE465/505 Clipping & Scan Conversion 3-26–15
Transcript

CS452/552; EE465/505

Clipping & Scan Conversion

3-26–15

! Return & Review Midterm Exam ! From Geometry to Pixels: Clipping & Scan conversion

Read: ✦Angel, Chapter 8, 8.1 - 8.4

Project#1 due: Friday, Mar. 27th Lab4 due: next week

Outline

! Framebuffer Objects (FBOs) are buffers that are created by the application Not under control of window system Cannot be displayed Can attach a renderbuffer to a FBO and can render off screen into the attached buffer Attached buffer can then be detached and used as a texture map for an on-screen render to the default frame buffer

Recap: Framebuffer Objects and Render to Texture

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

! Iterative calculations can be accomplished using multiple render buffers

!Original data in texture buffer 1 ! Render to texture buffer 2 ! Swap buffers and rerender to texture

Buffer Ping-ponging

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

! Examine what happens between the vertex shader and the fragment shader

! Introduce basic implementation strategies !Clipping (continued from last week) ! Rendering

✦lines ✦polygons

Rendering Overview

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

From Geometry to Pixels! At end of the geometric pipeline, vertices have been assembled into primitives

! Must clip out primitives that are outside the view frustum ■ Algorithms based on representing primitives by lists of vertices

! Must find which pixels can be affected by each primitive ■ Fragment generation ■ Rasterization or scan conversion

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

Required Tasks! Clipping ! Rasterization or scan conversion ! Transformations ! Some tasks deferred until fragment processing

■ Hidden surface removal ■ Antialiasing

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

! Any rendering method must process every object and must assign a color to every pixel

! Think of rendering algorithms as two loops ✦over objects ✦over pixels

! The order of these loops defines two strategies ✦ image oriented ✦object oriented

Rasterization Meta Algorithms

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

! For every object, determine which pixels it covers and shade these pixels

✦Pipeline approach ✦Must keep track of depths for HSR ✦Cannot handle most global lighting calculations ✦Need entire framebuffer available at all times

Object Space Approach

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

! For every pixel, determine which object that projects on the pixel is closest to the viewer and compute the shade of this pixel

✦Ray tracing paradigm ✦Need all objects available

! Patch Renderers ✦Divide framebuffer into small patches ✦Determine which objects affect each patch ✦Used in limited power devices such as cell phones

Image Space Approach

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

!Clipping lines ! First of implementation algorithms !Clipping polygons (later) ! Focus on pipeline plus a few classic algorithms

Clipping

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

Clipping! 2D against clipping window ! 3D against clipping volume ! Easy for line segments polygons ! Hard for curves and text

■ Convert to lines and polygons first

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

! General case of frustum (truncated pyramid)

! Clipping is tricky because of frustum shape

Clipping against a Frustum

! Solution: ■ implement perspective projection by perspective normalization and orthographic projection

■ perspective normalization is a homogeneous transformation

Perspective Normalization

Clipping Against Rectangle in 2D! Line-segment clipping: modify endpoints of lines to lie within clipping rectangle

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

Clipping Against Rectangle in 2D! The result (in red)

Clipping Against Rectangle in 2D! Could calculate intersections of line segments with clipping rectangle ■ expensive, due to floating point multiplications and divisions => minimize the number of * and /

! Main motivation: ■ avoid expensive line-rectangle intersections (which require floating-point divisions)

! Cohen-Sutherland Clipping ! Liang-Barsky Clipping ! There are many more (but many only work

in 2D)

Several practical algorithms for clipping

! Clipping rectangle is an intersection of 4 half-planes

! Encode results of 4 half-plane tests ! Generalizes to 3 dimensions (6 half-planes)

Cohen-Sutherland Clipping

Cohen-Sutherland Algorithm! Idea: eliminate as many cases as possible without computing intersections

! Start with four lines that determine the sides of the clipping window

x = xmaxx = xmin

y = ymax

y = ymin

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

! Divide space into 9 regions ! 4-bit outcode determined by comparisons

Outcodes (Cohen-Sutherland)

! Outcomes: accept, reject, subdivide

Cases for outcodes

The Cases! Case 1: both endpoints of line segment inside all four lines ■ Draw (accept) line segment as is

! Case 2: both endpoints outside all lines and on same side of a line ■ Discard (reject) the line segment

x = xmaxx = xmin

y = ymax

y = ymin

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

The Cases! Case 3: One endpoint inside, one outside

■ Must do at least one intersection

! Case 4: Both outside ■ May have part inside ■ Must do at least one intersection

x = xmaxx = xmin

y = ymax

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

Defining Outcodes! For each endpoint, define an outcode

! Outcodes divide space into 9 regions ! Computation of outcode requires at most 4 subtractions

b0b1b2b3

b0 = 1 if y > ymax, 0 otherwise b1 = 1 if y < ymin, 0 otherwise b2 = 1 if x > xmax, 0 otherwise b3 = 1 if x < xmin, 0 otherwise

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

Using Outcodes! Consider the 5 cases below ! AB: outcode(A) = outcode(B) = 0

■ Accept line segment

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

Using Outcodes! CD: outcode (C) = 0, outcode(D) ≠ 0

■ Compute intersection ■ Location of 1 in outcode(D) determines which edge to intersect with

■ Note if there were a segment from A to a point in a region with 2 ones in outcode, we might have to do two intersections

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

Using Outcodes! EF: outcode(E) logically ANDed with outcode(F) (bitwise) ≠ 0 ■ Both outcodes have a 1 bit in the same place ■ Line segment is outside of corresponding side of clipping window

■ reject

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

Using Outcodes! GH and IJ: same outcodes, neither zero but

logical AND yields zero ! Shorten line segment by intersecting with one of

sides of window ! Compute outcode of intersection (new endpoint of

shortened line segment) ! Re-execute algorithm

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

! Pick outside endpoint (o ≠ 0000) ! Pick a crossed edge (o = b1b2b3b4 and bk ≠ 0) ! Compute intersection of this line and this edge ! Replace endpoint with intersection point ! Restart with new line segment

■ outcodes of second point are unchanged ! The algorithm converges

Cohen-Sutherland Subdivision

! In many applications, the clipping window is small relative to the size of the entire data base Most line segments are outside one or more side of the window and can be eliminated based on their outcodes

! Inefficiency when code has to be reexecuted for line segments that must be shortened in more than one step

Efficiency

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

! Use 6-bit outcodes !When needed, clip line segment against planes

Cohen Sutherland in 3D

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

!General clipping in 3D requires intersection of line segments against arbitrary plane

! Example: oblique view

Clipping and Normalization

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

Plane-Line Intersections

)()(

12

1

ppnppn

a o

−•

−•=

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

Normalized Form

before normalization after normalization

Normalization is part of viewing (pre clipping) but after normalization, we clip against sides of

right parallelepiped

Typical intersection calculation now requires only a floating point subtraction, e.g. is x > xmax ?

top view

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


Recommended