1 further terrain rendering and level of detail lecture 8 - week 4 advanced programming for 3d...

40
1 1 Further Terrain Rendering and Further Terrain Rendering and Level of Detail Level of Detail Lecture 8 - Week 4 Lecture 8 - Week 4 Advanced Programming for 3D Advanced Programming for 3D Applications Applications CE00383-3 CE00383-3

Upload: violet-montgomery

Post on 18-Dec-2015

215 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

11

Further Terrain Rendering and Level of Further Terrain Rendering and Level of Detail Detail

Lecture 8 - Week 4Lecture 8 - Week 4

Advanced Programming for 3D Advanced Programming for 3D ApplicationsApplicationsCE00383-3CE00383-3

Page 2: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

2222

Fractal TerrainFractal Terrain• Based on subdivision of a course polygon meshBased on subdivision of a course polygon mesh• Each subdivision adds detail to the mesh in a Each subdivision adds detail to the mesh in a

random wayrandom way• Algorithm (starting with a triangular mesh):Algorithm (starting with a triangular mesh):

– Split each edge, and shift the new vertex up or down Split each edge, and shift the new vertex up or down by a random amountby a random amount

– Subdivide the triangles using the new verticesSubdivide the triangles using the new vertices– RepeatRepeat

• Also algorithms for quadrilateral meshesAlso algorithms for quadrilateral meshes

• http://www.gameprogrammer.com/http://www.gameprogrammer.com/fractal.htmlfractal.html

Page 3: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

3333

Subdivision Method No 1Subdivision Method No 1

Note: Works on any triangular mesh - does not have to be regular or have equal sized triangles.

Page 4: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

4444

Subdivision Method No 2Subdivision Method No 2

• Generates aGenerates a triangle triangle bintree bintree from the top downfrom the top down

• Useful for LOD, Useful for LOD, • Ideally, works for right-Ideally, works for right-

angled isosceles trianglesangled isosceles triangles

Page 5: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

5555

Subdivision Method No 3Subdivision Method No 3

• Assume quadrilateral meshesAssume quadrilateral meshes

Page 6: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

6666

Rendering TerrainRendering Terrain

Coarser

Finer

Page 7: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

7777

Rendering TerrainRendering Terrain

Adaptive Representation

Bilinear Patch

Page 8: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

8888

Rendering TerrainRendering Terrain

Adaptive Representation

T-Junction

Page 9: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

9999

Triangle BintreesTriangle Bintrees

• Binary trees in which:Binary trees in which:– Each node represents a right-angled isosceles Each node represents a right-angled isosceles

triangletriangle– Each node has two children formed by splitting from Each node has two children formed by splitting from

the right angle vertex to the midpoint of the baselinethe right angle vertex to the midpoint of the baseline– The leaf nodes use vertices from the original height The leaf nodes use vertices from the original height

fieldfield

• Another way to build a spatial partitioning tree, but Another way to build a spatial partitioning tree, but particularly well suited to simplification algorithmsparticularly well suited to simplification algorithms– Easy to maintain neighbor informationEasy to maintain neighbor information– Easy to avoid T-verticesEasy to avoid T-vertices

Page 10: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

10101010

1

2

3

46

5

8 71013

1411 12

9

21

3 4 5 6

7 8 9 10 11 12 13 14

Triangle Bintree ExampleTriangle Bintree Example

Page 11: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

11111111

Bintree Data StructureBintree Data Structure

• Parent and child pointersParent and child pointers

• NeighborsNeighbors– A left neighbor, a right neighbor, and a base neighborA left neighbor, a right neighbor, and a base neighbor– Note that the base and right angle give us a way to Note that the base and right angle give us a way to

orient the triangleorient the triangle– Neighbors are not necessarily at your own levelNeighbors are not necessarily at your own level

• Later, error bounds that say how much variation in Later, error bounds that say how much variation in height there is in your childrenheight there is in your children

Page 12: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

12121212

1

2

