Advanced Rendering III, Clipping Week 8, Mon Mar 5 - - PowerPoint PPT Presentation

advanced rendering iii clipping week 8 mon mar 5
SMART_READER_LITE
LIVE PREVIEW

Advanced Rendering III, Clipping Week 8, Mon Mar 5 - - PowerPoint PPT Presentation

University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Advanced Rendering III, Clipping Week 8, Mon Mar 5 http://www.ugrad.cs.ubc.ca/~cs314/Vjan2007 Reading for This Time FCG Chap 12 Graphics Pipeline


slide-1
SLIDE 1

University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner http://www.ugrad.cs.ubc.ca/~cs314/Vjan2007

Advanced Rendering III, Clipping Week 8, Mon Mar 5

slide-2
SLIDE 2

2

Reading for This Time

  • FCG Chap 12 Graphics Pipeline
  • only 12.1-12.4
slide-3
SLIDE 3

3

News

  • Announcement from Jessica
  • www.cutsforcancer.net
  • P1 grades posted (by student number)
  • P3, H3 out by Wednesday
slide-4
SLIDE 4

4

Correction: Recursive Ray Tracing

RayTrace(r,scene)

  • bj := FirstIntersection(r,scene)

if (no obj) return BackgroundColor; else begin if ( Reflect(obj) ) then reflect_color := RayTrace(ReflectRay(r,obj)); else reflect_color := Black; if ( Transparent(obj) ) then refract_color := RayTrace(RefractRay(r,obj)); else refract_color := Black; return Shade(reflect_color,refract_color,obj); end;

slide-5
SLIDE 5

5

Review: Ray Tracing

  • issues:
  • generation of rays
  • intersection of rays with geometric primitives
  • geometric transformations
  • lighting and shading
  • efficient data structures so we don’t have to

test intersection with every object

slide-6
SLIDE 6

6

Advanced Rendering III

slide-7
SLIDE 7

7

Optimized Ray-Tracing

  • basic algorithm simple but very expensive
  • optimize by reducing:
  • number of rays traced
  • number of ray-object intersection calculations
  • methods
  • bounding volumes: boxes, spheres
  • spatial subdivision
  • uniform
  • BSP trees
  • (more on this later with collision)
slide-8
SLIDE 8

8

Example Raytraced Images

slide-9
SLIDE 9

9

Radiosity

  • radiosity definition
  • rate at which energy emitted or reflected by a surface
  • radiosity methods
  • capture diffuse-diffuse bouncing of light
  • indirect effects difficult to handle with raytracing
slide-10
SLIDE 10

10

Radiosity

  • illumination as radiative heat transfer
  • conserve light energy in a volume
  • model light transport as packet flow until convergence
  • solution captures diffuse-diffuse bouncing of light
  • view-independent technique
  • calculate solution for entire scene offline
  • browse from any viewpoint in realtime

heat/light source thermometer/eye reflective objects energy packets

slide-11
SLIDE 11

11

Radiosity

[IBM] [IBM]

  • divide surfaces into small patches
  • loop: check for light exchange between all pairs
  • form factor: orientation of one patch wrt other patch (n x n matrix)

escience.anu.edu.au/lecture/cg/GlobalIllumination/Image/continuous.jpg escience.anu.edu.au/lecture/cg/GlobalIllumination/Image/discrete.jpg

slide-12
SLIDE 12

12

Better Global Illumination

  • ray-tracing: great specular, approx. diffuse
  • view dependent
  • radiosity: great diffuse, specular ignored
  • view independent, mostly-enclosed volumes
  • photon mapping: superset of raytracing and radiosity
  • view dependent, handles both diffuse and specular well

raytracing photon mapping

graphics.ucsd.edu/~henrik/images/cbox.html

slide-13
SLIDE 13

13

Subsurface Scattering: Translucency

  • light enters and leaves at different locations
  • n the surface
  • bounces around inside
  • technical Academy Award, 2003
  • Jensen, Marschner, Hanrahan
slide-14
SLIDE 14

14

Subsurface Scattering: Marble

slide-15
SLIDE 15

15

Subsurface Scattering: Milk vs. Paint

slide-16
SLIDE 16

16

Subsurface Scattering: Skin

