113
Game Programming Bing-Yu Chen National Taiwan University

Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Game Programming

Bing-Yu ChenNational Taiwan University

Page 2: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Game Geometry

Graph and MeshesSurface PropertiesBounding VolumesSpatial PartitioningLevel-of-Details

1

Page 3: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Standard Graph DefinitionsG=<V,E>V=vertices={A,B,C,D,E,F,G,H,I,J,K,L}E=edges={(A,B),(B,C),(C,D),(D,E),(E,F),(F,G),

(G,H),(H,A),(A,J),(A,G),(B,J),(K,F),(C,L),(C,I),(D,I),(D,F),(F,I),(G,K),(J,L),(J,K),(K,L),(L,I)}

Vertex degree (valence)=number of edges incident on vertexEx. deg(J)=4, deg(H)=2k-regular graph=graph whose vertices all have degree k

Face: cycle of vertices/edges which cannot be shortenedF=faces={(A,H,G),(A,J,K,G),(B,A,J),(B,C,L,J),(C,I,J),(C,D,I),

(D,E,F),(D,I,F),(L,I,F,K),(L,J,K),(K,F,G)}

2

Page 4: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

MeshesMesh: straight-line graph embedded in R3

Boundary edge: adjacent to exactly one faceRegular edge: adjacent to exactly two facesSingular edge: adjacent to more than two faces

Closed Mesh: mesh with no boundary edgesManifold Mesh: mesh with no singular edges

Corners ⊆ V x FHalf-edges ⊆ E x F

3

Page 5: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

OrientabilityOrientation of a face is clockwise or anticlockwise order in which its vertices and edges are lists

This defines the direction of face normal

Straight line graph is orientable if orientations of its faces can be chosen so that each edge is oriented in bothdirections

OrientedF={(L,J,B),(B,C,L),(L,C,I),

(I,K,L),(L,K,J)}

Not OrientedF={(B,J,L),(B,C,L),(L,C,I),

(L,I,K),(L,K,J)}

x

z G

HE

C

B

A

D

F

Back Face Culling = Front Facing12

Page 6: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Definitions of Triangle Meshes{f1} : { v1 , v2 , v3 }{f2} : { v3 , v2 , v4 }…

connectivity

geometry{v1} : (x,y,z){v2} : (x,y,z)…

face attributes{f1} : “skin material”{f2} : “brown hair”…

[Hoppe 99’] 13

Page 7: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Definitions of Triangle Meshes

{v2,f1} : (nx,ny,nz) (u,v){v2,f2} : (nx,ny,nz) (u,v)…

corner attributes

{f1} : { v1 , v2 , v3 }{f2} : { v3 , v2 , v4 }…

connectivity

geometry{v1} : (x,y,z){v2} : (x,y,z)…

face attributes{f1} : “skin material”{f2} : “brown hair”…

[Hoppe 99’] 14

Page 8: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Mesh Data StructuresUses of mesh data:

RenderingGeometry queries

What are the vertices of face #3?Are vertices i and j adjacent?Which faces are adjacent face #7?

Geometry operationsRemove/add a vertex/faceMesh simplificationVertex split, edge collapse

Storage of generic mesheshard to implement efficiently

Assume: orientable, manifold and triangular

Page 9: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Storing Mesh Data

How “good” is a data structure?Time to construct – preprocessingTime to answer a queryTime to perform an operation

update the data structureSpace complexityRedundancy

Page 10: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

1. List of FacesList of vertices (coordinates)

List of facestriplets of pointers to face vertices (c1,c2,c3)

Queries:What are the vertices of face #3?

O(1) – checking the third tripletAre vertices i and j adjacent?

A pass over all faces is necessary – NOT GOOD

Page 11: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

1. List of FacesExample

f1 f2

f3

f4

v6

v5

v4

v2

v1

v3

vertex coordinatev1 (x1,y1,z1)v2 (x2,y2,z2)v3 (x3,y3,z3)v4 (x4,y4,z4)v5 (x5,y5,z5)v6 (x6,y6,z6)