3

46

5

8 710

9

21

3 4 5 6

7 8 9 10 11 12 13 14

CutsCuts

Page 13: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

13131313

8 710

9

NeighborsNeighbors• 5: left neighbor 6, right neighbor 95: left neighbor 6, right neighbor 9• 6: left neighbor 8, right neighbor 56: left neighbor 8, right neighbor 5• 7: left neighbor 8, base neighbor 107: left neighbor 8, base neighbor 10• 8: base neighbor 6, right neighbor 78: base neighbor 6, right neighbor 7• 9: base neighbor 5, left neighbor 109: base neighbor 5, left neighbor 10• 10: base neighbor 7, right neighbor 9 10: base neighbor 7, right neighbor 9

• Note that 8 is 6’s left neighbor but 6 is 8’s base Note that 8 is 6’s left neighbor but 6 is 8’s base neighborneighbor– If you are someone’s left/right/base neighbor they If you are someone’s left/right/base neighbor they

are not always your right/left/base neighborare not always your right/left/base neighbor• In other words, neighbors need not come from the In other words, neighbors need not come from the

same level in the treesame level in the tree

6

5

Page 14: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

14141414

1

2

3

46

5

8 710

9

21

3 4 5 6

7 8 9 10 11 12 13 14

Cuts Are Not Always EqualCuts Are Not Always Equal

Note the T-vertex - causes cracks in rendering

Page 15: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

15151515

Generating CutsGenerating Cuts

• Cuts are generated by a sequence of Cuts are generated by a sequence of split or merge stepssplit or merge steps– Split: Drop the cut below to include your Split: Drop the cut below to include your

childrenchildren– Merge: Lift the cut up above two childrenMerge: Lift the cut up above two children

• To avoid T-vertices, some splits lead to To avoid T-vertices, some splits lead to other, other, forcedforced, splits, splits

• An LOD algorithm chooses which steps An LOD algorithm chooses which steps to apply to generate a particular to apply to generate a particular triangle count or error ratetriangle count or error rate

Page 16: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

16161616

21

3 4 5 6

7 8 9 10 11 12 13 14

A SplitA Split

• A split cuts a triangle in two by splitting its base edgeA split cuts a triangle in two by splitting its base edge– If the base edge is on a boundary, just split, as shownIf the base edge is on a boundary, just split, as shown– If the base edge is shared, additional splits are If the base edge is shared, additional splits are forcedforced

• Add a new triangle to the meshAdd a new triangle to the mesh

6

Page 17: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

17171717

Forced SplitsForced Splits

• Triangles are always split Triangles are always split along their basealong their base

• Hence, must also be able Hence, must also be able to split the base neighbor to split the base neighbor – Requires neighbors to be Requires neighbors to be

mutual base neighborsmutual base neighbors– If they are not base If they are not base

neighbors, even more neighbors, even more splits are neededsplits are needed

– Simple recursive Simple recursive formulationformulation

Page 18: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

18181818

8 710

9

MergesMerges• A diamond is a merge candidate if the children of it’s A diamond is a merge candidate if the children of it’s

members are in the triangulationmembers are in the triangulation– The children of the 7-10 diamond below are The children of the 7-10 diamond below are

candidatescandidates– Look for parents of sibling leaf nodes that are base Look for parents of sibling leaf nodes that are base

neighbors or have no base neighborsneighbors or have no base neighbors• Reduces the triangle countReduces the triangle count

21

3 4 5 6

7 8 9 10 11 12 13 14

Page 19: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

19191919

Refinement LOD AlgorithmRefinement LOD Algorithm

• Start with the base meshStart with the base mesh• Repeatedly split triangles until doneRepeatedly split triangles until done

– Stop when a specific triangle count is reached, or …Stop when a specific triangle count is reached, or …– Stop when error is below some amountStop when error is below some amount

