6.2 Bump Mapping & Clipping Hao Li http://cs420.hao-li.com 1 - - PowerPoint PPT Presentation

6 2 bump mapping clipping
SMART_READER_LITE
LIVE PREVIEW

6.2 Bump Mapping & Clipping Hao Li http://cs420.hao-li.com 1 - - PowerPoint PPT Presentation

Fall 2018 CSCI 420: Computer Graphics 6.2 Bump Mapping & Clipping Hao Li http://cs420.hao-li.com 1 Bump Mapping 2 A long time ago, in 1978 3 bump mapping was born courtesy by ZBrush 4 For Meshes vertex normal interpolation


slide-1
SLIDE 1

CSCI 420: Computer Graphics

Hao Li

http://cs420.hao-li.com

Fall 2018

6.2 Bump Mapping & Clipping

1

slide-2
SLIDE 2

Bump Mapping

2

slide-3
SLIDE 3

A long time ago, in 1978

3

slide-4
SLIDE 4

courtesy by ZBrush

… bump mapping was born

4

slide-5
SLIDE 5

vertex normal interpolation smooth shading What about accessing textures to modify surface normals...

For Meshes

5

slide-6
SLIDE 6

Use bump map normals given a parametrized mesh

u =

  • u

v ⇥

∈ R2

Goal

6

slide-7
SLIDE 7

Bump map normals

are defined in a local coordinate frame inside a triangle

7

slide-8
SLIDE 8

We have positions, normals and parameters

  • f the triangle corners

8

slide-9
SLIDE 9

9

How do we obtain coordinate frame?

slide-10
SLIDE 10

p(u) ∈ R3 u =

  • u

v ⇥

∈ R2

2-Manifold Surface Parameter Domain

Some Differential Geometry

10

slide-11
SLIDE 11

p(u) ∈ R3 u =

  • u

v ⇥

∈ R2

Surface Parameter Domain n(p)

11

Surface normals for shading

slide-12
SLIDE 12

p(u) ∈ R3 n(p) ∂p ∂u ∂p ∂v

12

Surface normals obtained from tangent space

slide-13
SLIDE 13

p1 p2 p3 p0

pi = p0 + ui ∂p ∂u + vi ∂p ∂v

p

13

Tangent vectors inside triangles

slide-14
SLIDE 14

we are not interested in

p0

p2 − p1 = (u2 − u1)∂p ∂u + (v2 − v1)∂p ∂v p3 − p1 = (u3 − u1)∂p ∂u + (v3 − v1)∂p ∂v

14

Fully determined from positions and parameters

slide-15
SLIDE 15
  • p2 − p1

p3 − p1 ⇥ = ⇧

∂p ∂u ∂p ∂v

⌃ ⇤ (u2 − u1)

(u3 − u1) (v2 − v1) (v3 − v1)

p2 − p1 = (u2 − u1)∂p ∂u + (v2 − v1)∂p ∂v p3 − p1 = (u3 − u1)∂p ∂u + (v3 − v1)∂p ∂v

correct if mesh is planar

2x2 Matrix Inversion

15

slide-16
SLIDE 16

n

n1 n2 n3

n = α1n1 + α2n2 + α3n3

p = α1p1 + α2p2 + α3p3

from

Normals Interpolation (see Phong Shading)

16

slide-17
SLIDE 17

n

∂p ∂u

∂p ∂v

∂pnew ∂v

∂pnew ∂u

Tangent vectors orthogonal to normal

17

slide-18
SLIDE 18

We now have an inexpensive way to add geometric details Other bump mapping techniques exist

18

slide-19
SLIDE 19
  • “Simulation of Wrinkled Surfaces” [Blinn 1978]
  • “Real-Time Rendering” [Akenine-Möller and Haines 2002] p.166 – 177

Further Readings

19

slide-20
SLIDE 20

Clipping

20

slide-21
SLIDE 21

The Graphics Pipeline, Revisited

  • Must eliminate objects that are outside 

  • f viewing frustum
  • Clipping: object space (eye coordinates)
  • Scissoring: image space (pixels in frame buffer)
  • most often less efficient than clipping
  • We will first discuss 2D clipping (for simplicity)
  • OpenGL uses 3D clipping

