Chapter 13 scene management
This presentation is the property of its rightful owner.
Sponsored Links
1 / 123

CHAPTER 13 Scene Management PowerPoint PPT Presentation


  • 86 Views
  • Uploaded on
  • Presentation posted in: General

CHAPTER 13 Scene Management. ( 友鈞 , 思元 , 紘瑋 , 章民 , 昭泉 , 琮凱 , 冠逸 ). Introduction ( 友鈞 ) The Concept of Scene Management ( 友鈞 ) Scene Management Techniques ( 紘瑋 ) Implementing a BSP Tree ( 思元 ) Class Declaration ( 章民 ) Implementing an Octree ( 琮凱 )

Download Presentation

CHAPTER 13 Scene Management

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Chapter 13 scene management

CHAPTER 13Scene Management

(友鈞,思元,紘瑋,章民,昭泉,琮凱,冠逸)

13. Scene Management


Agenda

  • Introduction (友鈞)

  • The Concept of Scene Management (友鈞)

  • Scene Management Techniques (紘瑋)

  • Implementing a BSP Tree (思元)

  • Class Declaration (章民)

  • Implementing an Octree (琮凱)

  • Demo Application: Octree and BSP Tree (冠逸)

  • One Look Back, Two Steps Forward (昭泉)

Agenda

13. Scene Management


Introduction the concept of scene management

Introduction & The Concept of Scene Management

Speaker: Icarus

13. Scene Management


Introduction

  • ■ Learning the concepts of scene management

  • ■ Understanding quadtrees and terrain rendering

  • ■ Using BSP trees and octrees for collision detection

  • ■ Understanding what a portal engine is

  • ■ Implementing a BSP tree and an octree

  • ■ Using the code in the demo application

Introduction

13. Scene Management


The concept of scene management

  • The term scene management describes algorithms and methods that let you select only the polygons that are needed for a certain location and orientation of the viewer out of the whole set of a hundred thousand polygons of the level.Most of those polygons are not visible to the user.

The Concept of Scene Management

13. Scene Management


The concept of scene management1

  • The removal of polygons that cannot be seen from a certain position and orientation of the viewer (because they are completely hidden behind other polygons) is called hidden surface removal, or HSR.

  • Another term for this is occlusion culling

    --------------------HOM, Occlusion frustum

  • View frustum culling

The Concept of Scene Management

13. Scene Management


Chapter 13 scene management

Q&A

13. Scene Management


Scene management techniques

Scene Management Techniques

Speaker: XJACK, Hsu

GAMELab/CSIE/NDHU

13. Scene Management

8


Outline

Outline

Overview

No Solution Is Also a Solution

Continuous and Discrete Level of Detail

Quadtrees

Octrees

Binary Space Partitioning Trees

Portal Engines

Potential Visibility Set

GAMELab/CSIE/NDHU

13. Scene Management

9


Outline1

Outline

Overview

No Solution Is Also a Solution

Continuous and Discrete Level of Detail

Quadtrees

Octrees

Binary Space Partitioning Trees

Portal Engines

Potential Visibility Set

GAMELab/CSIE/NDHU

13. Scene Management

10


Overview

Overview

  • You should always separate your algorithm in terms of the setting in which they should be used

  • Types of games

    • Indoor

    • Outdoor

    • No-door

GAMELab/CSIE/NDHU

13. Scene Management

11


Outline2

Outline

Overview

No Solution Is Also a Solution

Continuous and Discrete Level of Detail

Quadtrees

Octrees

Binary Space Partitioning Trees

Portal Engines

Potential Visibility Set

GAMELab/CSIE/NDHU

13. Scene Management

12


No solution is also a solution

No Solution Is Also a Solution

The basic method : brute force approach

In outdoor games that feature a number of small buildings

Using this to save you a lot of development time and headaches

GAMELab/CSIE/NDHU

13. Scene Management

13


Outline3

Outline

Overview

No Solution Is Also a Solution

Continuous and Discrete Level of Detail

Quadtrees

Octrees

Binary Space Partitioning Trees

Portal Engines

Potential Visibility Set

GAMELab/CSIE/NDHU

13. Scene Management

