3 D Game Engine Design Chapter 12 Spatial



















- Slides: 19

3 D Game Engine Design Chapter 12. Spatial Sorting Chung Ji Hye 2001. 12. 04 Korea Univ. Graphics Lab.

Overview Why do you use Sorting? l l Correct drawing of a scene To avoid drawing a pixel on the screen multiple times Type of sorting l l l Quadtrees and Octrees Use of portals BSP trees Chung ji hye -2 - Korea University Graphics Laboratory

Quadtrees & Octrees Construction of a scene graph can be based on l l planar locations : Quadtrees Spatial locations : Octrees Partition the world into cell Quadtrees & Octrees l l Attempt to setup visibility graph based on structure of the world and the objects Chung ji hye -3 - Korea University Graphics Laboratory

Quadtrees & Octrees camera. Block = Get. Block. Of(renderer. camera); visible. List = Get. Visible. Cells. From(camera. Block); for(each node in visible. List) renderer. Draw(node); Chung ji hye -4 - Korea University Graphics Laboratory

Portals Portal systems l l l Requires less interaction to setup visibility graph Specify additional planes that trim down the view frustum into smaller pieces Doorway is a portal l l Allows you to see inside the contents Objects hidden by the walls can be culling Partially hidden by the walls can be clipping Useful for indoor style game l Chung ji hye Many walls and other objects obstruct the view -5 - Korea University Graphics Laboratory

Portals Illustration of visibility through a portal Chung ji hye -6 - Korea University Graphics Laboratory

Portals Culling mechanism l l Keep track of a flag of six bits Each bit indicating whether or not the object is culled Flag can be extended to have any number of bits Camera can store additional planes for culling purposes Partition into convex regions Rendering algorithm l Back to front order Chung ji hye -7 - Korea University Graphics Laboratory

Binary Space Partitioning Data structure used to represent the partitioning Object is on the positive side l associated with the front child of the node Object is on the negative side l associated with the back child of the node Sorting polygon by way of a depth first traversal of the tree Chung ji hye -8 - Korea University Graphics Laboratory

BSP Tree P 0 + - P 0 c 0 + P 1 c 3 - P 2 c 1 + - c 4 P 3 C 0 c 2 Chung ji hye P 2 P 1 + C 1 -9 - C 3 C 4 C 2 Korea University Graphics Laboratory

Hidden Surface Removal Back to Front Drawing l l l Background first and foreground last Positive side of the plane Dot products l l used to determine the object is in the cone of the view frustum Partition plane l Chung ji hye Intersects the view frustum -10 - Korea University Graphics Laboratory

Hidden Surface Removal Front to Back Drawing Draw the polygons closet to the eye point l Pixel don’t be overwritten l Only use when it is known what order the polygons are l Chung ji hye -11 - Korea University Graphics Laboratory

Scan Line Masks Scan Line Method Keep track of each scan line separately l Interval [x 0, x 1) l l Chung ji hye Left end point is included, right end point is not included -12 - Korea University Graphics Laboratory

Scan Line Masks Screen width is W pixel [0, W) Triangle is rasterized on that scan line in the interval [x 0, x 1) Value X 0 causes split [0, x 0) , [x 0, w) [0, x 0) x 0 [x 0, w) x 1 [x 0, x 1) Chung ji hye -13 - [x 1, w) Korea University Graphics Laboratory

Scan Line Masks New initial interval [x 2, x 3) l Supposed that 0<= x 0 <x 2 <x 1 <x 3 <= w Comparing x 2 against x 1 l Left child is interval of drawn pixel no splitting occur Comparing x 3 against leaf node [x 1, w) l Undrawn pixel Splitting occur [x 1, x 3) and [x 1, w) Chung ji hye -14 - Korea University Graphics Laboratory

Scan Line Masks Representing BSP Tree [0, w) [0, x 0) x 0 [x 0, w) x 1 [x 0, x 1) [x 1, w) x 2 x 3 [x 1, x 3) Chung ji hye -15 - [x 3, w) Korea University Graphics Laboratory

Visibility Determination Deciding what part of the world are visible from that location Knowing what is visible helps to minimize the data is sent to the renderer Can be used for occlusion culling View space method l Visibility tree Screen space method l World tree Chung ji hye -16 - Korea University Graphics Laboratory

View Space Method Three dimension Represents the view frustum Compares objects and parts of objects to each other Chung ji hye -17 - Korea University Graphics Laboratory

Screen Space Method Two Dimension Initially represents the rectangle l corresponding to the drawable pixels on the screen World tree sorts the polygons from Front to back l Visible subpolygon obtained in the clipping Subpolygons can be stored in a list l Whatever purposes the application requires Chung ji hye -18 - Korea University Graphics Laboratory

Quadtrees & Octrees Chung ji hye -19 - Korea University Graphics Laboratory