Simulation Engines TDA571|DIT030 3D Graphics - Part 1 Tommaso - - PowerPoint PPT Presentation

simulation engines tda571 dit030 3d graphics part 1
SMART_READER_LITE
LIVE PREVIEW

Simulation Engines TDA571|DIT030 3D Graphics - Part 1 Tommaso - - PowerPoint PPT Presentation

Simulation Engines TDA571|DIT030 3D Graphics - Part 1 Tommaso Piazza 1 3D Graphics IDC | Interaction Design Collegium 2 Once again... Real-time 3D graphics is all about triangles Properties of a renderable triangle Vertices


slide-1
SLIDE 1

Simulation Engines TDA571|DIT030 3D Graphics - Part 1

Tommaso Piazza

1

slide-2
SLIDE 2

IDC | Interaction Design Collegium

3D Graphics

2

slide-3
SLIDE 3

IDC | Interaction Design Collegium

Once again...

  • Real-time 3D graphics is all about triangles
  • Properties of a renderable triangle
  • Vertices
  • Normals
  • Vertex order
  • (Tangents)
  • (Binormals/Bitangents)
  • (...)
  • 3D graphics is the art of coloring triangles.

3

slide-4
SLIDE 4

IDC | Interaction Design Collegium

3D Graphics is also about...

  • Vectors
  • Matrices
  • Quaternions
  • Loads and loads of mathematical operations
  • n the above.
  • If you feel that you are shaky on vector

algebra, take a look in your old math books. You will thank yourself later.

4

slide-5
SLIDE 5

IDC | Interaction Design Collegium

Categorization of 3D entities

  • Static
  • Objects that are immutable
  • Good candidates for extreme optimization
  • Dynamic
  • Moves or changes over time
  • Harder to optimize
  • Animated
  • Could be either static or dynamic
  • The vertex object can not be locked

5

slide-6
SLIDE 6

IDC | Interaction Design Collegium

Spatial data structures

  • Demands on real-time graphics grow rapidly
  • Modern graphics hardware is:
  • Fast
  • Programmable
  • Has plenty of memory
  • However...
  • ”The fastest polygon to render is the one never

sent down to the accelerator's pipeline.”

6

slide-7
SLIDE 7

IDC | Interaction Design Collegium

Words of wisdom

  • Performances are
  • "25k batches/s @ 100% 1GHz CPU"
  • To run smoothly
  • (i 60fps, 417 batches)

7

slide-8
SLIDE 8

IDC | Interaction Design Collegium

Spatial data structures

  • A spatial data structure:
  • Orders geometric data by its location
  • Is often hierarchic, which allows O(log n) searches

and rapidly discarding irrelevant data

  • Spatial data structures can be expensive to
  • construct. Construction is often preprocessed
  • Separate structures for static and dynamic data

8

slide-9
SLIDE 9

IDC | Interaction Design Collegium

Spatial Data Structures

  • Sample applications
  • Collision detection
  • Location queries
  • Chemical simulations
  • Rendering

9

slide-10
SLIDE 10

IDC | Interaction Design Collegium

Bounding volume hierarchies

  • In general: better fit = more memory and

more expensive intersection algorithm

  • Axis-Aligned Bounding Boxes (AABB)
  • The simplest type of bounding box
  • Enclosed by a model's minimum and maximum

values along the x-, y- and z-axis

  • Ordinarily described by a center and the distance

from the center to the edge along each axis

10

slide-11
SLIDE 11

IDC | Interaction Design Collegium

Bounding volume hierarchies

  • Oriented Bounding Boxes (OBB)
  • Similar to AABB's, but rotated to fit the model more

tightly

  • Ordinarily described by a center, three normalized

vectors and the distance from the center to the edges

  • k-Discrete Oriented Polytope (k-DOP)
  • Consists of k/2 normalized plane-normals associated

with two scalars. Together they describe the volume between the two planes

  • The k-DOP is the volume enclosed by all planes