face vertices (ccw)f1 (v1,v2,v3)f2 (v2,v4,v3)f3 (v3,v4,v6)f4 (v4,v5,v6)

Page 12: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

1. List of Faces

Pros:Convenient and efficient (memory wise)Can represent non-manifold meshes

Cons:Too simple – not enough information on relations between vertices and faces

Page 13: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

OBJ File Format (simple ver.)

v x y zvn i j kf v1 // vn1 v2 // vn2 v3 // vn3

Page 14: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

2. Adjacency matrixView mesh as connected graphGiven n vertices build nxn matrix of adjacency information

Entry (i,j) is TRUE value if vertices i and j are adjacent

Geometric infolist of vertex coordinates

Add faceslist of triplets of vertex indices (v1,v2,v3)

Page 15: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

2. Adjacency matrixExample

f1 f2

f3

f4

v6

v5

v4

v2

v1

v3

vertex coordinatev1 (x1,y1,z1)v2 (x2,y2,z2)v3 (x3,y3,z3)v4 (x4,y4,z4)v5 (x5,y5,z5)v6 (x6,y6,z6)

face vertices (ccw)f1 (v1,v2,v3)f2 (v2,v4,v3)f3 (v3,v4,v6)f4 (v4,v5,v6)

v1 v2 v3 v4 v5 v6v1 1 1v2 1 1 1v3 1 1 1 1v4 1 1 1 1v5 1 1v6 1 1 1

Page 16: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

2. Adjacency matrix

Queries:What are the vertices of face #3?

O(1) – checking the third triplet of facesAre vertices i and j adjacent?

O(1) – checking adjacency matrix at location (i,j)

Which faces are adjacent of vertex j?Full pass on all faces is necessary

Page 17: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

2. Adjacency matrix

Pros:Information on vertices adjacencyStores non-manifold meshes

Cons:Connects faces to their vertices, BUT NO connection between vertex and its face

Page 18: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

3. DCEL(Doubly-Connected Edge List)

Record for each face, edge and vertexGeometric informationTopological informationAttribute information

aka Half-Edge Structure

Page 19: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

3. DCELVertex record:

CoordinatesPointer to one half-edge that has v as its origin

Face record:Pointer to one half-edge on its boundary

Half-edge record:Pointer to its origin, origin(e)Pointer to its twin half-edge, twin(e)Pointer to the face it bounds, IncidentFace(e)

face lies to left of e when traversed from origin to destination

Next and previous edge on boundary of IncidentFace(e)

origin(e)

e

next(e)IncFace(e)

Page 20: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

3. DCEL

Operations supported:Walk around boundary of given faceVisit all edges incident to vertex v

Queries:Most queries are O(1)

Page 21: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

3. DCELExample

v1

v2

v3

v4

v5

f1

f2f3e1,1

e2,1

e3,1 e3,2e4,1

e5,1

e4,2

e6,1

e7,1

vertex coordinate IncidentEdgev1 (x1,y1,z1) e2,1

v2 (x2,y2,z2) e1,1

v3 (x3,y3,z3) e4,1

v4 (x4,y4,z4) e7,1

v5 (x5,y5,z5) e5,1

face edgef1 e1,1

f2 e3,2

f3 e4,2

Page 22: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

3. DCELExample

v1

v2

v3

v4

v5

f1

f2f3e1,1

e2,1

e3,1 e3,2e4,1

e5,1

e4,2

e6,1

e7,1

Half-edge

origin twin IncidentFace

next prev

e3,1 v3 e3,2 f1 e1,1 e2,1

e3,2 v2 e3,1 f2 e4,1 e5,1

e4,1 v3 e4,2 f2 e5,1 e3,2

e4,2 v5 e4,1 f3 e6,1 e7,1

Page 23: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

3. DCEL

Pros:All queries in O(1) timeAll operations are (usually) O(1)