slide-17
SLIDE 17

17

Subsurface Scattering: Skin

slide-18
SLIDE 18

18

Non-Photorealistic Rendering

  • simulate look of hand-drawn sketches or

paintings, using digital models

www.red3d.com/cwr/npr/

slide-19
SLIDE 19

19

Non-Photorealistic Shading

  • cool-to-warm shading

http://www.cs.utah.edu/~gooch/SIG98/paper/drawing.html

kw = 1+ n⋅ l 2 ,c = kwcw + (1− kw)cc

standard cool-to-warm with edges/creases

slide-20
SLIDE 20

20

Non-Photorealistic Shading

  • draw silhouettes: if , e=edge-eye vector
  • draw creases: if

(e⋅ n0)(e⋅ n1) ≤ 0

http://www.cs.utah.edu/~gooch/SIG98/paper/drawing.html

(n0 ⋅ n1) ≤ threshold

standard cool-to-warm with edges/creases

slide-21
SLIDE 21

21

Image-Based Modelling and Rendering

  • store and access only pixels
  • no geometry, no light simulation, ...
  • input: set of images
  • output: image from new viewpoint
  • surprisingly large set of possible new viewpoints
  • interpolation allows translation, not just rotation
  • lightfield, lumigraph: translate outside convex hull of object
  • QuickTimeVR: camera rotates, no translation
  • can point camera in or out
slide-22
SLIDE 22

22

Image-Based Rendering

  • display time not tied to scene complexity
  • expensive rendering or real photographs
  • example: Matrix bullet-time scene
  • array of many cameras allows virtual camera to "freeze time"
  • convergence of graphics, vision, photography
  • computational photography
slide-23
SLIDE 23

23

Clipping

slide-24
SLIDE 24

24

Rendering Pipeline

Geometry Database Geometry Database Model/View Transform. Model/View Transform. Lighting Lighting Perspective Transform. Perspective Transform. Clipping Clipping Scan Conversion Scan Conversion Depth Test Depth Test Texturing Texturing Blending Blending Frame- buffer Frame- buffer

slide-25
SLIDE 25

25

Next Topic: Clipping

  • we’ve been assuming that all primitives (lines,

triangles, polygons) lie entirely within the viewport

  • in general, this assumption will not hold:
slide-26
SLIDE 26

26

Clipping

  • analytically calculating the portions of

primitives within the viewport

slide-27
SLIDE 27

27

Why Clip?

  • bad idea to rasterize outside of framebuffer

bounds

  • also, don’t waste time scan converting pixels
  • utside window
  • could be billions of pixels for very close
  • bjects!
slide-28
SLIDE 28

28

Line Clipping

  • 2D
  • determine portion of line inside an axis-aligned

rectangle (screen or window)

  • 3D
  • determine portion of line inside axis-aligned

parallelpiped (viewing frustum in NDC)

  • simple extension to 2D algorithms
slide-29
SLIDE 29

29

Clipping

  • naïve approach to clipping lines:

for each line segment for each edge of viewport find intersection point pick “nearest” point if anything is left, draw it

  • what do we mean by “nearest”?
  • how can we optimize this?

A B C D

slide-30
SLIDE 30

30

Trivial Accepts

  • big optimization: trivial accept/rejects
  • Q: how can we quickly determine whether a line

segment is entirely inside the viewport?

  • A: test both endpoints
slide-31
SLIDE 31

31

Trivial Rejects

  • Q: how can we know a line is outside

viewport?

  • A: if both endpoints on wrong side of same

edge, can trivially reject line

slide-32
SLIDE 32

32

Clipping Lines To Viewport

  • combining trivial accepts/rejects
  • trivially accept lines with both endpoints inside all edges
  • f the viewport
  • trivially reject lines with both endpoints outside the same

edge of the viewport

  • otherwise, reduce to trivial cases by splitting into two

segments

slide-33
SLIDE 33

33

Cohen-Sutherland Line Clipping

  • outcodes
  • 4 flags encoding position of a point relative to

top, bottom, left, and right boundary

  • OC(p1)=0010
  • OC(p2)=0000
  • OC(p3)=1001

x= x=x xmin

min

x= x=x xmax

max