11

slide-12
SLIDE 12

IDC | Interaction Design Collegium

Bounding volume hierarchies

http://udn.epicgames.com/Two/CollisionTutorial.html

12

slide-13
SLIDE 13

IDC | Interaction Design Collegium

Outdoor scenery

  • Outdoor scenery is rarely represented in the

same fashion as indoor scenery

  • The main problem is the scale of outdoor

scenery

  • Outdoor scenery often needs special

considerations for optimization

  • Continuous level of detail

13

slide-14
SLIDE 14

IDC | Interaction Design Collegium

Heightmap

  • The most common representation of a terrain
  • Generally stored in a grayscale 2D texture
  • Often divided into several smaller objects and

rendered as series of triangle strips

14

slide-15
SLIDE 15

IDC | Interaction Design Collegium

Cracks in the terrain

  • Beware of cracks in the terrain when

rendering with non-uniform tessellation

  • Different levels of detail
  • Limited numerical accuracy in 3D card or API
  • Can be avoided by drawing “skirts”
  • Multiple techniques for this...

15

slide-16
SLIDE 16

IDC | Interaction Design Collegium

The ROAM algorithm

  • The Realtime Optimally Adapting Meshes

algorithm was designed as a high- performance, flexible terrain rendering algorithm with continuous LOD

  • Uses a special data structure called a “triangle

bintree” and two priority queues that drive the split and merge operations of patches in the heightmap based on the location of the camera

16

slide-17
SLIDE 17

IDC | Interaction Design Collegium

Trends in terrain rendering

  • On modern hardware, algorithms like ROAM

use unnecessarily much CPU-power

  • Fillrate and triangle-drawing capabilities on

modern 3D hardware are very good

  • Nowadays, terrain rendering is mostly done by

grouping blocks of terrain patches into vertex buffer objects of just a few detail levels, and culled using only view frustum culling

17

slide-18
SLIDE 18

IDC | Interaction Design Collegium

Volumetric terrain rendering

  • Uses voxels (volume pixels)
  • Can be used with 3D scans
  • Can be used to render heightmaps
  • Potentially very high resolution
  • Used in Comanche: Maximum overkill, 1992
  • No hardware support

18

slide-19
SLIDE 19

IDC | Interaction Design Collegium

Skyboxes and skydomes

  • Used to render the background of 3D scenes
  • Waste of resources to draw small background objects as

meshes

  • Drawn in the following way
  • Clear depth and color buffers
  • Apply camera transformation
  • Disable the depth buffer test

and writes

  • Draw the skybox or skydome
  • Enable depth buffer test and

writes

  • Draw the rest of the scene

19

slide-20
SLIDE 20

IDC | Interaction Design Collegium

Indoor scenery

  • Data is organized in a very different manner

than for outdoor scenery

  • Very different scales than for outdoor scenery
  • The existence of enclosing walls and ceilings

give excellent opportunities for culling

  • Thanks to the smaller scale, requirements on

detail are much greater than outdoors

  • Tim Sweeney estimates that we have a factor
  • f 10.000 to 40.000 to go before we are able to

render photo-realistic indoor environments

20

slide-21
SLIDE 21

IDC | Interaction Design Collegium

Uniform grids

  • The world is split into uniformly

sized voxels (in 3D) or squares (in 2D)

  • Very easy to implement
  • Relatively efficient with ray-grid-

intersection tests, therefore often used for raytracing

  • http://www.cs.yorku.ca/~amana/

research/grid.pdf

  • Useful for dynamic data

21

slide-22
SLIDE 22

IDC | Interaction Design Collegium

Binary space partitioning trees

  • Have been popular since they were used in

DOOM

  • Was originally designed to solve depth sorting

in the late 60's.

  • Sorts geometry by splitting along planes
  • Axis-aligned
  • Also known as KD-tree.
  • Ordinarily built by alternating the splitting axis.
  • Polygon-aligned
  • The most commonly used variant in games