14


Continuous and discrete level of detail

Continuous and Discrete Level of Detail

  • Scene management

    • Not only about removing whole objects from scene

    • More you can do

  • Level of detail (LOD)

GAMELab/CSIE/NDHU

13. Scene Management

15


Continuous and discrete level of detail1

Continuous and Discrete Level of Detail

  • Discreet LOD

  • Continuous LOD

    • Start from the most detailed version of the model and calculates a less detailed version on-the-fly

    • Suited for big, complex objects

GAMELab/CSIE/NDHU

13. Scene Management

16


Outline4

Outline

Overview

No Solution Is Also a Solution

Continuous and Discrete Level of Detail

Quadtrees

Octrees

Binary Space Partitioning Trees

Portal Engines

Potential Visibility Set

GAMELab/CSIE/NDHU

13. Scene Management

17


Quadtrees

Quadtrees

  • You already know the frustum culling text

  • Disadvantage

    • You have to test each object in the game

  • Quadtrees

    • Suited to tread 2D problem

    • 3D => 2D

GAMELab/CSIE/NDHU

13. Scene Management

18


Quadtrees1

Quadtrees

GAMELab/CSIE/NDHU

13. Scene Management

19


Quadtrees2

Quadtrees

  • Suppose the game is played in first-person view with the player walking around village

  • Why?

    • Less calculate

  • How?

    • Start from the root by subdividing the big rectangle in to 4 rectangles

  • When?

    • A leaf must not contain polygons from more than a single house

GAMELab/CSIE/NDHU

13. Scene Management

20


Quadtrees3

Quadtrees

GAMELab/CSIE/NDHU

13. Scene Management

21


Quadtrees4

Quadtrees

Heightmap is the most common way to represent the data of a terrain

GAMELab/CSIE/NDHU

13. Scene Management

22


Quadtrees5

Quadtrees

It is rather stupid to generate four rectangles with eight triangles

You can achieve the same result by using only one rectangle with two triangles

GAMELab/CSIE/NDHU

13. Scene Management

23


Quadtrees6

Quadtrees

  • The theory of applying quadtrees to terrain rendering

  • For example

    • 9 * 9 heightmap

    • 3 * 3 terrain block

GAMELab/CSIE/NDHU

13. Scene Management

24


Quadtrees7

Quadtrees

The theory of applying quadtrees to terrain rendering

GAMELab/CSIE/NDHU

13. Scene Management

25


Quadtrees8

Quadtrees

GAMELab/CSIE/NDHU

13. Scene Management

26


Quadtrees9

Quadtrees

No gain in performance?

Normal view frustum culling with the nodes bounding boxes

If a node is not inside, you can ignore it and all of its child nodes

Implement LOD

GAMELab/CSIE/NDHU

13. Scene Management

27


Quadtrees10

Quadtrees

GAMELab/CSIE/NDHU

13. Scene Management

28


Quadtrees11

Quadtrees

GAMELab/CSIE/NDHU

13. Scene Management

29


Quadtrees12

Quadtrees

GAMELab/CSIE/NDHU

13. Scene Management

30


Outline5

Outline

Overview

No Solution Is Also a Solution

Continuous and Discrete Level of Detail

Quadtrees

Octrees

Binary Space Partitioning Trees

Portal Engines

Potential Visibility Set

GAMELab/CSIE/NDHU

13. Scene Management

31


Octrees

Octrees

The same thing that you do with quadtrees in 2D can be done in 3D

Octrees

GAMELab/CSIE/NDHU

13. Scene Management

32


Octrees1

Octrees

  • The stop condition is basically the same as in the quatree

  • Two solution for the situation of when an object will not fit completely into one single node

    • Cut the object into two separate objects

    • Not cut but store them only on the node where their point lies

  • We implement an octree at the end of this chapter

GAMELab/CSIE/NDHU

13. Scene Management

33


Outline6

Outline

Overview

No Solution Is Also a Solution

Continuous and Discrete Level of Detail

Quadtrees

Octrees

Binary Space Partitioning Trees

Portal Engines

Potential Visibility Set

GAMELab/CSIE/NDHU

13. Scene Management

34