21

slide-22
SLIDE 22

2D Clipping Problem

22

slide-23
SLIDE 23
  • General case of frustum (truncated pyramid)
  • Clipping is tricky because of frustum shape

Clipping Against a Frustum

23

x y

image plane near far Z clipped line

slide-24
SLIDE 24

Perspective Normalization

  • Solution:
  • Implement perspective projection by perspective

normalization and orthographic projection

  • Perspective normalization is a homogeneous transformation

24

near far z clipped line image plane x y near clipped line z y x 1 1 1 far

slide-25
SLIDE 25

The Normalized Frustum

  • OpenGL uses -1 ≤ x,y,z ≤ 1 (others possible)
  • Clip against resulting cube
  • Clipping against arbitrary (programmer-specified) planes

requires more general algorithms and is more expensive

25

slide-26
SLIDE 26

The Viewport Transformation

  • Transformation sequence again:

1. Camera: From object coordinates to eye coords

  • 2. Perspective normalization: to clip coordinates
  • 3. Clipping
  • 4. Perspective division: to normalized device coords
  • 5. Orthographic projection (setting zp = 0)
  • 6. Viewport transformation: to screen coordinates
  • Viewport transformation can distort
  • Solution: pass the correct window aspect ratio to

gluPerspective

26

slide-27
SLIDE 27

Clipping

  • General: 3D object against cube

  • Simpler case:
  • In 2D: line against

square or rectangle

  • Later: polygon clipping

27

1 y x z 1 1 clipped line

slide-28
SLIDE 28

Clipping Against Rectangle in 2D

  • Line-segment clipping: modify endpoints of lines to lie

within clipping rectangle

28

slide-29
SLIDE 29

Clipping Against Rectangle in 2D

  • The result (in red)

29

slide-30
SLIDE 30

Clipping Against Rectangle in 2D

  • Could calculate intersections of line segments with

clipping rectangle

  • expensive, due to floating point multiplications 


and divisions

  • Want to minimize the number of multiplications


and divisions

30

y = y1 y = y0 y = kx + n x = x0 x = x1

slide-31
SLIDE 31

Several practical algorithms for clipping

  • 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)

31

slide-32
SLIDE 32

Cohen-Sutherland Clipping

32

  • Clipping rectangle is an intersection of 4 half-planes
  • Encode results of four half-plane tests
  • Generalizes to 3 dimensions (6 half-planes)

y < ymax y > ymin x > xmin x < xmax

= ∩

interior

xmin xmax ymin ymax

interior

slide-33
SLIDE 33

Outcodes (Cohen-Sutherland)

  • Divide space into 9 regions
  • 4-bit outcode determined by comparisons (TBRL)

33

b0 : y > ymax b1 : y < ymin b2 : x > xmax b3 : x < xmin O1 = outcode(x1, y1) O1 = outcode(x2, y2)

1001 1000 1010 0010 0000 0001 0101 0100 0110 ymax ymin

(x1, y1) (x2, y2)

xmin xmax

slide-34
SLIDE 34

Cases for Outcodes

  • Outcomes: accept, reject, subdivide

34

1001 1000 1010 0010 0000 0001 0101 0100 0110 ymax ymin xmin xmax O1 = O2 = 0000: accept entire segment O1 & O2 ≠ 0000: reject entire segment O1 = 0000, O2 ≠ 0000: subdivide O1 ≠ 0000, O2 = 0000: subdivide O1 & O2 = 0000: subdivide bitwise AND

slide-35
SLIDE 35