• To guide the split order, assign priorities to each split To guide the split order, assign priorities to each split and always do the one with the highest priorityand always do the one with the highest priority– After each split, update priorities of affected trianglesAfter each split, update priorities of affected triangles– Sample priority: High priority to splits that will reduce Sample priority: High priority to splits that will reduce

big errorsbig errors• What is the complexity of this? (Roughly)What is the complexity of this? (Roughly)• A similar algorithm works by simplifying the mesh A similar algorithm works by simplifying the mesh

through merge operations. Why choose one over the through merge operations. Why choose one over the other?other?

Page 20: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

20202020

Fractal Terrain DetailsFractal Terrain Details• The original mesh vertices don’t move, so The original mesh vertices don’t move, so

it defines the overall shape of the terrain it defines the overall shape of the terrain (mountains, valleys, etc)(mountains, valleys, etc)

• There are options for choosing where to There are options for choosing where to move the new verticesmove the new vertices– Uniform random offsetUniform random offset– Normally distributed offset – small Normally distributed offset – small

motions more likelymotions more likely– Procedural rule – eg Procedural rule – eg Perlin noisePerlin noise

• making patterns from pseudo-making patterns from pseudo-random numbersrandom numbers

• If desired, boundary vertices can be left If desired, boundary vertices can be left unmoved, to maintain the boundary edgeunmoved, to maintain the boundary edge

Page 21: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

21212121

Fractal TerrainsFractal Terrains

Very jagged terrain

Page 22: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

22222222

Populating TerrainPopulating Terrain• Coloring terrain:Coloring terrain:

– Paint texture mapsPaint texture maps– Base color on height (with some randomness)Base color on height (with some randomness)

• Trees:Trees:– Paint densities, or randomly set densityPaint densities, or randomly set density– Then place trees randomly within regions Then place trees randomly within regions

according to densityaccording to density

• Rivers (and lakes):Rivers (and lakes):– Trace local minima, and estimate catchment Trace local minima, and estimate catchment

areas (more later…)areas (more later…)

Page 23: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

23232323

Terrain Generation Trade-Terrain Generation Trade-OffsOffs• Control vs Automation:Control vs Automation:

– Painting gives most controlPainting gives most control– Fractal terrain next best control because you can Fractal terrain next best control because you can

always specify more pointsalways specify more points– Random methods give little control - generate Random methods give little control - generate

lots and choose the one you likelots and choose the one you like

• Generate on-the-fly:Generate on-the-fly:– Random points and fractal terrain could be Random points and fractal terrain could be

generated on the fly, but fractal terrain generated on the fly, but fractal terrain generation is quite slowgeneration is quite slow

– Tilings can also be generated on the flyTilings can also be generated on the fly

Page 24: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

24242424

Static LODStatic LOD• Depending on the roughness of the Depending on the roughness of the

terrain and the application, 5%-50% of terrain and the application, 5%-50% of the vertices and triangles can be removedthe vertices and triangles can be removed– With 536.805.378 triangles still more than With 536.805.378 triangles still more than

200.000.000 triangles to draw in best case.200.000.000 triangles to draw in best case.

• Frustum culling further reduces number of Frustum culling further reduces number of triangles to drawtriangles to draw

• In most cases we still draw the terrain at In most cases we still draw the terrain at full resolution near the far planefull resolution near the far plane

Page 25: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

25252525

View-Dependent Dynamic View-Dependent Dynamic LODLOD• Dynamic simplification of visible part of Dynamic simplification of visible part of

the terrainthe terrain

• A mountain observed from a distance of A mountain observed from a distance of 10 km requires a higher tessellation than 10 km requires a higher tessellation than when observed from a distance of 100 kmwhen observed from a distance of 100 km

• The quality of the tessellation can be The quality of the tessellation can be changed at run time to achieve constant changed at run time to achieve constant frame ratesframe rates

• Terrains can be altered at run timeTerrains can be altered at run time

Page 26: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

26262626

Terrain LODTerrain LOD• Terrain poses problems for static LOD methodsTerrain poses problems for static LOD methods

