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

CHAPTER 13 Scene Management PowerPoint PPT Presentation


  • 90 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 13Scene Management

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

13. Scene Management


  • 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

Speaker: Icarus

13. Scene Management


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


Q&A

13. Scene Management


Scene Management Techniques

Speaker: XJACK, Hsu

GAMELab/CSIE/NDHU

13. Scene Management

8


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


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

  • 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


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

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


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

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


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

  • 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


Quadtrees

GAMELab/CSIE/NDHU

13. Scene Management

19


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


Quadtrees

GAMELab/CSIE/NDHU

13. Scene Management

21


Quadtrees

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

GAMELab/CSIE/NDHU

13. Scene Management

22


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


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


Quadtrees

The theory of applying quadtrees to terrain rendering

GAMELab/CSIE/NDHU

13. Scene Management

25


Quadtrees

GAMELab/CSIE/NDHU

13. Scene Management

26


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


Quadtrees

GAMELab/CSIE/NDHU

13. Scene Management

28


Quadtrees

GAMELab/CSIE/NDHU

13. Scene Management

29


Quadtrees

GAMELab/CSIE/NDHU

13. Scene Management

30


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

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

Octrees

GAMELab/CSIE/NDHU

13. Scene Management

32


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


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

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

  • Convex polygon Concave polygon

GAMELab/CSIE/NDHU

13. Scene Management

36


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 Trees

GAMELab/CSIE/NDHU

13. Scene Management

38


Binary Space Partitioning Trees

GAMELab/CSIE/NDHU

13. Scene Management

39


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 games

DOOM 1 in December 1993

GAMELab/CSIE/NDHU

13. Scene Management

41


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

  • 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(BSP)

Score

GAMELab/CSIE/NDHU

13. Scene Management

45


Finding the best splitter(BSP)

GAMELab/CSIE/NDHU

13. Scene Management

46


Finding the best splitter(BSP)

GAMELab/CSIE/NDHU

13. Scene Management

47


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


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

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 Engines

GAMELab/CSIE/NDHU

13. Scene Management

51


Portal Engines

GAMELab/CSIE/NDHU

13. Scene Management

52


Portal Engines

GAMELab/CSIE/NDHU

13. Scene Management

53


Portal Engines

  • Zero overdraw

    • Front to back

GAMELab/CSIE/NDHU

13. Scene Management

54


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

  • 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


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

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

For example

GAMELab/CSIE/NDHU

13. Scene Management

60


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


Q&A

GAMELab/CSIE/NDHU

13. Scene Management

62


Implementing a BSP Tree

Speaker: 思元

13. Scene Management


  • Implement a BSP Tree

  • Simple demo that uses the BSP tree and the octree

  • Introduction ZFXPolylist

Implementing a BSP Tree

13. Scene Management


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

};


Q&A

13. Scene Management


Class Declaration

Speaker: Chen, Chang-Min

13. Scene Management


  • 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 (cont.)


  • 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


Recursive Creation of the Tree


  • 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.)


  • void ZFXBspTree::CreateChilds(void)

Recursive Creation of the Tree (cont.)


  • bool ZFXBspTree::FindBestSplitter(void)

    • // CALCULATE SCORE

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

Selecting the Best Splitter


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


Q&A

13. Scene Management


Implementing an Octree

Speaker: Cong-Kai Lin

13. Scene Management


  • 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


  • Goal:

    • collision detection for scene management

  • Eight children name

Implementing an Octree

13. Scene Management


  • 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


  • Two functions for CD

  • A Traversing function

  • A Render function for debugging purposes

Class Declaration

13. Scene Management


Class Declaration (Con.t)

13. Scene Management


Class Declaration (Con.t)

13. Scene Management


Creating and Releasing Instances

13. Scene Management


Creating and Releasing Instances (Cont.)

13. Scene Management


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

13. Scene Management


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


  • 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


  • 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


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

Player’s Height in the Octree

13. Scene Management


  • 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


  • 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


Q&A

13. Scene Management


Demo Application

Speaker:冠逸

13. Scene Management


End program

Framework

13. Scene Management


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


  • Initialize

Loading Level

13. Scene Management


  • Parse number of polygons

Loading Level

13. Scene Management


  • Load polygons

Loading Level

13. Scene Management


End program

Framework

13. Scene Management


  • Build tree

Loading Level

13. Scene Management


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


  • Initialize & read headers

Loading Polygons

13. Scene Management


  • Allocate memory

Loading Polygons

13. Scene Management


  • Read data

Loading Polygons

13. Scene Management


  • Convert and fill the data

Loading Polygons

13. Scene Management


End program

Framework

13. Scene Management


  • Initialize

Game Loop

13. Scene Management


  • Fetch input

Game Loop

13. Scene Management


  • CD test

Game Loop

13. Scene Management


  • Update position & viewing parameters

Game Loop

13. Scene Management


  • Traverse tree

Game Loop

13. Scene Management


  • Render scene

Game Loop

13. Scene Management


  • Initialize

Rendering Polygons

13. Scene Management


  • Copy vertices positions & calculate texture coordinate

Rendering Polygons

13. Scene Management


  • Render (solid)

Rendering Polygons

13. Scene Management


  • Render (wireframe)

Rendering Polygons

13. Scene Management


  • Cuts by octree & BSP tree

    • BSP tree cut better than octree

  • Performance

    • BSP tree has better performance than octree

Remarkable Things

13. Scene Management


Q&A

13. Scene Management


  • Login