Binary space partitioning trees

Binary Space Partitioning Trees

  • The BSP tree can partition the space or the geometry that occupies space using arbitrary partitioning planes

  • Advantage

    • You do not need to split as many polygons

    • You can even adjust the algorithm’s heuristic to avoid splits

  • The BSP tree is a data structure that stores the result of the BSP algorithm

GAMELab/CSIE/NDHU

13. Scene Management

35


Binary space partitioning trees1

Binary Space Partitioning Trees

  • Convex polygon Concave polygon

GAMELab/CSIE/NDHU

13. Scene Management

36


Binary space partitioning trees2

Binary Space Partitioning Trees

A collection of polygons in 3D space is convex when you can go into each position inside the convex and look in each direction

By dividing a complex 3D level into a lot of convex groups, you can render a whole level without the need for a depth buffer

GAMELab/CSIE/NDHU

13. Scene Management

37


Binary space partitioning trees3

Binary Space Partitioning Trees

GAMELab/CSIE/NDHU

13. Scene Management

38


Binary space partitioning trees4

Binary Space Partitioning Trees

GAMELab/CSIE/NDHU

13. Scene Management

39


History of bsp tree in video games

History of BSP tree in Video games

BSP algorithm was originally developed in the end of the 1970s at the university of Texas at Dallas

Henry Fuchs and Zvi Kedem

Bruce Naylor

Predetermining Visibility Priority in 3D Scenes [SIGGRAPH 79]

On Visible Surface Generation by A Priori Tree Structures[SIGGRAPH 80]

A priori Based Techniques for Determining Visibility Priority for 3D Scenes

GAMELab/CSIE/NDHU

13. Scene Management

40


History of bsp tree in video games1

History of BSP tree in Video games

DOOM 1 in December 1993

GAMELab/CSIE/NDHU

13. Scene Management

41


History of bsp tree in video games2

History of BSP tree in Video games

DOOM 1 uses a 2D BSP algorithm and BSP tree

GAMELab/CSIE/NDHU

13. Scene Management

42


History of bsp tree in video games3

History of BSP tree in Video games

Quake 1 by id software in June 1996

This was the first video game that used a real 3D BSP algorithm

GAMELab/CSIE/NDHU

13. Scene Management

43


Finding the best splitter bsp

Finding the best splitter(BSP)

  • The BSP algorithm is not very complicated

  • The secret of the algorithm is to select one of the polygons at each node as splitter to divide the list of polygons into two smaller lists

  • Which polygon do you choose as a splitter?

  • Two attributes

    • How many polygons get cut by a certain splitter?

    • The balance of the tree

GAMELab/CSIE/NDHU

13. Scene Management

44


Finding the best splitter bsp1

Finding the best splitter(BSP)

Score

GAMELab/CSIE/NDHU

13. Scene Management

45


Finding the best splitter bsp2

Finding the best splitter(BSP)

GAMELab/CSIE/NDHU

13. Scene Management

46


Finding the best splitter bsp3

Finding the best splitter(BSP)

GAMELab/CSIE/NDHU

13. Scene Management

47


Bsp tree variants

BSP Tree Variants

  • Three variants

    • Node-Based BSP Trees

      • To do collision detection without doing any kind of calculation

    • Leafy BSP Tree

      • You do not retain the solid information

    • Solid BSP Tree

      • Combines both of the advantages of the approaches into a single BSP tree

GAMELab/CSIE/NDHU

13. Scene Management

48


Outline7

Outline

Overview

No Solution Is Also a Solution

Continuous and Discrete Level of Detail

Quadtrees

Octrees

Binary Space Partitioning Trees

Portal Engines

Potential Visibility Set

GAMELab/CSIE/NDHU

13. Scene Management

49


Portal engines

Portal Engines

There was another scene management approach working its way into the industry

Portal Engines

It is not a tree structure

GAMELab/CSIE/NDHU

13. Scene Management

50


Portal engines1

Portal Engines

GAMELab/CSIE/NDHU

13. Scene Management

51


Portal engines2

Portal Engines

GAMELab/CSIE/NDHU

13. Scene Management

52


Portal engines3

Portal Engines

