1 of 32

Texturing, culling

Instructor: Christopher Rasmussen (cer@cis.udel.edu)

April 13, 2021 ❖ Lecture 15

2 of 32

Outline

  • Texturing: Rasterization details
  • Culling non-visible surfaces
    • Viewing volume: Clipping
    • Backface, occlusion: next time...

3 of 32

Texture mapping: Steps

  • Creation: Where does the texture image come from?
  • Geometry: Transformation from 3-D shape locations to 2-D texture image coordinates
  • Rasterization: What to draw at each pixel (since texture coords. are floats)
    • E.g., bilinear interpolation vs. nearest-neighbor

4 of 32

Texture mapping: Steps

  • Creation: Where does the texture image come from?
  • Geometry: Transformation from 3-D shape locations to 2-D texture image coordinates
  • Rasterization: What to draw at each pixel (since texture coords. are floats)
    • E.g., bilinear interpolation vs. nearest-neighbor

5 of 32

Texture mapping: Rasterization issue

6 of 32

Texture mapping: Rasterization issue

7 of 32

Texture mapping: Rasterization issue

Take "nearest neighbor" texel color or some kind of blend of surrounding texels?

8 of 32

Linear Interpolation (aka lerp)

  • Parametric definition of a line segment:

p(t) = p0 + t(p1 - p0), where t in [0, 1]

= p0 - t p0 + t p1

= (1 - t)p0 + t p1

from Akenine-Möller & Haines

like a “blend” of

the two endpoints

= lerp(p0, p1, t)

9 of 32

Bilinear interpolation for LIGHTING

m = lerp(mleft, mright, t)

mleft= lerp(m3, m4, tleft)

mright= lerp(m1, m2, tright)

10 of 32

dest

I = texture image, Idest = image we are rendering

11 of 32

Rasterization: Magnification and minification

  • Magnification: Single screen pixel maps to area less than or equal to one texel

Magnification

Minification

from Angel

courtesy of H. Pfister

12 of 32

Rasterization: Magnification and minification

  • Magnification: Single screen pixel maps to area less than or equal to one texel
  • Minification: Single screen pixel area maps to area greater than one texel
    • If texel area covered is much greater than 4, even bilinear filtering isn’t so great

Magnification

Minification

from Angel

courtesy of H. Pfister

13 of 32

Filtering for minification

  • Aliasing problem much like line rasterization
    • Pixel maps to quadrilateral (pre-image) in texel space

image courtesy of D. Cohen-Or

14 of 32

Supersampling: Using more than BLI’s 4 texels

  • Rasterize at higher resolution
    • Regular grid pattern around each “normal” image pixel
    • Irregular jittered sampling pattern reduces artifacts
  • Combine multiple samples into one pixel via weighted average
    • “Box” filter: All samples associated with a pixel have equal weight (i.e., directly take their average)
    • Gaussian/cone filter: Sample weights inversely proportional to distance from associated pixel

from Hill

Regular supersampling

with 2x frequency

Jittered supersampling

15 of 32

Mipmaps

  • Filtering for minification is expensive, and different areas must be averaged depending on the amount of minification
  • Idea:
    • Prefilter entire texture image at different resolutions
    • For each screen pixel, pick texture in mipmap at level of detail (LOD) that minimizes minification (i.e., pre-image area closest to 1)
    • Do nearest or linear filtering in appropriate LOD texture image, or across levels

from Woo, et al.

16 of 32

Clipping

courtesy of L. McMillan

17 of 32

Clipping

courtesy of L. McMillan

18 of 32

Clipping

  • Removal of portions of geometric primitives outside viewing volume (VV)
  • Why?
    • Optimization that saves computation which would otherwise be wasted on lighting, texturing, etc.
  • Cases
    • Trivial acceptance: Complete inside VV
    • Trivial rejection: Completely outside VV
    • Crossing clip plane(s): Partially outside, so must trim to fit
  • Different primitives require different methods
    • Points: Only trivial accept/reject
    • Lines: Chop at intersection with clip plane
    • Polygons: Must trim so as to maintain connectivity

courtesy of L. McMillan

19 of 32

Geometry pipeline

Coordinate change rigid transform

(View)

Perspective transformation

(and orthographic scaling)

(Projection)

2-D scale and shift

(Viewport)

Perspective division

Orthographic projection

Camera coordinates

Clip coordinates

