subodh kumar dept of computer sc. & engg. iit delhi › ~subodh › courses › csl781 ›...

27
Computer Graphics Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi

Upload: others

Post on 09-Jun-2020

18 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi › ~subodh › courses › CSL781 › pdfslides › clipping.… · Computer Graphics Subodh Kumar Dept of Computer Sc. & Engg

Computer Graphics

Subodh Kumar

Dept of Computer Sc. & Engg. IIT Delhi

Page 2: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi › ~subodh › courses › CSL781 › pdfslides › clipping.… · Computer Graphics Subodh Kumar Dept of Computer Sc. & Engg

Geometry Shader

Graphics PipelineVertex

Vertex Shader

Framebuffer

Clip & Setup

Rasterize Fragment Shader

Raster OPs

Primitive Assembly

Texture

Blend

Picture

Connectivity Textures

Tessellation

Page 3: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi › ~subodh › courses › CSL781 › pdfslides › clipping.… · Computer Graphics Subodh Kumar Dept of Computer Sc. & Engg

Geometry Shader

Graphics PipelineVertex

Vertex Shader

Framebuffer

Clip & Setup

Rasterize Fragment Shader

Raster OPs

Primitive Assembly

Texture

Blend

Picture

Connectivity Textures

Tessellation

Page 4: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi › ~subodh › courses › CSL781 › pdfslides › clipping.… · Computer Graphics Subodh Kumar Dept of Computer Sc. & Engg

Geometry Shader

Graphics PipelineVertex

Vertex Shader

Framebuffer

Clip & Setup

Rasterize Fragment Shader

Raster OPs

Primitive Assembly

Texture

Blend

Picture

Connectivity Textures

Tessellation

Page 5: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi › ~subodh › courses › CSL781 › pdfslides › clipping.… · Computer Graphics Subodh Kumar Dept of Computer Sc. & Engg

Fragments

Page 6: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi › ~subodh › courses › CSL781 › pdfslides › clipping.… · Computer Graphics Subodh Kumar Dept of Computer Sc. & Engg

Clipping

Page 7: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi › ~subodh › courses › CSL781 › pdfslides › clipping.… · Computer Graphics Subodh Kumar Dept of Computer Sc. & Engg

Clipping

Page 8: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi › ~subodh › courses › CSL781 › pdfslides › clipping.… · Computer Graphics Subodh Kumar Dept of Computer Sc. & Engg

Clipping

x=-1 x= 1

Page 9: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi › ~subodh › courses › CSL781 › pdfslides › clipping.… · Computer Graphics Subodh Kumar Dept of Computer Sc. & Engg

Line Clipping

! Find intersection with all boundaries ! Upto 2 possible

! Replace one end point with the intersection point ! Intersection closest to the vertex

Page 10: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi › ~subodh › courses › CSL781 › pdfslides › clipping.… · Computer Graphics Subodh Kumar Dept of Computer Sc. & Engg

Clip Space

! Transform to Normalized Image space ! Clip against -1 ≤ X,Y ≤ 1 ! ⇒ -1 ≤ X/w,Y/w ≤ 1 per vertex

! Similarly Z ! ⇒ 0 ≤ Z/w ≤ 1 (near ➔ 0, far ➔ 1)

! Clip in 3D? ! 3D frustum in object space ! Camera space

! Homogeneous space clipping ! -w <= X,Y <= w

Page 11: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi › ~subodh › courses › CSL781 › pdfslides › clipping.… · Computer Graphics Subodh Kumar Dept of Computer Sc. & Engg

Find Intersection

! Simultaneous equations: ! ax+by+c=0 ! dx+ey+f=0

! But (x, y) must be between end-points ! Alternative, use parametric equations

! x0 + (x1-x0)t = x2 + (x3-x2) u

! y0 + (y1-y0)t = y2 + (y3-y2) u

! t and u must be in [0:1]

Page 12: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi › ~subodh › courses › CSL781 › pdfslides › clipping.… · Computer Graphics Subodh Kumar Dept of Computer Sc. & Engg

Cyrus-Beck Clipping

! Can we reduce the number of intersection computations?

! Can we quicky reject a few potential intersections?

Page 13: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi › ~subodh › courses › CSL781 › pdfslides › clipping.… · Computer Graphics Subodh Kumar Dept of Computer Sc. & Engg

Classify Intersections

! P0 P1 . N < 0 => entering boundary

! P0 P1 . N > 0 => leaving boundary

! P0 P1 . N = 0 => straddling boundary

N

P0

P1

