1 of 37

Nima Kalantari

CSCE 441 - Computer Graphics

Culling, Clipping, and Viewport

Some slides from Scott Schaefer and Pradeep Sen

2 of 37

So far

Normalized Device Coordinates (NDC)

3 of 37

Outline

  • View volume culling
    • Clipping
  • Backface culling
  • Viewport

4 of 37

View Volume Culling

Normalized Device Coordinates (NDC)

5 of 37

View Volume Culling

  • Objects have thousands of triangles
    • Time-consuming to check each triangle

Normalized Device Coordinates (NDC)

Thousands of

Triangles

6 of 37

View Volume Culling

  • Check the bounding sphere against all the six planes

Normalized Device Coordinates (NDC)

7 of 37

View Volume Culling

  • Check the bounding sphere against all the six planes

Normalized Device Coordinates (NDC)

r

c

z

Z = -1

n

p

outside frustum

8 of 37

View Volume Culling

  • Worth doing if the scene is big and only a small portion of the it is inside the view volume (frustum)

9 of 37

View Volume Culling

  • What if only part of the object is inside?
    • Some triangles inside (accept)
    • Some triangles outside (reject)
    • Some triangles intersect the plane (clipping)

Normalized Device Coordinates (NDC)

10 of 37

Outline

  • View volume culling
    • Clipping
  • Backface culling
  • Viewport

11 of 37

Clipping

12 of 37

Triangle Clipping Algorithm

13 of 37

Clipping Space

  • Should we perform the clipping in NDC?

14 of 37

Clipping

z

x

y

z

near

far

far (+1)

near (-1)

Camera Coordinate

NDC

15 of 37

Clipping

x

y

z

near

far

far (+1)

near (-1)

Camera Coordinate

NDC

16 of 37

Clipping

x

y

z

near

far

far (+1)

near (-1)

Camera Coordinate

NDC

17 of 37

Clipping

x

y

z

near

far

far (+1)

near (-1)

Camera Coordinate

NDC

18 of 37

Clipping

  • Done before perspective division (in clip space)
  • Clip triangles against each plane in clip space
    • x = +w
    • x = -w
    • y = +w
    • y = -w
    • z = +w
    • z = -w

19 of 37

Clipping Equation

20 of 37

Triangle Clipping Algorithm

21 of 37

Triangle Clipping Algorithm

22 of 37

Triangle Clipping Algorithm

23 of 37

Triangle Clipping Algorithm

24 of 37

Triangle Clipping Algorithm

25 of 37

Four cases for each plane

  • All vertices outside
    • Cull triangle
  • One vertex outside
    • Break to two
    • Clip against the next plane
  • Two vertices outside
    • Break to one triangle
    • Clip against the next plane
  • All vertices inside
    • Clip against the next plane

26 of 37

Summary

  • At the end of clipping all vertices are
    • -w ≤ x, y, z ≤ w

27 of 37

Outline

  • View volume culling
    • Clipping
  • Backface culling
  • Viewport

28 of 37

Backface Culling

29 of 37

Backface Culling

30 of 37

Backface Culling

31 of 37

Backface Culling

view direction

32 of 37

Backface Culling

view direction

, draw triangle

33 of 37

Backface Culling

view direction

, cull triangle

34 of 37

Outline

  • View volume culling
    • Clipping
  • Backface culling
  • Viewport

35 of 37

Screen

  • Array of pixels [width × height]
  • Index of pixels
    • x-direction: 0 to width – 1
    • y-direction: 0 to height - 1
  • Pixels are located at (x + 0.5, y + 0.5)

36 of 37

Viewport

  • Transformation from NDC to screen
  • Mapping x values from [-1, +1] to [0, width]
  • Mapping y values from [-1, +1] to [0, height]

37 of 37

Coordinate spaces

Modelview matrix

Projection matrix

Clipping

Homogenize

Viewport Transform

Rasterization

screen-space coordinates

normalized device coordinates (NDC)

object space coordinates

eye space coordinates

clip-space coordinates

coordinates of the vertices of the objects

eye at origin, facing –z, +x is right, +y is up

vertices are now:

0 < x < screen width

0 < y < screen height

vertices are now (xc, yc, zc, wc)

all vertices are now from -1 to 1