– Must have high resolution in the near field, and low Must have high resolution in the near field, and low resolution in the distance, all in one modelresolution in the distance, all in one model

• Dynamic LOD methods are the answerDynamic LOD methods are the answer– All based on the idea of All based on the idea of cutscuts through a tree of through a tree of

potential simplificationspotential simplifications

• ROAM algorithm is a good exampleROAM algorithm is a good example– Other continuous LOD algorithms are similar in styleOther continuous LOD algorithms are similar in style

• An alternative is to create fixed LODs for sub-An alternative is to create fixed LODs for sub-regions and figure out how to join them regions and figure out how to join them together together

Page 27: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

27272727

Terrain LOD AlgorithmsTerrain LOD Algorithms

• Triangle bintree basedTriangle bintree based– ‘‘ROAMing Terrain: Real-time Optimally Adapting ROAMing Terrain: Real-time Optimally Adapting

Meshes’ – Duchaineau et al.Meshes’ – Duchaineau et al.• Quad tree basedQuad tree based

– E.g. ‘Real-Time, Continuous Level of Detail E.g. ‘Real-Time, Continuous Level of Detail Rendering of Height Fields’ – Lindstrom et al.Rendering of Height Fields’ – Lindstrom et al.

• Progressive mesh basedProgressive mesh based– E.g. ‘Smooth View-Dependent Level-of-Detail E.g. ‘Smooth View-Dependent Level-of-Detail

Control and its Application to Terrain Rendering’ Control and its Application to Terrain Rendering’ – Hoppe– Hoppe

• Geo MipmappingGeo Mipmapping– ‘‘Fast Terrain Rendering Using Geometrical Fast Terrain Rendering Using Geometrical

MipMapping’ – de BoerMipMapping’ – de Boer

Page 28: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

28282828

Rendering Fractal Rendering Fractal LandscapesLandscapes• Alternative methods:Alternative methods:

– Polygon rendering using graphics hardwarePolygon rendering using graphics hardware•Tesselate the height fieldTesselate the height field

•Draw each triangle separately orDraw each triangle separately or

•Perform adaptive level-of-detail renderingPerform adaptive level-of-detail rendering

– Ray-tracingRay-tracing•A) Tesselate the height field and trace the A) Tesselate the height field and trace the

triangle meshtriangle mesh

•B) Directly trace the fractal (QEAB) B) Directly trace the fractal (QEAB)

Check out http://www.vterrain.org/

Page 29: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

29292929

Rendering Fractal Rendering Fractal Landscapes Landscapes • Polygon renderingPolygon rendering

– Tesselation is given implicitely or can be generatedTesselation is given implicitely or can be generated A height field over a rectangular domain, values A height field over a rectangular domain, values

are given at discrete sample pointsare given at discrete sample points

Page 30: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

30303030

Rendering Fractal Rendering Fractal LandscapesLandscapes

• Rendering lit and textured triangles Rendering lit and textured triangles – Vertices, colors, texture coords, normalsVertices, colors, texture coords, normals

Textured only Textured and shaded

Page 31: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

31313131

Rendering Fractal Rendering Fractal LandscapesLandscapes• Rendering triangles using graphics hardwareRendering triangles using graphics hardware

– Render triangle strips: Render triangle strips: vv00,v,vXX,v,v11,v,vX+1X+1,v,v22,v,vX+1X+1, ..., ...

• Triangle defined by new point and previous two pointsTriangle defined by new point and previous two points• Each vertex is rendered only onceEach vertex is rendered only once

– Still have to send every vertex even in smooth Still have to send every vertex even in smooth regionsregions

– Popping artefacts where triangles below pixel sizePopping artefacts where triangles below pixel size

V0 V2V1 V3

...

... VX-1

VX VX+2VX+1 VX+3

Page 32: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

32323232

Rendering Fractal Rendering Fractal LandscapesLandscapes• LOD-RenderingLOD-Rendering