Cons:Represents only manifold meshes

Page 24: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Geometry DataVertex position

(x, y, z, w)in model space or screen space

Vertex normal(nx, ny, nz)

Vertex color(r, g, b) or (diffuse, specular)

Texture coordinates on vertex(u1, v1), (u2, v2), …

Skin weights(bone1, w1, bone2, w2, …)

Tangent and bi-normal

N

T

Bn

34

Page 25: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Topology DataLines

Line segmentsPolyline

Open / closed

Indexed trianglesTriangle strips/fansSurfaces

Non-Uniform Rational B-Spline (NURBS)Subdivision

35

Page 26: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Indexed Triangles

Geometric dataVertex datav0, v1, v2, v3, …(x, y, z, nx, ny, nz, tu, tv)or (x, y, z, cr, cg, cb, tu, tv, …)

TopologyFace v0 v3 v6 v7

right-hand rule for index

Edge table36

v0

v3

v6

v7

polygon normal

vertex normal

Page 27: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Triangle Strips/Fansv0

v1

v2

v3

v4

v5

v6

v7

T0

T1

T2 T3

T4

T5

v0 , v1 , v2 , v3 , v4 , v5 , v6 , v7

Get great performance to use triangle strips/fans for rendering on current hardware

v0 , v1 , v2 , v3 , v4 , v5

v0

v1

v2

v3v4

v5

37

Page 28: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Surface Properties

MaterialTexturesShaders

38

Page 29: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

MaterialsMaterial

AmbientEnvironmentNon-lighted area

DiffuseDynamic lighting

EmissiveSelf-lighting

Specular with shinenessHi-lightView-dependentNot good for hardware rendering

Local illumination39

Page 30: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Textures

TexturesSingle textureTexture coordinate animationTexture animationMultiple texturesAlphamap

Material or vertex colors

Base color texture

Lightmap

40

Page 31: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

ShadersProgrammable shading language

Vertex shaderPixel shader

Procedural way to implement some process of rendering

TransformationLightingTexturingBRDFRasterizationPixel fill-inPost-processing for rendering

41

Page 32: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Powered by ShadersPer-pixel lightingMotion blurVolume / Height fogVolume linesDepth of fieldFur renderingReflection / RefractionNPRShadowLinear algebra operatorsPerlin noiseQuaternionSparse matrix solversSkin bone deformationNormal mapDisplacement mapParticle shaderProcedural MorphingWater Simulation

43

Page 33: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Bounding VolumesBounding sphereBounding cylinderAxis-aligned bounding box (AABB)Oriented bounding box (OBB)Discrete oriented polytope (k-DOP)

45

Bounding Sphere AABB

OBB

k-DOP

Bounding Cylinder

Page 34: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Bounding Volume - Application

Collision detectionVisibility cullingHit testSteering behavior

in “Game AI”

46

Page 35: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Application Example –Bounding Sphere

47

Bounding sphere B1(c1, r1), B2(c2, r2)

If the distance between two bounding spheres islarger than the sum of radius of the spheres, thanthese two objects have no chance to collide.

D > Sum(r1, r2)

D

B1

B2

c1

c2

Page 36: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Application Example - AABB

Axis-aligned bounding box (AABB)Simplified calculation using axis-alignment featureBut need run-timely to track the bounding box

AABB

48

Page 37: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Application Example - OBB

Oriented bounding box (OBB)Need intersection calculation using the transformed OBB geometric data

3D containment testLine intersection with plane

For games, ☺

OBB

49

Page 38: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Ray Casting

Window

Center ofprojection

50

Page 39: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Spatial Partitioning

51

Page 40: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Spatial Partitioning

R

A B

C

52

Page 41: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Spatial Partitioning

1

23

A

B

53

Page 42: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Space Subdivision Approaches

Uniform grid K-d tree

54

Page 43: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Space Subdivision Approaches

Quadtree (2D)Octree (3D)

BSP tree

55