Normalized device coordinates (CVV)

Window coordinates

Screen coordinates (pixels)

World coordinates

Model coordinates

Coordinate change rigid transform

(Model)

20 of 32

When to clip?

  • The earlier in the pipeline invisible primitives are removed, the less computation is wasted on them
  • However...difficulty of clipping problem depends on stage of geometry pipeline
    • Camera coordinates: VV is a frustum, so clip planes are angled (dot product necessary for inside/outside (IO) test)
    • Clip coordinates: CVV is an axis-aligned box (cube with corners at ±1 after perspective division), so clip planes are simple (IO test is simple greater-than/less-than comparison)
    • NDC: Perspective division destroys true sign of point’s z---can’t distinguish between point at (x, y, z) and one at (-x, -y, -z). This allows points behind eye to be erroneously displayed
    • Screen coordinates: Simple, but too late—nearly all of the work has already been done

21 of 32

Clipping: Basic issues

  • Testing which side of a clip plane a point is on
    • Which side of a line in 2-D
  • How to trim primitives that span VV border
    • Find the intersection of a line segment and a clip plane

from E. Angel

22 of 32

Cohen-Sutherland 2-D line clipping (not in textbook)

  • Idea: Consider rectangle (the “viewing area” (VA)) as intersection of 4 half-planes defined by sides

VA

xmin

xmax

ymax

ymin

adapted from F. Pfenning

y < ymax

y > ymin

x > xmin

x < xmax

=

23 of 32

Cohen-Sutherland clipping: Outcodes

  • Test a line endpoint p = (x, y) against each of 4 half-planes and record whether it is outside the half-plane or not (T or F)
  • These four T/F bits are p’s outcode o(p)

from Hill

24 of 32

Cohen-Sutherland clipping

  • Outcodes partition plane around the viewing area
  • Trivial line clipping cases
    • Accept line (p1, p2): Both endpoints are inside the rectangle
      • In terms of outcodes, this means o(p1) = FFFF and o(p2) = FFFF
    • Reject line: Both endpoints outside rectangle on same side
      • This means both points’ outcodes have a T at the same bit position—e.g., o(p1) = FTTF and o(p2) = FFTF

from Hill

25 of 32

Cohen-Sutherland clipping

  • Tougher cases are what’s left

  • Basic idea: Subdivide non-trivial lines by sequentially removing (aka clipping) portions outside rectangle edge lines until what’s left is trivial
    • Arbitrary order: Left, right, bottom, top

adapted from E. Angel

26 of 32

Cohen-Sutherland: Algorithm

compute outcodes

compute intersection

27 of 32

Computing the intersection point

  • What is c = (cx, cy)?

adapted from Hill

Δx

Δy

c

a

b

xmin

xmax

ymax

ymin

28 of 32

Computing the intersection point

  • What is c = (cx, cy)?
    • Obviously, in this case cx = xmax and cy = ay - d

adapted from Hill

Δx

Δy

c

a

b

xmin

xmax

ymax

ymin

29 of 32

Computing the intersection point

  • What is c = (cx, cy)?
    • Obviously, in this case cx = xmax and cy = ay - d
    • Noting that e = ax - xmax and e/Δx = d/Δy , we can compute d = e Δy/Δx and obtain cy

adapted from Hill

Δx

Δy

c

a

b

xmin

xmax

ymax

ymin

30 of 32

Computing the intersection point

  • What is c = (cx, cy)?
    • Obviously, in this case cx = xmax and cy = ay - d
    • Noting that e = ax - xmax and e/Δx = d/Δy , we can compute d = e Δy/Δx and obtain cy
  • A similar approach works for the other clip lines

adapted from Hill

Δx

Δy

c

a

b

xmin

xmax

ymax

ymin

31 of 32

Line clipping: Notes

  • C-S’s recursive clipping (up to 4 passes) is not optimal
    • E.g., Liang-Barsky method can be faster
  • C-S generalizable to 3-D (CVV)
    • Instead of 4 half-planes there are 6 half-spaces (3-D volumes)
    • Outcode has 6 bits (two more for near and far Z clip planes)

from E. Angel

from Hill

32 of 32

Clipping Triangles

  • Four cases for the whole triangle:

courtesy of L. McMillan

Keep complete triangle

Throw away complete triangle

Keep triangular portion inside

Split quadrilateral portion inside into 2 triangles