GAMELab/CSIE/NDHU

13. Scene Management

53


Portal engines4

Portal Engines

  • Zero overdraw

    • Front to back

GAMELab/CSIE/NDHU

13. Scene Management

54


Portal engines5

Portal Engines

  • The criticism of the BSP algorithm

    • A lot of potential overdraw

      • Form back to front

  • The criticism of the portal engine

    • A lot of clipping operations

      • From front to back

  • There is no such thing as the optimal approach

  • Both approach are very useful in large, 3D projects

GAMELab/CSIE/NDHU

13. Scene Management

55


Portal engines6

Portal Engines

  • In this chapter, we implement only leafy BSP tree and an octree

  • Portal engine prepare in Chapter 14 and implemented in Chapter 15

GAMELab/CSIE/NDHU

13. Scene Management

56


Special effects with portals

Special Effects with Portals

  • There are a lot of special effects that can be natively built using a portal engine

  • Such as mirrors

    • Infinite loop

  • Labyrinth

    • Randomize which portal leads to which one

  • Lead to the same sector

    • Leaves the room through one door and enters the room through another door (Or maybe he enters through the same door through which he left)

GAMELab/CSIE/NDHU

13. Scene Management

57


Outline8

Outline

Overview

No Solution Is Also a Solution

Continuous and Discrete Level of Detail

Quadtrees

Octrees

Binary Space Partitioning Trees

Portal Engines

Potential Visibility Set

GAMELab/CSIE/NDHU

13. Scene Management

58


Potential visibility set

Potential Visibility Set

  • You should precompute everything you can to avoid slow calculations at run time

  • John Carmack

    • The reduction in the frame rate resulted from the slow traveling down the whole BSP tree

    • A lot of pixel overdraw was goning on for leaves that were rendered but finally occluded by others

    • The idea was to precalculate which leaves could potentially be seen from each other

GAMELab/CSIE/NDHU

13. Scene Management

59


Potential visibility set1

Potential Visibility Set

For example

GAMELab/CSIE/NDHU

13. Scene Management

60


Potential visibility set2

Potential Visibility Set

In a precalulation step, you build a list for each leaf

This list contains all other leaves that can potentially be seen from each position and orientation in the leaf

During runtime, you just need to find the leaf the viewer is in and then render the list of potentially visible leaves

(I do not recommend using a PVS for a BSP tree because there are too many issues)

GAMELab/CSIE/NDHU

13. Scene Management

61


Chapter 13 scene management

Q&A

GAMELab/CSIE/NDHU

13. Scene Management

62


Implementing a bsp tree

Implementing a BSP Tree

Speaker: 思元

13. Scene Management


Implementing a bsp tree1

  • Implement a BSP Tree

  • Simple demo that uses the BSP tree and the octree

  • Introduction ZFXPolylist

Implementing a BSP Tree

13. Scene Management


Zfxpolylist

ZFXPolylist

class ZFXPolylist{

public:

ZFXPolylist(void);

~ZFXPolylist(void);

bool AddPolygon(const ZFXPolygon&);

void Reset(void);

ZFXPolygon* GetPolylist(void);

unsigned int GetNum(void);

private:

ZFXPolygon *m_pPolys;

unsigned int m_Num;// 目前擁有的Polygon數

unsigned int m_Max;// 最大能放的Polygon數

bool CheckMem(void);// 檢查記憶體空間

};


Chapter 13 scene management

Q&A

13. Scene Management


Class declaration

Class Declaration

Speaker: Chen, Chang-Min

13. Scene Management


Class declaration1

  • The Contents

    • BSP tree class

    • Creating and Releasing Instances

    • Recursive Creation of the Tree

    • Selecting the Best Splitter

    • Collision Detection

Class Declaration

13. Scene Management


Bsp tree class

BSP tree class


Bsp tree class cont

BSP tree class (cont.)


Bsp tree class cont1

  • Self-explanatory

  • m_pPolys

    • The polygon is stored in the member attribute

    • Dynamically allocated to the number of polygons at the node

  • Two traverse functions

    • Back-to-front order

    • Front-to-back order

BSP tree class (cont.)


Creating and releasing instances