Cohen-Sutherland Subdivision

  • Pick outside endpoint (o ≠ 0000)
  • Pick a crossed edge (o = b0b1b2b3 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
  • This algorithms converges

35

slide-36
SLIDE 36

Liang-Barsky Clipping

  • Start with parametric form for a line

36

p1 p2

slide-37
SLIDE 37

Liang-Barsky Clipping

  • Compute all four intersections 1,2,3,4 with extended

clipping rectangle

  • Often, no need to compute all four intersections

37

p1 p2 1 2 3 4 extended clipping rectangle

slide-38
SLIDE 38

Ordering of intersection points

  • Order the intersection points
  • Figure (a): 1 > α4 > α3 > α2 > α1 > 0
  • Figure (b): 1 > α4 > α2 > α3 > α1 > 0

38

slide-39
SLIDE 39

Liang-Barsky Idea

  • It is possible to clip already if one knows


the order of the four intersection points !

  • Even if the actual intersections were not computed !
  • Can enumerate all ordering cases

39

slide-40
SLIDE 40

Liang-Barsky efficiency improvements

40

  • Efficiency improvement 1:
  • Compute intersections one by one
  • Often can reject before all four are computed
  • Efficiency improvement 2:
  • Equations for α3, α2
  • Compare α3, α2 without floating-point division
slide-41
SLIDE 41

Line-Segment Clipping Assessment

  • Cohen-Sutherland
  • Works well if many lines can be rejected early
  • Recursive structure (multiple subdivisions) is a drawback
  • Liang-Barsky
  • Avoids recursive calls
  • Many cases to consider (tedious, but not expensive)
  • In general much faster than Cohen-Sutherland

41

slide-42
SLIDE 42

Outline

  • Line-Segment Clipping
  • Cohen-Sutherland
  • Liang-Barsky
  • Polygon Clipping
  • Sutherland-Hodgeman
  • Clipping in Three Dimensions

42

slide-43
SLIDE 43

Polygon Clipping

  • Convert a polygon into one or more polygons
  • Their union is intersection with clip window
  • Alternatively, we can first tesselate concave polygons

(OpenGL supported)

43

slide-44
SLIDE 44

Concave Polygons

44

  • Approach 1: clip, and then join pieces to a single polygon
  • often difficult to manage
  • Approach 2: tesselate and clip triangles
  • this is the common solution
slide-45
SLIDE 45

Sutherland-Hodgeman (part 1)

  • Subproblem:
  • Input: polygon (vertex list) and single clip plane
  • Output: new (clipped) polygon (vertex list)
  • Apply once for each clip plane
  • 4 in two dimensions
  • 6 in three dimensions
  • Can arrange in pipeline

45

slide-46
SLIDE 46

Sutherland-Hodgeman (part 2)

  • To clip vertex list (polygon) against a half-plane:
  • Test first vertex. Output if inside, otherwise skip.
  • Then loop through list, testing transitions
  • In-to-in: output vertex
  • In-to-out: output intersection
  • out-to-in: output intersection and vertex
  • out-to-out: no output
  • Will output clipped polygon as vertex list
  • May need some cleanup in concave case
  • Can combine with Liang-Barsky idea

46

slide-47
SLIDE 47

Other Cases and Optimizations

  • Curves and surfaces
  • Do it analytically if possible
  • Otherwise, approximate curves / surfaces by

lines and polygons

  • Bounding boxes
  • Easy to calculate and maintain
  • Sometimes big savings

47

slide-48
SLIDE 48

Outline

  • Line-Segment Clipping
  • Cohen-Sutherland
  • Liang-Barsky
  • Polygon Clipping
  • Sutherland-Hodgeman
  • Clipping in Three Dimensions

48

slide-49
SLIDE 49

Clipping Against Cube

  • Derived from earlier algorithms
  • Can allow right parallelepiped

49

slide-50
SLIDE 50

Cohen-Sutherland in 3D

  • Use 6 bits in outcode
  • b4: z > zmax
  • b5: z < zmin
  • Other calculations

as before

50

slide-51
SLIDE 51

Liang-Barsky in 3D

51

  • Add equation
  • Solve, for p0 in plane and normal n:
  • Yields
  • Optimizations as for Liang-Barsky in 2D

z(α) = (1 − α)z1 + αz2

slide-52
SLIDE 52

Summary: Clipping

  • Clipping line segments to rectangle or cube
  • Avoid expensive multiplications and divisions
  • Cohen-Sutherland or Liang-Barsky
  • Polygon clipping
  • Sutherland-Hodgeman pipeline
  • Clipping in 3D
  • essentially extensions of 2D algorithms

52

slide-53
SLIDE 53

Next Time

  • Scan conversion
  • Anti-aliasing
  • Other pixel-level operations

53

slide-54
SLIDE 54

http://cs420.hao-li.com

Thanks!

54