y= y=y ymin

min

y= y=y ymax

max

0000 0000 1010 1010 1000 1000 1001 1001 0010 0010 0001 0001 0110 0110 0100 0100 0101 0101 p1 p1 p2 p2 p3 p3

slide-34
SLIDE 34

34

Cohen-Sutherland Line Clipping

  • assign outcode to each vertex of line to test
  • line segment: (p1,p2)
  • trivial cases
  • OC(p1)== 0 && OC(p2)==0
  • both points inside window, thus line segment completely visible

(trivial accept)

  • (OC(p1) & OC(p2))!= 0
  • there is (at least) one boundary for which both points are outside

(same flag set in both outcodes)

  • thus line segment completely outside window (trivial reject)
slide-35
SLIDE 35

35

Cohen-Sutherland Line Clipping

  • if line cannot be trivially accepted or rejected,

subdivide so that one or both segments can be discarded

  • pick an edge that the line crosses (how?)
  • intersect line with edge (how?)
  • discard portion on wrong side of edge and assign
  • utcode to new vertex
  • apply trivial accept/reject tests; repeat if necessary
slide-36
SLIDE 36

36

Cohen-Sutherland Line Clipping

  • if line cannot be trivially accepted or rejected,

subdivide so that one or both segments can be discarded

  • pick an edge that the line crosses
  • check against edges in same order each time
  • for example: top, bottom, right, left

A B D E C

slide-37
SLIDE 37

37

Cohen-Sutherland Line Clipping

  • intersect line with edge

A B D E C

slide-38
SLIDE 38

38

  • discard portion on wrong side of edge and assign
  • utcode to new vertex
  • apply trivial accept/reject tests and repeat if

necessary

Cohen-Sutherland Line Clipping

A B D C

slide-39
SLIDE 39

39

Viewport Intersection Code

  • (x1, y1), (x2, y2) intersect vertical edge at xright
  • yintersect = y1 + m(xright – x1)
  • m=(y2-y1)/(x2-x1)
  • (x1, y1), (x2, y2) intersect horiz edge at ybottom
  • xintersect = x1 + (ybottom – y1)/m
  • m=(y2-y1)/(x2-x1)

(x2, y2) (x1, y1) xright (x2, y2) (x1, y1) ybottom

slide-40
SLIDE 40

40

Cohen-Sutherland Discussion

  • key concepts
  • use opcodes to quickly eliminate/include lines
  • best algorithm when trivial accepts/rejects are

common

  • must compute viewport clipping of remaining

lines

  • non-trivial clipping cost
  • redundant clipping of some lines
  • basic idea, more efficient algorithms exist
slide-41
SLIDE 41

41

Line Clipping in 3D

  • approach
  • clip against parallelpiped in NDC
  • after perspective transform
  • means that clipping volume always the same
  • xmin=ymin= -1, xmax=ymax= 1 in OpenGL
  • boundary lines become boundary planes
  • but outcodes still work the same way
  • additional front and back clipping plane
  • zmin = -1, zmax = 1 in OpenGL
slide-42
SLIDE 42

42

Polygon Clipping

  • objective
  • 2D: clip polygon against rectangular window
  • or general convex polygons
  • extensions for non-convex or general polygons
  • 3D: clip polygon against parallelpiped
slide-43
SLIDE 43

43

Polygon Clipping

  • not just clipping all boundary lines
  • may have to introduce new line segments
slide-44
SLIDE 44

44

  • what happens to a triangle during clipping?
  • some possible outcomes:
  • how many sides can result from a triangle?
  • seven

triangle to triangle

Why Is Clipping Hard?

triangle to quad triangle to 5-gon

slide-45
SLIDE 45

45

  • a really tough case:

Why Is Clipping Hard?

concave polygon to multiple polygons

slide-46
SLIDE 46

46

Polygon Clipping

  • classes of polygons
  • triangles
  • convex
  • concave
  • holes and self-intersection
slide-47
SLIDE 47

47

Sutherland-Hodgeman Clipping

  • basic idea:
  • consider each edge of the viewport individually
  • clip the polygon against the edge equation
  • after doing all edges, the polygon is fully clipped
slide-48
SLIDE 48

48