Creating and Releasing Instances


Recursive creation of the tree

Recursive Creation of the Tree


Recursive creation of the tree cont

  • void ZFXBspTree::CreateChilds(void)

    • CalcBoundingBox

      • Calculate the bounding box for a node

    • FindBestSplitter

      • Find the best splitter out of the list o polygons of this node

    • Create two new objects for the attributes m_pFront and m_pBack,two children of this node

    • If a polygon is located on the front side of the plane

      • it goes to the frontlist child

    • If a polygon is located on the back side of the plane

      • it goes to the backlist child

    • If the polygon lies in the plane, the angle between the its normal and the plane’s normal is zero

      • the polygon is sorted into the frontlist child

      • Otherwise the backlist child

    • the polygon intersects the plane

      • clip the polygon into two pieces on the front side and on the back side of the plane

      • sort them into the appropriate lists

Recursive Creation of the Tree (cont.)


Recursive creation of the tree cont1

  • void ZFXBspTree::CreateChilds(void)

Recursive Creation of the Tree (cont.)


Selecting the best splitter

  • bool ZFXBspTree::FindBestSplitter(void)

    • // CALCULATE SCORE

    • lScore = abs(lFront - lBack) + (lSplits * 3);

Selecting the Best Splitter


Traversing the tree

  • Back-to-front

    • Using transparency effects

    • void ZFXBspTree::TraverseFtB(ZFXPolylist *pList, ZFXVector vcPos,const ZFXPlane *Frustum)

  • Front-to-back

    • Faster rendering

    • void ZFXBspTree::TraverseBtF(ZFXPolylist *pList, ZFXVector vcPos, const ZFXPlane *Frustum)

Traversing the Tree


Collision detection

  • Collision Detection with BSP

    • Front-to-back order to Find the closest leaf that collides

    • void ZFXBsptree::TestCollision(const ZFXRay &Ray, float fL, float *pfD, ZFXVector *pvcN)

  • Whether a Monster can see a player

    • bool ZFXspTree::LineOfSight(const ZFXVector &vcA, const ZFXVector &vcB)

ZFXRay

{

ZFXVector m_vcOrig;

ZFXVector m_vcDir;

}

Collision Detection


Chapter 13 scene management

Q&A

13. Scene Management


Implementing an octree

Implementing an Octree

Speaker: Cong-Kai Lin

13. Scene Management


Outline9

  • Class Declaration

  • Creating and Releasing Instances

  • Initializing a Child Node

  • Recursive Creation of the Tree

  • Clip the Polygon List to a Node

  • Collision Detection in the Octree

  • Player’s Height in the Octree

  • Traversing the Tree

Outline

13. Scene Management


Implementing an octree1

  • Goal:

    • collision detection for scene management

  • Eight children name

Implementing an Octree

13. Scene Management


Implementing an octree cont

  • Stop Criteria:

    • Certain depth defined by user

    • Number of objects in a node defined by user

  • The deeper the octree gets, the longer the search times in the tree.

Implementing an Octree (Cont.)

13. Scene Management


Class declaration2

  • Two functions for CD

  • A Traversing function

  • A Render function for debugging purposes

Class Declaration

13. Scene Management


Class declaration con t

Class Declaration (Con.t)

13. Scene Management


Class declaration con t1

Class Declaration (Con.t)

13. Scene Management


Creating and releasing instances1

Creating and Releasing Instances

13. Scene Management


Creating and releasing instances cont

Creating and Releasing Instances (Cont.)

13. Scene Management


Initializing a child node

  • Creation of bounding box for a child.

  • Assign each attributes for a child.

    • Bounding box

    • ChildID

    • pParent

  • See InitChildObject(int ChildID, ZFXOctree *pParent)

Initializing a Child Node

13. Scene Management


Recursive creation of the tree1

Recursive Creation of the Tree

13. Scene Management


Recursive creation of the tree cont2

Initialize the eight child objects

Clip the polygon list to the child nodes

Recursively create the children of the child nodes

Recursive Creation of the Tree (Cont.)

13. Scene Management