– Adaptively refine the mesh with regard to the current viewAdaptively refine the mesh with regard to the current view

Page 33: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

33333333

Rendering Fractal Rendering Fractal LandscapesLandscapes• LOD-RenderingLOD-Rendering

– Top-down or bottom-up approachTop-down or bottom-up approach– Hierarchically partition the meshHierarchically partition the mesh– Start with coarse resolution and adaptively Start with coarse resolution and adaptively

refine until desired level-of-detail is refine until desired level-of-detail is reachedreached

– Start with original mesh and successively Start with original mesh and successively merge trianglesmerge triangles

– Consider world space and/or screen space Consider world space and/or screen space deviationdeviation

– Re-build mesh for every frameRe-build mesh for every frame

Page 34: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

34343434

Rendering Fractal Rendering Fractal LandscapesLandscapes• ROAM: Real-Time Optimally Adapting MeshesROAM: Real-Time Optimally Adapting Meshes

– Exploits triangle bintree structure: split along base edgeExploits triangle bintree structure: split along base edge

– Valid triangulation has to be guaranteedValid triangulation has to be guaranteed• Two triangles have no overlapTwo triangles have no overlap

• Overlap at common vertex/common edgeOverlap at common vertex/common edge

Critical case

Page 35: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

35353535

Rendering Fractal Rendering Fractal LandscapesLandscapes• The recursive split operationThe recursive split operation

– Triangle to be split has coarser base neighbor Triangle to be split has coarser base neighbor • Force split of base neighbor firstForce split of base neighbor first• Recursively force further splits until diamond is foundRecursively force further splits until diamond is found• Diamond can be split without further splitsDiamond can be split without further splits

Page 36: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

36363636

Rendering Fractal Rendering Fractal LandscapesLandscapes• Error criterion for split operationError criterion for split operation

– Deviation in world spaceDeviation in world space•Difference between height value at center Difference between height value at center

vertex and average of left and right vertexvertex and average of left and right vertex

•Recursively pull deviation values from Recursively pull deviation values from bottom to top bottom to top

– Deviation in screen spaceDeviation in screen space•Determine upper bound for screen space Determine upper bound for screen space

length of world space difference vector length of world space difference vector (0,d,0) (0,d,0)

Page 37: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

37373737

Rendering Fractal Rendering Fractal LandscapesLandscapes• Ray-TracingRay-Tracing

– Ray-tracing triangle meshesRay-tracing triangle meshes• Trace rays until a triangle is hitTrace rays until a triangle is hit

• Implicit occlusion cullingImplicit occlusion culling

Page 38: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

38383838

Rendering Fractal Rendering Fractal LandscapesLandscapes• Ray-Tracing - performance issuesRay-Tracing - performance issues

– Mesh data structure has to be storedMesh data structure has to be stored– Hierarchical representation necessary for Hierarchical representation necessary for

improved intersection testimproved intersection test• Octree or kD-treeOctree or kD-tree

max/min(H)

max/min(H)

max/min(H)

Store max/min heights within subregion

Skip regions below minimal height of ray

Employ ray coherences

Page 39: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

39393939

Rendering Fractal Rendering Fractal LandscapesLandscapes• Rendering polygonal models – analysisRendering polygonal models – analysis

– Aliasing due to undersampling of small featuresAliasing due to undersampling of small features– No exploitation of the fractal lod-natureNo exploitation of the fractal lod-nature

© Images K. Musgrave

Page 40: 1 Further Terrain Rendering and Level of Detail Lecture 8 - Week 4 Advanced Programming for 3D Applications CE00383-3

40404040

Other IssuesOther Issues• Terrain Texturing Terrain Texturing • Terrain LightingTerrain Lighting• Camera Animation and Fly-through Camera Animation and Fly-through • SkyBoxSkyBox• Terrain following (a form of collision)Terrain following (a form of collision)

– Maintaining characters and objects on top of Maintaining characters and objects on top of TerrainTerrain