Page 14: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi › ~subodh › courses › CSL781 › pdfslides › clipping.… · Computer Graphics Subodh Kumar Dept of Computer Sc. & Engg

Classify Intersections

! P0 P1 . N < 0 => entering boundary

! P0 P1 . N > 0 => leaving boundary

! P0 P1 . N = 0 => straddling boundary

N

P0

P1

For convex window: Find last entering and first leaving

Page 15: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi › ~subodh › courses › CSL781 › pdfslides › clipping.… · Computer Graphics Subodh Kumar Dept of Computer Sc. & Engg

Intersection Computation

N

P0

P1

P[Liang-Barsky]

Page 16: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi › ~subodh › courses › CSL781 › pdfslides › clipping.… · Computer Graphics Subodh Kumar Dept of Computer Sc. & Engg

Intersection Computation

N

P0

P1

P

Pb

[Liang-Barsky]

Page 17: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi › ~subodh › courses › CSL781 › pdfslides › clipping.… · Computer Graphics Subodh Kumar Dept of Computer Sc. & Engg

Intersection Computation

! P Pb . N = 0 ! (P-Pb) . N = 0

! [P0 + (P1-P0)t - Pb] . N = 0

! (P1-P0).N t = (Pb-P0).N

! t = (Pb-P0).N / (P1-P0).N ! If N = +- [0,1] or [1,0]?

! If Pb is a corner? N

P0

P1

P

Pb

[Liang-Barsky]

Page 18: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi › ~subodh › courses › CSL781 › pdfslides › clipping.… · Computer Graphics Subodh Kumar Dept of Computer Sc. & Engg

Intersection Computation

! P Pb . N = 0 ! (P-Pb) . N = 0

! [P0 + (P1-P0)t - Pb] . N = 0

! (P1-P0).N t = (Pb-P0).N

! t = (Pb-P0).N / (P1-P0).N ! If N = +- [0,1] or [1,0]?

! If Pb is a corner? N

P0

P1

P

Pb

[Liang-Barsky]

What happens in 3D?

Page 19: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi › ~subodh › courses › CSL781 › pdfslides › clipping.… · Computer Graphics Subodh Kumar Dept of Computer Sc. & Engg

Triangle Clipping

Page 20: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi › ~subodh › courses › CSL781 › pdfslides › clipping.… · Computer Graphics Subodh Kumar Dept of Computer Sc. & Engg

Clip Against Each Boundary

! Could triangulate now !

Page 21: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi › ~subodh › courses › CSL781 › pdfslides › clipping.… · Computer Graphics Subodh Kumar Dept of Computer Sc. & Engg

Clip Against Each Boundary

! Could triangulate now !

Page 22: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi › ~subodh › courses › CSL781 › pdfslides › clipping.… · Computer Graphics Subodh Kumar Dept of Computer Sc. & Engg

Clip Against Each Boundary

! Clip against the next boundary ! And so on..

Page 23: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi › ~subodh › courses › CSL781 › pdfslides › clipping.… · Computer Graphics Subodh Kumar Dept of Computer Sc. & Engg

Clipping General Polygons

Page 24: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi › ~subodh › courses › CSL781 › pdfslides › clipping.… · Computer Graphics Subodh Kumar Dept of Computer Sc. & Engg

Clipping General Polygons

Page 25: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi › ~subodh › courses › CSL781 › pdfslides › clipping.… · Computer Graphics Subodh Kumar Dept of Computer Sc. & Engg

Clipping General Polygon

! Clip against each boundary ! Traverse Polygon for each boundary

! If In " In ! Output new vertex

! If In " Out ! Output intersection point ! Output new vertex

! If Out " In ! Output Intersection point

[Sutherland-Hodgeman]

Page 26: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi › ~subodh › courses › CSL781 › pdfslides › clipping.… · Computer Graphics Subodh Kumar Dept of Computer Sc. & Engg

Clipping General Polygon

! Clip against each boundary ! Traverse Polygon for each boundary

! If In " In ! Output new vertex

! If In " Out ! Output intersection point ! Output new vertex

! If Out " In ! Output Intersection point

[Sutherland-Hodgeman]Tes

t Triv

ial R

eject/

Accep

t Firs

t!

Page 27: Subodh Kumar Dept of Computer Sc. & Engg. IIT Delhi › ~subodh › courses › CSL781 › pdfslides › clipping.… · Computer Graphics Subodh Kumar Dept of Computer Sc. & Engg

Clipping Vertex Attributes

t

a0

a1at = (1-t)a0 + t a1