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 Normals Vertex order ( Tangents ) (Binormals/Bitangents) (...) 3D graphics is the art of coloring triangles. IDC | Interaction Design Collegium 3
3D Graphics is also about... Vectors Matrices Quaternions Loads and loads of mathematical operations on 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. IDC | Interaction Design Collegium 4
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 IDC | Interaction Design Collegium 5
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 .” IDC | Interaction Design Collegium 6
Words of wisdom Performances are "25k batches/s @ 100% 1GHz CPU" To run smoothly (i 60fps, 417 batches) IDC | Interaction Design Collegium 7
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 IDC | Interaction Design Collegium 8
Spatial Data Structures Sample applications Collision detection Location queries Chemical simulations Rendering IDC | Interaction Design Collegium 9
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 IDC | Interaction Design Collegium 10
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 IDC | Interaction Design Collegium 11
Bounding volume hierarchies http://udn.epicgames.com/Two/CollisionTutorial.html IDC | Interaction Design Collegium 12
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 IDC | Interaction Design Collegium 13
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 IDC | Interaction Design Collegium 14
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... IDC | Interaction Design Collegium 15
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 IDC | Interaction Design Collegium 16
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 IDC | Interaction Design Collegium 17
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 IDC | Interaction Design Collegium 18
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 IDC | Interaction Design Collegium 19
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 of 10.000 to 40.000 to go before we are able to render photo-realistic indoor environments IDC | Interaction Design Collegium 20
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 IDC | Interaction Design Collegium 21
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 IDC | Interaction Design Collegium 22
Quad trees Two-dimensional representation Similar to KD-trees, but always split in the middle Useful for representing outdoor environments which are represented with height- maps IDC | Interaction Design Collegium 23
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 octrees/quadtrees IDC | Interaction Design Collegium 24
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 IDC | Interaction Design Collegium 25
Software vs. Hardware culling GPU CPU Viewport clipping View frustum culling Z-buffer testing Occlusion culling Backface culling Backface culling IDC | Interaction Design Collegium 26
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% IDC | Interaction Design Collegium 27
View frustum culling Culls objects that are outside 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 IDC | Interaction Design Collegium 28
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 IDC | Interaction Design Collegium 29
Occlusion culling Performed per pixel by the Z-buffer by the GPU View frustum culling does not discard objects which are hidden behind other objects With frustum culling and similar methods, data structures overestimate the size of objects. With occlusion culling, silhouettes which underestimate sizes are used There are hardware extensions for occlusion culling IDC | Interaction Design Collegium 30
Recommend
More recommend