930 likes | 950 Views
Voxel Game Engine Development. Yingcai Xiao. Game Engine Development. What do we need? What tools do we have? How can we design and implement? We will answer those questions in an agile way. What do we need?. Video Game: Interactive animation. Display Device Driver (GDI).
E N D
Voxel Game Engine Development • Yingcai Xiao
Game Engine Development What do we need? What tools do we have? How can we design and implement? We will answer those questions in an agile way.
Video Game: Interactive animation Display Device Driver (GDI) Input Device Driver Game (Software)
Video Game: Interactive animation Similar to all other programs: data, algorithms, input, output. Data: Game Objects Algorithms: Animation Input: Interactive Events Output: Display
Data: Game Objects Voxelization: to partition a volume into connected voxels. Two types of voxelization: game objects game space
Data: Game Objects Voxel: volume element, the smallest element of a volume. Geometry: hexahedron, tetrahedron, … Attributes: two types: single-valued: one value for each voxel multi-valued: one value for each corner of the voxel
Voxelization of A Game Space To partition a game space into connected voxels. Uniform Grid Rectlinear Grid Structured Grid Unstructured Grid
Uniform Grid • Uniform Grid (uniform in each direction) • Parameters: • Dimension: nx, ny, nz • Origin: x0, y0, z0 • Spacing: dx, dy, dz
Uniform Grid • IJK space • x = i*dx + x0 • y = j*dy + y0 • z = k*dz + z0 • AttributeArray [i, j, k], loops i first, then j, k last. • Simple, compact and speedy retrieval. • Not flexible • 2D equivalent: Elevation Grid
Rectlinear Grid • Dimension: nx, ny, nz • Nonuniform spacing, but straight grid lines. float x[44]={0.0,1.2,2.8,3.9…….} float y[33]={1.0,……………} float z[22]={0.8,……………}
Rectlinear Grid • IJK space. x = x[I]; y = y[J]; z = z[K]; • Data array (i, j, k), i changes first, then j, k last. • Simple • compact (takes O(nx +ny + nz) more space) • speedy retrieval • Little more flexible
Characteristics of GO Data Structure • DiscreteInterpolation • P1, P2 • Regular/Irregular • Data Dimensions
Data Structure Design Criterion • Compact (save space) • Efficient (fast retrieval) • Map-able (easy to convert) • Minimal Coverage (small foot prints) • Simple (easy to use)
Dataset for a Game Object • Two parts: • Structure • Attributes
Dataset • Structure: topology and geometry • Topology: is the set of properties invariant under certain geometric transformations. • Geometry: is the instantiation of the topology; the specification of positions in a 3D space.
Dataset • Dataset Attribute: • Color • Normal (shading) • Texture coordinates (texture mapping) • Material properties (strength, temperature, …)
Cell Types • A data set consists of one or more cells • A cell is defined by a “type” and an ordered list of point • Type: topology, cell type • Ordered list: geometry, points • Together: organizational structure • Use Set: all the cells using a point: • U(pi) = {Ci: pi Ci}
Cell Types Vertex: zero-dimensional cell, It is defined by a single point. Line: one dimensional cell. It is defined by two points. Polyline: is a composite one-dimensional cell consisting of n connected lines. It is defined by an ordered list of n+1 points. Triangle: is a primary two-dimensional cell. The triangle is defined by a counter-clockwise ordered list of three points. Triangle is a 2D simplex. Polygon: is a primary two-dimensional cell. The polygon is defined by an ordered list of three or more points lying in a plane Tetrahedron: is a primary three-dimensional cell. It is defined by a list of four nonplanar point. Tetrahedron is a 3D simplex.
Data Structure (DS) for Game Objects (GO) indexed structure:
Data Structure (DS) for Game Objects (GO) Convert a uniform grid into an indexed mesh. O(0,0,0) D(1,1,1) 3x3x3
Data Structure (DS) for Game Objects (GO) Convert a surface of two connected triangle into an indexed mesh. P0(0,0,0) P1(1,0,0) P2(1,1,0) P3(0,1,0)
Data Structures forGame SpaceUniform Grid:2D: Elevation Grid of Terrain3D: Voxel Space
Uniform Grid • Uniform Grid (uniform in each direction) • Parameters: • Dimension: nx, ny, nz • Origin: x0, y0, z0 • Spacing: dx, dy, dz
Uniform Grid • IJK space • x = i*dx + x0 • y = j*dy + y0 • z = k*dz + z0 • AttributeArray [i, j, k], loops i first, then j, k last. • Simple, compact and speedy retrieval. • Not flexible • 2D equivalent: Elevation Grid
Data Structures forGame ObjectIndexed Structure:Topology (Cells)Geometry (Points)Attributes (Data)
Data Structure (DS) for Game Objects (GO) indexed dataset:
Algorithms for Voxel Based Game Engine
Algorithms for Construction of Game Space
Construction of Dataset for GS & GO
Constructing a Uniform Grid • Define the bounding box • Specify the dimension: nx, ny, nz • Set the origin: x0, y0, z0 • Compute the spacing: dx, dy, dz
Triangulated Networks • Delaunay Triangulation
Data collected in the real world • Can we use local interpolation with the closest points? • Need to find and connect the closest points. • Demo in 2D.
Visualizing Unstructured Points Triangulation: Connect points to form a triangulated topological structure. (topology generation)
Triangulation • Use Edge Swapping to make a Delaunay Triangulation. • Find the minimum bounding triangle. (may need to add a fake point) • Add one point at a time, do triangulation. • After each point is added, check if the joined triangles are optimal or not; if not swap the joining edge (edge swapping). Check all other triangles and make sure they are still optimal after adding the current point. • Repeat step 3 to add each point and we when all points are added and all triangles are optimal. • Clean up: remove all fake points and related triangles.
Triangulation • Properties of Delaunay Triangulation: • Circumsphic property: no other points in the circumspheres. • Optimal property: The minimum interior angle of a triangle is greater than or equal to the minimum interior angle of any other triangulation • It is the dual of the Diritchlet tessellation • Voronoi cell, Centroid • A collection of connected Voronoi cells tessellete the area (partition, coverage)
Triangulation Formal definition of Triangulation: N dimensional triangulation of a point set P=(P1, P2, ……,Pn) is a collection of N-dimensional simplexes (triangles) whose defining points lie in P. Optimal Triangulation: a triangulation that generates maximized minimum angles. Delaunay Trianglation: an optimal triangulation, which satisfies the circumshpere condition. Circumsphere Condition: the circumshpere of any N-dementional simplex contains no other points of P except the n+1 points defining the simplex.
Traversing Gaming Space (Image created by Russell Yuncker) (Image created by Jian He)
Follow predefined paths • Follow pre-partitioned spaces • Follow line of sights • Collision detection Traversing Gaming Space
Used in maze games. • 3D Maze 2: an Android app. • The predefined paths are usually bounded by predefined structures. • Simple bounding structures can be designed in game engines. • Complicated bounding structures can be designed in a Computer Aided Design software. TGS: Following predefined paths
AutoDesk provides CAD software for different industries. • AutoCAD and 3DS Max for manufacturing industry. • Maya for entertainment industry. • Develop their own games. • All tools are free for students TGS: Following predefined paths
For voxelized game space, use IJK space to traverse. • x = i*dx + x0 • y = j*dy + y0 • z = k*dz + z0 • i = (x - x0) / dx • j = (y - y0) / dy • k = (z - z0) / dz TGS: Follow pre-partitioned spaces
Line of sight for eyes: image generation • Line of sight for lights: shadow • Line of sight for objects: collision • Commonly use the ray tracing technique. • TGS: Follow line of sights
Simple Ray Tracing for Image Generation for (each scan line in image ) { for (each pixel in the scan line ) { determine ray from eye through pixel; for(each object in scene) { if(object is intersected and is the closest considered thus far) record intersection point and object id. } set pixel’s color to that at closest object intersection point (using the REGULAR I formula.) } }
Shading Shading: determining light reflection from objects at a pixel. Basic Reflection Model: Phong Reflection Model (most commonly used) I= kaIa + kd Id (l · n) + ksIs(v · r )α I : reflected-light intensity