Sutherland-Hodgeman Clipping

  • basic idea:
  • consider each edge of the viewport individually
  • clip the polygon against the edge equation
  • after doing all edges, the polygon is fully clipped
slide-49
SLIDE 49

49

Sutherland-Hodgeman Clipping

  • basic idea:
  • consider each edge of the viewport individually
  • clip the polygon against the edge equation
  • after doing all edges, the polygon is fully clipped
slide-50
SLIDE 50

50

Sutherland-Hodgeman Clipping

  • basic idea:
  • consider each edge of the viewport individually
  • clip the polygon against the edge equation
  • after doing all edges, the polygon is fully clipped
slide-51
SLIDE 51

51

Sutherland-Hodgeman Clipping

  • basic idea:
  • consider each edge of the viewport individually
  • clip the polygon against the edge equation
  • after doing all edges, the polygon is fully clipped
slide-52
SLIDE 52

52

Sutherland-Hodgeman Clipping

  • basic idea:
  • consider each edge of the viewport individually
  • clip the polygon against the edge equation
  • after doing all edges, the polygon is fully clipped
slide-53
SLIDE 53

53

Sutherland-Hodgeman Clipping

  • basic idea:
  • consider each edge of the viewport individually
  • clip the polygon against the edge equation
  • after doing all edges, the polygon is fully clipped
slide-54
SLIDE 54

54

Sutherland-Hodgeman Clipping

  • basic idea:
  • consider each edge of the viewport individually
  • clip the polygon against the edge equation
  • after doing all edges, the polygon is fully clipped
slide-55
SLIDE 55

55

Sutherland-Hodgeman Clipping

  • basic idea:
  • consider each edge of the viewport individually
  • clip the polygon against the edge equation
  • after doing all edges, the polygon is fully clipped
slide-56
SLIDE 56

56

Sutherland-Hodgeman Algorithm

  • input/output for whole algorithm
  • input: list of polygon vertices in order
  • output: list of clipped polygon vertices consisting of
  • ld vertices (maybe) and new vertices (maybe)
  • input/output for each step
  • input: list of vertices
  • output: list of vertices, possibly with changes
  • basic routine
  • go around polygon one vertex at a time
  • decide what to do based on 4 possibilities
  • is vertex inside or outside?
  • is previous vertex inside or outside?
slide-57
SLIDE 57

57

Clipping Against One Edge

  • p[i] inside: 2 cases
  • utside
  • utside

inside inside inside inside

  • utside
  • utside

p[i] p[i] p[i-1] p[i-1]

  • utput:
  • utput: p[i]

p[i] p[i] p[i] p[i-1] p[i-1] p p

  • utput:
  • utput: p,

p, p[i] p[i]

slide-58
SLIDE 58

58

Clipping Against One Edge

  • p[i] outside: 2 cases

p[i] p[i] p[i-1] p[i-1]

  • utput:
  • utput: p

p p[i] p[i] p[i-1] p[i-1] p p

  • utput: nothing
  • utput: nothing
  • utside
  • utside

inside inside inside inside

  • utside
  • utside
slide-59
SLIDE 59

59

Clipping Against One Edge

clipPolygonToEdge( p[n], edge ) { for( i= 0 ; i< n ; i++ ) { if( p[i] inside edge ) { if( p[i-1] inside edge ) output p[i]; // p[-1]= p[n-1] else { p= intersect( p[i-1], p[i], edge ); output p, p[i]; } } else { // p[i] is outside edge if( p[i-1] inside edge ) { p= intersect(p[i-1], p[I], edge ); output p; } } }

slide-60
SLIDE 60

60

Sutherland-Hodgeman Example

inside inside

  • utside
  • utside

p0 p0 p1 p1 p2 p2 p3 p3 p4 p4 p5 p5 p7 p7 p6 p6

slide-61
SLIDE 61

61

Sutherland-Hodgeman Discussion

  • similar to Cohen/Sutherland line clipping
  • inside/outside tests: outcodes
  • intersection of line segment with edge:

window-edge coordinates

  • clipping against individual edges independent
  • great for hardware (pipelining)
  • all vertices required in memory at same time
  • not so good, but unavoidable
  • another reason for using triangles only in

hardware rendering