22

slide-23
SLIDE 23

IDC | Interaction Design Collegium

Quad trees

  • Two-dimensional

representation

  • Similar to KD-trees, but

always split in the middle

  • Useful for representing
  • utdoor environments which

are represented with height- maps

23

slide-24
SLIDE 24

IDC | Interaction Design Collegium

Octtrees

  • Like quad trees, but in 3D
  • Efficient for large three-

dimensional spaces

  • Often have criteria for how

many children are needed in a voxel before splitting it as well as how many levels of hierarchy are allowed

  • Structures where the voxels

do not necessarily have the same size are called loose

  • ctrees/quadtrees

24

slide-25
SLIDE 25

IDC | Interaction Design Collegium

Culling

  • Culling is the act of removing polygons that

do not need to be rendered

  • Can be done by either the CPU or the GPU
  • Culling on CPU generally saves bandwidth
  • Culling on GPU (probably) saves CPU-time
  • Modern hardware stores geometry in vertex

buffers, and encourages culling per object instead of per polygon, because that allows reusing of vertex buffer objects

25

slide-26
SLIDE 26

IDC | Interaction Design Collegium

Software vs. Hardware culling

GPU Viewport clipping Z-buffer testing Backface culling CPU View frustum culling Occlusion culling Backface culling

26

slide-27
SLIDE 27

IDC | Interaction Design Collegium

Backface culling

  • Ordinarily done in the

geometry stage of the

  • pipeline. All data is sent to

the GPU, but only visible pixels are rasterized

  • A polygon is backfacing if

n·v < 0

  • The amount of rendered

triangles is normally reduced by 50%

27

slide-28
SLIDE 28

IDC | Interaction Design Collegium

View frustum culling

  • Culls objects that are
  • utside of the view frustum
  • The view frustum is volume

enclosed by six planes that is visible from the camera

  • Very efficient when used on a

hierarchy of spatial data structure

28

slide-29
SLIDE 29

IDC | Interaction Design Collegium

Example: View frustum culling over an octtree

  • The view frustum is represented by six planes

that point to the inside of the enclosed volume

  • Recurse over the following algorithm for voxels

in the octtree, beginning with the voxel that contains the entire tree:

  • If the voxel is outside of any of the planes, do

not draw it

  • If the voxel is inside all of the planes, draw all of

its contents

  • If the voxel intersects any of the planes, perform

this test for all of its children

29

slide-30
SLIDE 30

IDC | Interaction Design Collegium

Occlusion culling

  • Performed per pixel by the Z-buffer by the GPU
  • View frustum culling does not discard
  • bjects which are hidden behind other
  • bjects
  • With frustum culling and similar methods, data

structures overestimate the size of objects. With

  • cclusion culling, silhouettes which

underestimate sizes are used

  • There are hardware extensions for occlusion

culling

30

slide-31
SLIDE 31

IDC | Interaction Design Collegium

Portal culling

  • A special case of occlusion culling.
  • Data is partitioned into rooms. Their

insides are only visible through portals (windows, doors, etc.).

  • Frustum culling is recursively

performed on the volumes that are created between the camera and the portal

  • Ordinarily, engines use either portal- or

BSP-structures

  • Artist controlled

31

slide-32
SLIDE 32

IDC | Interaction Design Collegium

Antiportals

  • Relatively modern technique.
  • Artist-controlled method of occlusion culling
  • Antiportals are similar to portals, but instead of

revealing objects, data within the frustum between the camera and the antiportal is culled.

  • Used by the Unreal Engine from UT2003 and
  • nward.

32

slide-33
SLIDE 33

IDC | Interaction Design Collegium

Level of detail

  • LOD is based on the assumption that fewer

triangles are needed to visualize an object when it is further away from the camera

  • Two alternative ways:
  • Static: several precreated alternative models are

used.

  • Dynamic: a single model is altered in runtime.
  • LOD is also applicable for materials.

33