Page 44: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Uniform Grid

56

Page 45: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Preprocess scene1. Find bounding box

Uniform Grid

57

Page 46: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Preprocess scene1. Find bounding box2. Determine grid resolution

Uniform Grid

58

Page 47: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Uniform Grid

Preprocess scene1. Find bounding box2. Determine grid resolution3. Place object in cell if its

bounding box overlaps the cell

59

Page 48: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Uniform Grid

Preprocess scene1. Find bounding box2. Determine grid resolution3. Place object in cell if its

bounding box overlaps the cell

4. Check that object overlaps cell (expensive!)

60

Page 49: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Uniform Grid Traversal

Preprocess sceneTraverse grid

3D line = 3D-DDA

61

Page 50: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

From Uniform Grid to Quadtree

62

Page 51: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Quadtree (Octrees)

subdivide the space adaptively 63

Page 52: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Quadtree Data Structure

Quadrant Numbering

64

Page 53: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Quadtree Data Structure

Quadrant Numbering

65

Page 54: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Quadtree Data Structure

Quadrant Numbering

66

Page 55: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Quadtree Data Structure

Quadrant Numbering

67

Page 56: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

From Quadtree to Octree

x

y

z68

Page 57: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

A

A

Leaf nodes correspond to unique regions in space

K-d Tree

69

Page 58: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Leaf nodes correspond to unique regions in space

A

A

B

K-d Tree

70

Page 59: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Leaf nodes correspond to unique regions in space

A

B

A

B

K-d Tree

71

Page 60: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

A

B

A

B

C

K-d Tree

72

Page 61: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

A

B

C A

B

C

K-d Tree

73

Page 62: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

A

B

C A

B

C

D

K-d Tree

74

Page 63: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

A

B

C

D

A

B

C

D

K-d Tree

75

Page 64: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

A

B C

D

A

B

C

D

Leaf nodes correspond to unique regions in space

K-d Tree

76

Page 65: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

A

B C

D

A

B

C

D

Leaf nodes correspond to unique regions in space

K-d Tree Traversal

77

Page 66: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Binary Space-Partitioning Trees

T1

T2

T2 T3

T1 +-

T3

79

Page 67: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Binary Space-Partitioning Trees

T1

T2T3

T3

T1 +-

T2 +-

80

Page 68: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Splitting trianglesa

b

c

A

B

a

b

c

A

B

81

Page 69: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

3

4

1

2

56

7

9

8

11

10

BSP Tree

86

Page 70: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

3

4

1

2

56

7

1

insideones

outsideones

9

8

11

10

BSP Tree

87

Page 71: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

3

4

1

2

56

7

1

234

567891011

9

8

11

10

BSP Tree

88

Page 72: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

3

4

1

2

9

8

11

10

56

7

9b

9a

1

5

679a1011a11a

11b89b11b

BSP Tree

89

Page 73: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

3

4

1

2

9

8

11

10

56

7

9b

11a

2

3

4

1

5

6

7

9a

10

11a

8

9b

11b

9a11b

BSP Tree

90

Page 74: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

3

4

1

2

9

8

11

10

56

7

9b

point

11a

2

3

4

1

5

6

7

9a

10

11a

8

9b

11b

9a11b

BSP Tree

91

Page 75: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

3

4

1

2

9

8

11

10

56

7

9b

point

11a

2

3

4

1

5

6

7

9a

10

11a

8

9b

11b

9a11b

BSP Tree Traversal

92

Page 76: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

1

2

9

8

11

10

56

7

9b

point

11a

2

3

4

1

5

6

7

9a

10

11a

8

9b

11b

9a11b

3

4

BSP Tree Traversal

93

Page 77: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Level-of-Details

Discrete LODSwitch multiple resolution models run-timely

Continuous LODUse progressive mesh to dynamically reduce the rendered polygons

View-dependent LODBasically for terrain

94

Page 78: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Level of Detail: The Basic Idea