Clip the polygon list to a node

  • Polygon totally outside of the bounding box

  • Polygon inside the bounding box

  • Polygon intersects the bounding box

    • Cut the polygon so that it fits exactly into the node’s bounding box.

  • See ChopListToMe(ZFXPolygon *pList, UINT Num)

Clip the Polygon List to a Node

13. Scene Management


Collision detection in the octree

  • Octree geometry and Bounding box

  • See TestCollision(const ZFXAabb &aabb, ZFXPlane *pP)

  • Octree geometry and a ray

  • See TestCollision(const ZFXRay &Ray, float fL, float *pfD)

Length of the intersection point to the ray origin

Length of the ray you want to check

Collision Detection in the Octree

13. Scene Management


Player s height in the octree

  • Finding the closest polygon below a given position in 3D space.

Player’s Height in the Octree

13. Scene Management


Player s height in the octree cont

  • Find the closest point under the given position

  • See GetFloor(const ZFXVector &vcPos, float *pf, ZFXPlane *pPlane)

Player’s Height in the Octree (Cont.)

13. Scene Management


Traversing the tree1

  • Render the bounding boxes and collect the polygons from octree.

  • Slow

  • Visualize the octree

  • Not needed in a real application

  • See Traverse(ZFXPolylist *pList, ZFXPolylist *pAabbList, const ZFXPlane *pFrustum)

  • See GetAabbAsPolygons(ZFXPolylist *pList)

Traversing the Tree

13. Scene Management


Chapter 13 scene management

Q&A

13. Scene Management


Demo application

Demo Application

Speaker:冠逸

13. Scene Management


Framework

End program

Framework

13. Scene Management


Level data format

Polygons Number (UINT)

Name Length (UINT)

Texture Name (string)

Polygons data

Name Length (UINT)

Texture Name (string)

Polygons data

Name Length (UINT)

Texture Name (string)

Polygons data

Level Data Format

13. Scene Management


Loading level

  • Initialize

Loading Level

13. Scene Management


Loading level1

  • Parse number of polygons

Loading Level

13. Scene Management


Loading level2

  • Load polygons

Loading Level

13. Scene Management


Framework1

End program

Framework

13. Scene Management


Loading level3

  • Build tree

Loading Level

13. Scene Management


Polygon data format

Polygons data

Vertices Numbers (UINT)

Indices Numbers (UINT)

Skin ID (UINT)

ZFXAabb

bool

Texture repeat / offset

Polygons Number (UINT)

Name Length (UINT)

Vertices (VERTEX)

Indices (WORD)

Interface List

Texture Name (string)

Polygons data

Name Length (UINT)

Texture Name (string)

Polygons data

Name Length (UINT)

Texture Name (string)

Polygons data

Polygon Data Format

13. Scene Management


Loading polygons

  • Initialize & read headers

Loading Polygons

13. Scene Management


Loading polygons1

  • Allocate memory

Loading Polygons

13. Scene Management


Loading polygons2

  • Read data

Loading Polygons

13. Scene Management


Loading polygons3

  • Convert and fill the data

Loading Polygons

13. Scene Management


Framework2

End program

Framework

13. Scene Management


Game loop

  • Initialize

Game Loop

13. Scene Management


Game loop1

  • Fetch input

Game Loop

13. Scene Management


Game loop2

  • CD test

Game Loop

13. Scene Management


Game loop3

  • Update position & viewing parameters

Game Loop

13. Scene Management


Game loop4

  • Traverse tree

Game Loop

13. Scene Management


Game loop5

  • Render scene

Game Loop

13. Scene Management


Rendering polygons

  • Initialize

Rendering Polygons

13. Scene Management


Rendering polygons1

  • Copy vertices positions & calculate texture coordinate

Rendering Polygons

13. Scene Management


Rendering polygons2

  • Render (solid)

Rendering Polygons

13. Scene Management


Rendering polygons3

  • Render (wireframe)

Rendering Polygons

13. Scene Management


Remarkable things

  • Cuts by octree & BSP tree

    • BSP tree cut better than octree

  • Performance

    • BSP tree has better performance than octree

Remarkable Things

13. Scene Management


Chapter 13 scene management

Q&A

13. Scene Management


  • Login