1 3 D Clipping 3 D Clipping Represent edge param et rically as - - PDF document

1
SMART_READER_LITE
LIVE PREVIEW

1 3 D Clipping 3 D Clipping Represent edge param et rically as - - PDF document

3 D Clipping CS 4 7 3 1 : Com put e r Gr a phics Le ct u r e 1 4 : 3 D Clippin g a n d Vie w por t Tr a n sf or m a t ion Em m anuel Agu Clipping occur s a ft e r pr oj e ct ion t r a nsfor m a t ion Clipping is a ga inst ca nonica


slide-1
SLIDE 1

1

CS 4 7 3 1 : Com put e r Gr a phics Le ct u r e 1 4 : 3 D Clippin g a n d Vie w por t Tr a n sf or m a t ion Em m anuel Agu

3 D Clipping

Clipping occur s a ft e r pr oj e ct ion t r a nsfor m a t ion Clipping is a ga inst ca nonica l vie w volum e

3 D Clipping

  • 3D clipping against canonical view volum e (CVV)
  • Autom atically clipping after projection m atrix
  • Liang- Barsky algorithm (em bellished by Blinn)
  • CVV = = 6 infinite planes (x= - 1,1; y= - 1,1; z= - 1,1)
  • Clip edge- by- edge of the an object against CVV
  • Chopping m ay change num ber of sides of an object. E.g.

chopping tip of triangle m ay create quadrilateral

3 D Clipping

  • Problem:
Two point s, A = ( Ax, Ay, Az, Aw ) and C = ( Cx, Cy, Cz, Cw ),

in hom ogeneous coordinates

I f segm ent int ersect s wit h CVV, need t o com put e

intersection point I -= (I x, Iy, I z, I w )

slide-2
SLIDE 2

2

3 D Clipping

  • Represent edge param et rically as A + ( C – A)t
  • I ntepretation : a point is t raveling such t hat :
at t im e t = 0, point at A at t im e t = 1, point at C
  • Lik e Cohen-Sut herland, first det erm ine t rivial accept / rej ect
  • E.g. t o t est edge against plane, point is:
I nside (right of plane x= - 1) if Ax/ Aw > -1 or ( Aw + Ax) > 0 I nside ( left of plane x= 1) if Ax/ Aw < 1 or ( Aw -Ax ) > 0
  • 1

1 Ax/ Aw

3 D Clipping

  • Using not at ion ( Aw + Ax) = w + x, writ e boundary coordinat es

for 6 planes as: z= 1 w-z BC5 z= -1 w+ z BC4 y= 1 w-y BC3 y= -1 w+ y BC2 x= 1 w-x BC1 x= -1 w+ x BC0 Clip plane Homogenous coordinate Boundary coordinate ( BC) Trivia l a ccept : 12 BCs ( 6 for pt . A, 6 for pt . C) are posit ive Trivial rej ect: Bot h endpoint s out side of sam e plane

3 D Clipping

  • I f not trivial accept/ rej ect, then clip
  • Define Candidat e I nt erval ( CI ) as t im e int erval during which

edge m ight st ill be inside CVV. i.e. CI = t _in t o t _out

  • Conversely: values of t out side CI = edge is out side CVV
  • I nit ialize CI t o [ 0,1]

1 t t_in t_out

CI 3 D Clipping

  • How t o calculat e t _hit ?
  • Represent an edge t as:
  • E.g. I f x = 1,
  • Solving for t above,

1 ) ( ) ( = − + − + t Aw Cw Aw t Ax Cx Ax ) ( ) ( Cx Cw Ax Aw Ax Aw t − − − − =

) ) ( ( , ) ( ( , ) ( ( , ) ( (( ) ( t Aw Cw Aw t Az Cz Az t Ay Cy Ay t Ax Cx Ax t Edge − + − + − + − + =

slide-3
SLIDE 3

3

3 D Clipping

  • Test against each wall in t urn
  • I f BCs have opposit e signs = edge hit s plane at t im e t _hit
  • Define: “ ent ering” = as t increases, out side t o inside
  • i.e. if pt . A is out side, C is inside
  • Likewise, “ leaving” = as t increases, inside t o out side ( A inside,

C out side)

3 D Clipping

  • Algorithm :
Test for t rivial accept / rej ect ( st op if eit her occurs) Set CI t o [ 0,1] For each of 6 planes: Find hit t im e t _hit I f, as t increases, edge ent ering, t _in = m ax( t _in,t _hit ) I f, as t increases, edge leaving, t _out = m in( t _out , t _hit ) I f t _in > t _out = > exit ( no valid int ersect ions)

N ot e : seeking sm allest valid CI wit hout t _in crossing t _out

3 D Clipping

Exam ple t o illust rat e search for t _in, t _out N ot e : CVV is different shape. This is j ust exam ple

3 D Clipping

  • I f valid t _in, t _out , calculat e adj ust ed edge endpoint s A, C as
  • A_chop = A + t _in ( C – A)
  • C_ chop = C + t _ out ( C – A )
slide-4
SLIDE 4

4

3 D Clipping I m plem entation

  • Funct ion clipEdge( )
  • I nput : t wo point s A and C ( in hom ogenous coordinat es)
  • Output:
0, if no part of line AC lies in CVV 1, otherwise Also returns clipped A and C
  • Store 6 BCs for A, 6 for C

3 D Clipping I m plem entation

  • Use outcodes t o t rack in/ out
Number walls 1…

6

Bit i of A’s outcode = 0 if A is inside it h wall 1 otherwise
  • Trivial accept : bot h A and C
  • ut codes = 0
  • Trivial rej ect : bit wise AND of A and C
  • ut codes is n on-zero
  • I f not trivial accept/ reject:
Compute tHit Update t_in, t_out If t_in > t_out, early exit

3 D Clipping Pseudocode

int clipEdge( Point4& A, Point4& C) { double tI n = 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;

3 D Clipping Pseudocode

for( i= 0;i< 6;i+ + ) / / clip against each plane { if( cBC[ I ] < 0) / / exits: C is outside { tHit = aBC[ I ] / (aBC[ I ] – cBC[ I ] ) ; tOut = MI N( tOut, tHit); } else if( aBC[ i] < 0 ) / / enters: A is outside { tHit = aBC[ i] / (aBC[ i] – cBC [ i] ) ; tI n = MAX( tI n, tHit); } if( tI n > tOut) return 0; / / CI is em pty: early out }

slide-5
SLIDE 5

5

3 D Clipping Pseudocode

Point4 tmp ; / / stores homogeneous coordinates I f( aOutcode != 0) / / A is out: tI n has changed { tmp .x = A.x + tI n * ( C.x – A.x) ; / / do sam e for y, z, and w com ponents } I f( cOutcode != 0 ) / / C is out: tOut has changed { C.x = A.x + tOut * ( C.x – A.x); / / do sam e for y, z and w com ponents } A = tmp ; Return 1; / / som e of the edges lie inside CVV }

View port Transform ation

  • After clipping, do viewport t ransform at ion
  • We have used glViewport ( x,y, w id, ht) before
  • Use again here! !
  • glViewport shift s x, y t o screen coordinat es
  • Also m aps pseudo -dept h z fr om r ange [ - 1,1] to [ 0,1]
  • Pseudo- dept h st ored in dept h buffer, used for Dept h t est ing ( Will

discuss later)

References

  • Hill, sections 7.4.4, 4.8.2