One solution:Simplify the polygonal geometry of small or distant objectsKnown as Level of Detail or LOD

a.k.a. polygonal simplification, geometric simplification, mesh reduction, multiresolution modeling, …

95

Page 79: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Level of Detail:Traditional Approach

Create levels of detail (LODs) of objects:

69,451 polys 2,502 polys 251 polys 76 polys

96

Page 80: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Level of Detail:Traditional Approach

Distant objects use coarser LODs:

97

Page 81: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Traditional Approach: Discrete Level of Detail

Traditional LOD in a nutshell:Create LODs for each object separately in a preprocessAt run-time, pick each object’s LOD according to the object’s distance (or similar criterion)

Since LODs are created offline at fixed resolutions, this can be referred as Discrete LOD

98

Page 82: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Discrete LOD:Advantages

Simplest programming model; decouples simplification and rendering

LOD creation need not address real-time rendering constraintsRun-time rendering need only pick LODs

99

Page 83: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Discrete LOD:Advantages

Fits modern graphics hardware wellEasy to compile each LOD into triangle strips, display lists, vertex arrays, …These render much faster than unorganized polygons on today’s hardware (3-5 x)

100

Page 84: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Discrete LOD:Disadvantages

So why use anything but discrete LOD?Answer: sometimes discrete LOD not suited for drastic simplificationSome problem cases:

Terrain flyoversVolumetric isosurfacesSuper-detailed range scansMassive CAD models

101

Page 85: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Continuous Level of Detail

A departure from the traditional static approach:

Discrete LOD: create individual LODs in a preprocessContinuous LOD: create data structure from which a desired level of detail can be extracted at run time.

106

Page 86: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Continuous LOD:Advantages

Better granularity better fidelityLOD is specified exactly, not chosen from a few pre-created optionsThus objects use no more polygons than necessary, which frees up polygons for other objects Net result: better resource utilization, leading to better overall fidelity/polygon

107

Page 87: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Continuous LOD:Advantages

Better granularity smoother transitions

Switching between traditional LODs can introduce visual “popping” effectContinuous LOD can adjust detail gradually and incrementally, reducing visual pops

Can even geomorph the fine-grained simplification operations over several frames to eliminate pops [Hoppe 96, 98]

108

Page 88: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Continuous LOD:Advantages

Supports progressive transmissionProgressive Meshes [Hoppe 97]Progressive Forest Split Compression [Taubin 98]

Leads to view-dependent LODUse current view parameters to select best representation for the current viewSingle objects may thus span several levels of detail

109

Page 89: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

MethodologySequence of local operations

Involve near neighbors - only small patch affected in each operationEach operation introduces errorFind and apply operation which introduces the least error

110

Page 90: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Simplification OperationsDecimation

Vertex removalv ← v-1f ← f-2

Remaining vertices - subset of original vertex set

111

Page 91: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Simplification Operations

DecimationEdge collapse

v ← v-1f ← f-2

Triangle collapsev ← v-2f ← f-4

Vertices may move

112

Page 92: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Simplification Error Metrics

MeasuresDistance to planeCurvature

Usually approximatedAverage planeDiscrete curvature

/ 2α π∑114

Page 93: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

The Basic Algorithm

RepeatSelect the element with minimal errorPerform simplification operation

(remove/contract)Update error

(local/global)

Until mesh size / quality is achieved

115

Page 94: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Progressive MeshesRender a model in different Level-of-Detail at run timeUser-controlledly or automatically change the percentage of rendered verticesUse collapse map to control the simplification process

Collapse map

Vertex list

Triangle list

Index 0 1 2 3 4 5 6 7 8

Map 0 1 1 2 3 0 4 5 6

0 1 2 3 4 5 6 7 8

0 2 5 0 1 2 3 5 8

0 0 6

4

117

Page 95: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

View-dependent LOD for Terrain - ROAM