slide-34
SLIDE 34

IDC | Interaction Design Collegium

Static LOD

  • One of several pre-created models is drawn

depending on the distance to it

  • Fast and simple but requires more memory and

more work with creating alternative models

  • Artifacts may arise when switching models. This

can be solved by blending between the models (preferably in a vertex program on the GPU)

  • Be careful not to be counterproductive. Too

many levels or distance functions may result in even more data being sent to the GPU

34

slide-35
SLIDE 35

IDC | Interaction Design Collegium

Dynamic LOD

  • Less ”popping” than with LOD, but

likely creates models that look worse than those created by artists

  • Uses more CPU-time than static LOD
  • Two popular methods:
  • Continuous Level of Detail (CLOD):

Removes the edge between two triangles when its two vertices are close to each

  • ther
  • Geomorph Level of Detail: Builds on

CLOD, but interpolates intermediate positions for corners before merging

35

slide-36
SLIDE 36

IDC | Interaction Design Collegium

Static objects

  • Static objects in 3D have immutable

geometry and are only subject to affine transformations

  • Possible optimizations
  • Storage
  • Since the geometry never changes, we only need one

copy of each object, even if we have multiple instances of it in our scene

  • Rendering
  • The static nature of the geometry allows for rendering
  • ptimizations such as display lists and vertex arrays and

buffers

36

slide-37
SLIDE 37

IDC | Interaction Design Collegium

Vertex arrays/objects/buffers

  • The traditional OpenGL way of rendering consist
  • f a lot of glBegin, glEnd, glVertex, glNormal, etc.
  • Unnecessary work
  • OpenGL introduced vertex arrays
  • Vertex buffers in Direct3D
  • Specifies a block of vertices for reuse
  • Thanks to hardware T&L (transform and lightning) and

locking the vertex array, the 3D card can perform most of this work without CPU intervention

  • OpenGL uses VBOs nowadays

37

slide-38
SLIDE 38

IDC | Interaction Design Collegium

Characters

  • Characters tend to be subject to vertex

animation

  • Vertex arrays can not be locked
  • Often animated with use of skeletal animation
  • Can be done almost entirely in hardware, which

allows for locked arrays

  • Morph targets
  • Harder to do in hardware, but optimizations can be

done

38

slide-39
SLIDE 39

IDC | Interaction Design Collegium

Data structures in Ogre

  • Ogre allows you to choose between multiple

Scene Managers which use different data structures.

  • Octtree
  • Terrain: Uses an octtree for objects and a grid for the

terrain.

  • Nature Scene Manager (ogreaddons)
  • Paging Scene Manager (ogreaddons)
  • BSP Scene Manager: Certain legal problems.
  • Dot Scene Manager (ogreaddons): Recommended

instead of BSP in the documentation. Uses an octtree.

39

slide-40
SLIDE 40

IDC | Interaction Design Collegium

Culling in Ogre

  • A few quotes from the forum:
  • ”The scene manager culling method. This is customized based
  • n the scene manager being used; for example the BSP

manager culls based on bsp leaves, the octree manager culls based on an octree etc. Normally these managers cull at a high level though, bounding boxes typically.”

  • ”Frustum culling. Once the scene manager has identified

potentially visible chunks, a basic frustum cull is done based on the bounding box.”

  • ”GPU culling. The GPU will eliminate backface triangles (unless

you change the culling mode in the .material) and offscreen triangles will be discarded during primitive assembly.”

40

slide-41
SLIDE 41

IDC | Interaction Design Collegium

Ogre tips

  • Read about the Ogre scene managers at:

http://www.ogre3d.org/wiki/index.php/ SceneManagersFAQ

  • Read about terrains in Ogre at:

http://www.ogre3d.org/wiki/index.php/ TerrainHowto

  • Siggraph papers can be read for free from

Chalmers computers at: http://portal.acm.org/portal.cfm

  • Google-equivalent:

http://scholar.google.se/

41