chapter 13 scene management
Download
Skip this Video
Download Presentation
CHAPTER 13 Scene Management

Loading in 2 Seconds...

play fullscreen
1 / 123

CHAPTER 13 Scene Management - PowerPoint PPT Presentation


  • 120 Views
  • Uploaded on

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

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' CHAPTER 13 Scene Management' - elton


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

slide7
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

slide62
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); // 檢查記憶體空間

};

slide66
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 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.)
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.)
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
slide79
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

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 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

slide97
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 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 polygons2

Read 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 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

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

slide123
Q&A

13. Scene Management

ad