Real-time Optimal Adapting Meshes (ROAM)Use height mapRun-timely to re-construct the active (for rendering) geometric topology (re-mesh) to get an optimal mesh (polygon count) to improve the rendering performanceSomeone calls this technique as theview-dependent level-of-detailVery good for fly-simulation-like application

118

Page 96: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Vertex Tree & Active Triangle List

The Vertex Treerepresents the entire modela hierarchical clustering of verticesqueried each frame for updated scene

The Active Triangle Listrepresents the current simplificationlist of triangle to be displayed

119

Page 97: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

The Vertex Tree

Each vertex tree node contains:a subset of model verticesa representative vertex or repvert

Folding a node collapses its vertices to the repvertUnfolding a node splits the repvert back into vertices

120

Page 98: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Vertex Tree Example

Vertex TreeTriangles in Active List

1

2

3

4 5

6

78

9

10

1 2

3

4 5 67 8 9

10 A B C

I II

R

121

Page 99: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Vertex Tree Example

Vertex TreeTriangles in Active List

1

2

3

4 5

6

78

9

10

1 2

3

4 5 67 8 9

10 A B C

I II

R

A

122

Page 100: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Vertex Tree Example

Vertex TreeTriangles in Active List

3

4 5

6

8

9

10

1 2

3

4 5 67 8 9

10 A B C

I II

R

A

123

Page 101: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Vertex Tree Example

Vertex TreeTriangles in Active List

3

4 5

6

8

9

10

1 2

3

4 5 67 8 9

10 A B C

I II

R

A

B

124

Page 102: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Vertex Tree Example

Vertex TreeTriangles in Active List

3

8

9

10

1 2

3

4 5 67 8 9

10 A B C

I II

R

A

B

125

Page 103: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Vertex Tree Example

Vertex TreeTriangles in Active List

3

8

9

10

1 2

3

4 5 67 8 9

10 A B C

I II

R

A

B

C

126

Page 104: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Vertex Tree Example

Vertex TreeTriangles in Active List

3

10

1 2

3

4 5 67 8 9

10 A B C

I II

R

A

B

C

127

Page 105: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Vertex Tree Example

Vertex TreeTriangles in Active List

3

10

1 2

3

4 5 67 8 9

10 A B C

I II

R

A

B

C

II

128

Page 106: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Vertex Tree Example

Vertex TreeTriangles in Active List

10

1 2

3

4 5 67 8 9

10 A B C

I II

R

A

B

II

129

Page 107: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Vertex Tree Example

Vertex TreeTriangles in Active List

10

1 2

3

4 5 67 8 9

10 A B C

I II

R

A

B

II I

130

Page 108: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Vertex Tree Example

Vertex TreeTriangles in Active List

1 2

3

4 5 67 8 9

10 A B C

I II

R

B

II I

131

Page 109: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Vertex Tree Example

Vertex TreeTriangles in Active List

1 2

3

4 5 67 8 9

10 A B C

I II

R

B

II I

R

132

Page 110: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Vertex Tree Example

Vertex TreeTriangles in Active List

1 2

3

4 5 67 8 9

10 A B C

I II

R

R

133

Page 111: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

The Vertex Tree:Folding & Unfolding

1

2

3

4 5

6

78

9

10

A

3

4 5

6

8

9

10

A

Fold node A

Unfold node A

134

Page 112: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

The Vertex Tree:Tris & Subtris

1

2

3

4 5

6

78

9

10

3

4 5

6

8

9

10

A

Fold node A

Unfold node A

Tris: triangles that change shape upon foldingSubtris: triangles that disappear completely

135

Page 113: Game Programming - 國立臺灣大學graphics.im.ntu.edu.tw/~robin/courses/game07/ppt/game07_04geo.pdfRendering Geometry queries What are the vertices of face #3? ... in model space

Level-of-detail SuggestionApply progressive mesh for multi-resolution model generationUse in-game discrete LOD for performance tuningWhy ?

For modern game API / platform, dynamic vertex update is costly on performanceLock video memory stall CPU/GPU performance

136