SlideShare a Scribd company logo
1 of 25
Download to read offline
BSP Trees in 3D
Game Engines (1)
Shot from Unreal Tournament 2003
Shot From Doom3
Modified from an original presentation
prepared by Jason Calvert, 2003.
Principles of:
Constructive Solid Geometry
and Leaf Based BSP Trees
Geometry
Node Based BSP Trees represented all
geometry as polygons.
Games must represent all geometry as solids
(Solid Geometry)
Fully Enclosed Hulls - Box, Sphere, Teapot, etc…
Solid node trees give us a way to represent solid
and empty areas of a game level.
Nodes still represent partitioning planes but
each leaf represents solid or empty space.
Useful in collision detection and Line of sight
determination.
Game Level Creation
Levels are constructed using Constructive
Solid Geometry (CSG) methods.
A level starts out as a solid cube and various
tools are used to hollow out the cube leaving
empty space inside solid space (walls).
Space will be represented by adding a leaf
node to the end of each branch instead null.
Each leaf node will represent either solid or
empty space.
Solid Tree Node Structure
class BSPNode
{
BSPNode Front;
BSPNode Back;
Polygon Poly;
boolean isLeaf; // are we in a leaf?
boolean isSolid; // is this leaf solid or empty?
}
Each node can be marked as a leaf and if it is a leaf
it can represent either empty or solid space.
Example
A
BE
D
C
D2D1
F
A
Back
AAA
A Front
BCD2 D1EF
First Split
To build the BSP tree
Assume a splitter choosing
heuristic that chooses the “best”
splitter.
A is chosen in this case so D
must be split into D1 and D2.
FrontBack
Example
A
BE
D
C
D2D1
F
A
F
sol
Back
AAA
F Front
D1 E
F Split
solid
To build the BSP tree
Using the Front list – F is the
next splitter (at random or using
the heuristic)
Example
A
BE
D
C
D2D1
F
A
F
D1sol
sol
Back
AAA
D1 Front
E
D1 Split
solid
To build the BSP tree
Using the Front list – D1 is the
next splitter
Example
A
BE
D
C
D2D1
F
A
F
D1
E
sol emp
sol
sol
Back
AAA
E Front
empty
E Split
solid
To build the BSP tree
Using the Front list – E is the
only remaining polygon – it has
solid space behind it and empty
space in front
Example
A
BE
D
C
D2D1
F
A
F
D1
E
sol emp
C
sol
sol
sol
To build the BSP tree
Using the Back list (from the first
split) – C is next splitter
Back
AAA
C Front
BD2
C Split
solid
Example
A
BE
D
C
D2D1
F
A
F
D1
E
sol emp
C
sol
sol
sol B
sol
To build the BSP tree
Using the Front list (from the C
split) – B is next splitter
Back
AAA
B Front
D2
B Split
solid
Example
A
BE
D
C
D2D1
F
A
F
D1
E
sol emp
C
sol
sol
sol B
sol D2
sol emp
To build the BSP tree
Using the Front list (from the B
split) – D2 is last splitter
Note that this is still a node
based tree.
Back
AAA
D2 Front
empty
D2 Split
solid
Leaf Based BSP Trees
While our node based BSP tree has provided us
a way to render our scene in back to front order
we still have to render every polygon.
Goal is to throw away any unseen geometry.
We will next build a leaf based BSP tree so that
we can build a Potential Visibility Set (PVS).
This will allow us to throw away nearly all unseen
geometry with practically zero overhead.
Leaf Based BSP Trees
Built almost exactly like node based trees.
Leafy BSP trees store their geometry in the leafs
instead of nodes.
There will be many polygons in a single leaf.
These polygons will all be facing each other.
We will now store the plane of the splitting
polygon in the node, and send the polygon down
it’s own front list.
This polygon may continue to be split, but it cannot be
used as a splitter again.
We will continue to use solid geometry.
Leafy BSP compile process
The recursive BuildBSPTree process starts with
a list of polygons and will build a subtree using
that input. It progresses as follows:
Select a splitter polygon – store the plane
equation in the node.
Mark splitter polygon as having been used as a
splitter so it can’t be used again.
Classify each remaining polygon against the
current splitter polygon.
If the current polygon being tested is the splitter
send it down it’s own front list.
Polygon Classification
Polygon Classification (con't):
If the current polygon is in front of the splitter add it to
the front list.
If the current polygon is behind the splitter add it to the
back list.
If the current polygon is on the same plane as the
splitter check the polygons normal against the splitters
normal.
If they are facing the same direction send the polygon
down the front list.
If they are facing opposite directions send the polygon
down the back list.
Polygon Classification (2)
Polygon Classification (con't):
If the polygon is spanning the plane split it and add the
front part to the front list and the back part to the back
list.
Split polygons must inherit the information that their
parent was already used as a splitter.
Alternative to splitting:
Since splitting can double polygon count, do NOT
split the polygon but send it down both front and back
lists.
When rendering keep track of each polygon rendered
to avoid rendering twice.
Leaf Building
Once all polygons have been classified (added to
the front or back list):
Check Front List to determine if all polygons in the
front list have been used as splitters.
If so we have a batch of polygons which all lie in
front of each other. We are in a room.
Build a leaf structure and add all polygons in the
front list to the leaf.
Build a bounding box around leaf.
Otherwise we need to process the list further by
passing it to another call to BuildBSPTree.
Leaf Building (2)
Once all polygons have been classified(cont):
Check Back List to see if it is empty.
If so we are in solid space (all polygons
surrounding solid space face away from the space)
We cannot have any back leaves that contain
polygons since polygons cannot exist in solid
space.
So, we store a marker that signifies that we’ve
ended in solid space.
Otherwise continue processing by calling
BuildBSPTree passing in the back list.
Leaf Rendering
All of the polygons stored in a leaf can be
rendered in any order.
This is due to the fact that the polygons
are all in front of each other.
They will not be crossing or behind each
other.
Example of BSP building
A
BE
D
C
D2D1
F
Assume A is used as first splitter
Root node contains the plane of
A
Back
AAA
PA Front
BCD2 D1EFA
First Split
PA
Final BSP Tree
A
BE
D
C
D2D1
F PA
PB PD1
PC
PF
PE
PD2
solid
solid
solid
solid
solid
solid
BCD2
AD1EF
Example of BSP building
A
BE
D
CE2
E1
F
Assume B is used as first splitter
Root node contains the plane of
B
Back
AAA
PB Front
AFE1 BCE2D
First Split
PB
Final BSP Tree
PB
PA PC
PF
PE2
PD
PE1
solid
solid
solid
solid
solid
solid
AFE1
BCE2D
A
BE
D
CE2
E1
F
Leaf Properties & Visibility
These batches of polygons “hulls” give us
exactly what we need to build a system to
throw away nearly all unseen geometry.
We need a way (Potential Visibility Set) to
know which leafs can be seen by the leaf
the camera is in.
Knowing this will allow us to throw away
many leafs without any costly tests.
These leafs will not be processed in any way.
Compile Process
Everything is nearly the same as the node
based compile process.
Compiling has changed in two ways.
We now send splitters down their own front
list.
This polygon may continue to be split.
All polygons accumulate in non-solid leaves.

More Related Content

What's hot

vkFX: Effect(ive) approach for Vulkan API
vkFX: Effect(ive) approach for Vulkan APIvkFX: Effect(ive) approach for Vulkan API
vkFX: Effect(ive) approach for Vulkan APITristan Lorach
 
Optimizing the Graphics Pipeline with Compute, GDC 2016
Optimizing the Graphics Pipeline with Compute, GDC 2016Optimizing the Graphics Pipeline with Compute, GDC 2016
Optimizing the Graphics Pipeline with Compute, GDC 2016Graham Wihlidal
 
HPG 2018 - Game Ray Tracing: State-of-the-Art and Open Problems
HPG 2018 - Game Ray Tracing: State-of-the-Art and Open ProblemsHPG 2018 - Game Ray Tracing: State-of-the-Art and Open Problems
HPG 2018 - Game Ray Tracing: State-of-the-Art and Open ProblemsElectronic Arts / DICE
 
Parallel Futures of a Game Engine (v2.0)
Parallel Futures of a Game Engine (v2.0)Parallel Futures of a Game Engine (v2.0)
Parallel Futures of a Game Engine (v2.0)Johan Andersson
 
Graph representation
Graph representationGraph representation
Graph representationTech_MX
 
Parallel Futures of a Game Engine
Parallel Futures of a Game EngineParallel Futures of a Game Engine
Parallel Futures of a Game EngineJohan Andersson
 
The Rendering Technology of Killzone 2
The Rendering Technology of Killzone 2The Rendering Technology of Killzone 2
The Rendering Technology of Killzone 2Guerrilla
 
OpenGL 4.4 - Scene Rendering Techniques
OpenGL 4.4 - Scene Rendering TechniquesOpenGL 4.4 - Scene Rendering Techniques
OpenGL 4.4 - Scene Rendering TechniquesNarann29
 
Computer Graphics and Multimedia lab report
Computer Graphics and Multimedia lab reportComputer Graphics and Multimedia lab report
Computer Graphics and Multimedia lab reportBijoy679
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked listSumathi Kv
 
Graphics programming in open gl
Graphics programming in open glGraphics programming in open gl
Graphics programming in open glArvind Devaraj
 
Bfs and dfs in data structure
Bfs and dfs in  data structure Bfs and dfs in  data structure
Bfs and dfs in data structure Ankit Kumar Singh
 
Siggraph 2011: Occlusion culling in Alan Wake
Siggraph 2011: Occlusion culling in Alan WakeSiggraph 2011: Occlusion culling in Alan Wake
Siggraph 2011: Occlusion culling in Alan WakeUmbra
 

What's hot (20)

vkFX: Effect(ive) approach for Vulkan API
vkFX: Effect(ive) approach for Vulkan APIvkFX: Effect(ive) approach for Vulkan API
vkFX: Effect(ive) approach for Vulkan API
 
Optimizing the Graphics Pipeline with Compute, GDC 2016
Optimizing the Graphics Pipeline with Compute, GDC 2016Optimizing the Graphics Pipeline with Compute, GDC 2016
Optimizing the Graphics Pipeline with Compute, GDC 2016
 
DFS and BFS
DFS and BFSDFS and BFS
DFS and BFS
 
HPG 2018 - Game Ray Tracing: State-of-the-Art and Open Problems
HPG 2018 - Game Ray Tracing: State-of-the-Art and Open ProblemsHPG 2018 - Game Ray Tracing: State-of-the-Art and Open Problems
HPG 2018 - Game Ray Tracing: State-of-the-Art and Open Problems
 
Scope Stack Allocation
Scope Stack AllocationScope Stack Allocation
Scope Stack Allocation
 
visible surface detection
visible surface detectionvisible surface detection
visible surface detection
 
Parallel Futures of a Game Engine (v2.0)
Parallel Futures of a Game Engine (v2.0)Parallel Futures of a Game Engine (v2.0)
Parallel Futures of a Game Engine (v2.0)
 
Graph representation
Graph representationGraph representation
Graph representation
 
Parallel Futures of a Game Engine
Parallel Futures of a Game EngineParallel Futures of a Game Engine
Parallel Futures of a Game Engine
 
Graphs bfs dfs
Graphs bfs dfsGraphs bfs dfs
Graphs bfs dfs
 
The Rendering Technology of Killzone 2
The Rendering Technology of Killzone 2The Rendering Technology of Killzone 2
The Rendering Technology of Killzone 2
 
OpenGL 4.4 - Scene Rendering Techniques
OpenGL 4.4 - Scene Rendering TechniquesOpenGL 4.4 - Scene Rendering Techniques
OpenGL 4.4 - Scene Rendering Techniques
 
Computer Graphics and Multimedia lab report
Computer Graphics and Multimedia lab reportComputer Graphics and Multimedia lab report
Computer Graphics and Multimedia lab report
 
B tree
B treeB tree
B tree
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
 
Bending the Graphics Pipeline
Bending the Graphics PipelineBending the Graphics Pipeline
Bending the Graphics Pipeline
 
Graphics programming in open gl
Graphics programming in open glGraphics programming in open gl
Graphics programming in open gl
 
Polygon mesh
Polygon meshPolygon mesh
Polygon mesh
 
Bfs and dfs in data structure
Bfs and dfs in  data structure Bfs and dfs in  data structure
Bfs and dfs in data structure
 
Siggraph 2011: Occlusion culling in Alan Wake
Siggraph 2011: Occlusion culling in Alan WakeSiggraph 2011: Occlusion culling in Alan Wake
Siggraph 2011: Occlusion culling in Alan Wake
 

Viewers also liked (13)

Threading Game Engines: QUAKE 4 & Enemy Territory QUAKE Wars
Threading Game Engines: QUAKE 4 & Enemy Territory QUAKE WarsThreading Game Engines: QUAKE 4 & Enemy Territory QUAKE Wars
Threading Game Engines: QUAKE 4 & Enemy Territory QUAKE Wars
 
Doom3
Doom3Doom3
Doom3
 
Shadow Techniques for Real-Time and Interactive Applications
Shadow Techniques for Real-Time and Interactive ApplicationsShadow Techniques for Real-Time and Interactive Applications
Shadow Techniques for Real-Time and Interactive Applications
 
Beyond GPS - Neogeograpy Data Collection
Beyond GPS - Neogeograpy Data CollectionBeyond GPS - Neogeograpy Data Collection
Beyond GPS - Neogeograpy Data Collection
 
Implementing Server Side Data Synchronization for Mobile Apps
Implementing Server Side Data Synchronization for Mobile AppsImplementing Server Side Data Synchronization for Mobile Apps
Implementing Server Side Data Synchronization for Mobile Apps
 
Hageman id software project
Hageman id software projectHageman id software project
Hageman id software project
 
968
968968
968
 
SVN session from PiTechnologies
SVN session from PiTechnologies SVN session from PiTechnologies
SVN session from PiTechnologies
 
Dutch Cuisine | Dag van de Duurzaamheid 2016 | Centrum Duurzaam
Dutch Cuisine | Dag van de Duurzaamheid 2016 | Centrum DuurzaamDutch Cuisine | Dag van de Duurzaamheid 2016 | Centrum Duurzaam
Dutch Cuisine | Dag van de Duurzaamheid 2016 | Centrum Duurzaam
 
2200m ah external battery charger pack case for samsung galaxy s2 i9100
2200m ah external battery charger pack case for samsung galaxy s2 i91002200m ah external battery charger pack case for samsung galaxy s2 i9100
2200m ah external battery charger pack case for samsung galaxy s2 i9100
 
Badger Advanced Freight & Fleet Tracking Systems
Badger Advanced Freight & Fleet Tracking SystemsBadger Advanced Freight & Fleet Tracking Systems
Badger Advanced Freight & Fleet Tracking Systems
 
Daily newsletter-e no500 6-6-2014
Daily newsletter-e no500 6-6-2014Daily newsletter-e no500 6-6-2014
Daily newsletter-e no500 6-6-2014
 
Pitkä työura ja terve vanheneminen
 Pitkä työura ja terve vanheneminen Pitkä työura ja terve vanheneminen
Pitkä työura ja terve vanheneminen
 

Similar to BSPTreesGameEngines-1

Trees in Data Structure
Trees in Data StructureTrees in Data Structure
Trees in Data StructureOm Prakash
 
for sbi so Ds c c++ unix rdbms sql cn os
for sbi so   Ds c c++ unix rdbms sql cn osfor sbi so   Ds c c++ unix rdbms sql cn os
for sbi so Ds c c++ unix rdbms sql cn osalisha230390
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURESbca2010
 
bca data structure
bca data structurebca data structure
bca data structureshini
 
Chap 7 binary threaded tree
Chap 7 binary threaded treeChap 7 binary threaded tree
Chap 7 binary threaded treeRaj Sarode
 

Similar to BSPTreesGameEngines-1 (9)

Chap 8 graph
Chap 8 graphChap 8 graph
Chap 8 graph
 
Trees in Data Structure
Trees in Data StructureTrees in Data Structure
Trees in Data Structure
 
for sbi so Ds c c++ unix rdbms sql cn os
for sbi so   Ds c c++ unix rdbms sql cn osfor sbi so   Ds c c++ unix rdbms sql cn os
for sbi so Ds c c++ unix rdbms sql cn os
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
 
bca data structure
bca data structurebca data structure
bca data structure
 
Chap 7 binary threaded tree
Chap 7 binary threaded treeChap 7 binary threaded tree
Chap 7 binary threaded tree
 
Data structure
Data structureData structure
Data structure
 
Trees unit 3
Trees unit 3Trees unit 3
Trees unit 3
 
Graphs
GraphsGraphs
Graphs
 

BSPTreesGameEngines-1

  • 1. BSP Trees in 3D Game Engines (1) Shot from Unreal Tournament 2003 Shot From Doom3 Modified from an original presentation prepared by Jason Calvert, 2003. Principles of: Constructive Solid Geometry and Leaf Based BSP Trees
  • 2. Geometry Node Based BSP Trees represented all geometry as polygons. Games must represent all geometry as solids (Solid Geometry) Fully Enclosed Hulls - Box, Sphere, Teapot, etc… Solid node trees give us a way to represent solid and empty areas of a game level. Nodes still represent partitioning planes but each leaf represents solid or empty space. Useful in collision detection and Line of sight determination.
  • 3. Game Level Creation Levels are constructed using Constructive Solid Geometry (CSG) methods. A level starts out as a solid cube and various tools are used to hollow out the cube leaving empty space inside solid space (walls). Space will be represented by adding a leaf node to the end of each branch instead null. Each leaf node will represent either solid or empty space.
  • 4. Solid Tree Node Structure class BSPNode { BSPNode Front; BSPNode Back; Polygon Poly; boolean isLeaf; // are we in a leaf? boolean isSolid; // is this leaf solid or empty? } Each node can be marked as a leaf and if it is a leaf it can represent either empty or solid space.
  • 5. Example A BE D C D2D1 F A Back AAA A Front BCD2 D1EF First Split To build the BSP tree Assume a splitter choosing heuristic that chooses the “best” splitter. A is chosen in this case so D must be split into D1 and D2. FrontBack
  • 6. Example A BE D C D2D1 F A F sol Back AAA F Front D1 E F Split solid To build the BSP tree Using the Front list – F is the next splitter (at random or using the heuristic)
  • 7. Example A BE D C D2D1 F A F D1sol sol Back AAA D1 Front E D1 Split solid To build the BSP tree Using the Front list – D1 is the next splitter
  • 8. Example A BE D C D2D1 F A F D1 E sol emp sol sol Back AAA E Front empty E Split solid To build the BSP tree Using the Front list – E is the only remaining polygon – it has solid space behind it and empty space in front
  • 9. Example A BE D C D2D1 F A F D1 E sol emp C sol sol sol To build the BSP tree Using the Back list (from the first split) – C is next splitter Back AAA C Front BD2 C Split solid
  • 10. Example A BE D C D2D1 F A F D1 E sol emp C sol sol sol B sol To build the BSP tree Using the Front list (from the C split) – B is next splitter Back AAA B Front D2 B Split solid
  • 11. Example A BE D C D2D1 F A F D1 E sol emp C sol sol sol B sol D2 sol emp To build the BSP tree Using the Front list (from the B split) – D2 is last splitter Note that this is still a node based tree. Back AAA D2 Front empty D2 Split solid
  • 12. Leaf Based BSP Trees While our node based BSP tree has provided us a way to render our scene in back to front order we still have to render every polygon. Goal is to throw away any unseen geometry. We will next build a leaf based BSP tree so that we can build a Potential Visibility Set (PVS). This will allow us to throw away nearly all unseen geometry with practically zero overhead.
  • 13. Leaf Based BSP Trees Built almost exactly like node based trees. Leafy BSP trees store their geometry in the leafs instead of nodes. There will be many polygons in a single leaf. These polygons will all be facing each other. We will now store the plane of the splitting polygon in the node, and send the polygon down it’s own front list. This polygon may continue to be split, but it cannot be used as a splitter again. We will continue to use solid geometry.
  • 14. Leafy BSP compile process The recursive BuildBSPTree process starts with a list of polygons and will build a subtree using that input. It progresses as follows: Select a splitter polygon – store the plane equation in the node. Mark splitter polygon as having been used as a splitter so it can’t be used again. Classify each remaining polygon against the current splitter polygon. If the current polygon being tested is the splitter send it down it’s own front list.
  • 15. Polygon Classification Polygon Classification (con't): If the current polygon is in front of the splitter add it to the front list. If the current polygon is behind the splitter add it to the back list. If the current polygon is on the same plane as the splitter check the polygons normal against the splitters normal. If they are facing the same direction send the polygon down the front list. If they are facing opposite directions send the polygon down the back list.
  • 16. Polygon Classification (2) Polygon Classification (con't): If the polygon is spanning the plane split it and add the front part to the front list and the back part to the back list. Split polygons must inherit the information that their parent was already used as a splitter. Alternative to splitting: Since splitting can double polygon count, do NOT split the polygon but send it down both front and back lists. When rendering keep track of each polygon rendered to avoid rendering twice.
  • 17. Leaf Building Once all polygons have been classified (added to the front or back list): Check Front List to determine if all polygons in the front list have been used as splitters. If so we have a batch of polygons which all lie in front of each other. We are in a room. Build a leaf structure and add all polygons in the front list to the leaf. Build a bounding box around leaf. Otherwise we need to process the list further by passing it to another call to BuildBSPTree.
  • 18. Leaf Building (2) Once all polygons have been classified(cont): Check Back List to see if it is empty. If so we are in solid space (all polygons surrounding solid space face away from the space) We cannot have any back leaves that contain polygons since polygons cannot exist in solid space. So, we store a marker that signifies that we’ve ended in solid space. Otherwise continue processing by calling BuildBSPTree passing in the back list.
  • 19. Leaf Rendering All of the polygons stored in a leaf can be rendered in any order. This is due to the fact that the polygons are all in front of each other. They will not be crossing or behind each other.
  • 20. Example of BSP building A BE D C D2D1 F Assume A is used as first splitter Root node contains the plane of A Back AAA PA Front BCD2 D1EFA First Split PA
  • 21. Final BSP Tree A BE D C D2D1 F PA PB PD1 PC PF PE PD2 solid solid solid solid solid solid BCD2 AD1EF
  • 22. Example of BSP building A BE D CE2 E1 F Assume B is used as first splitter Root node contains the plane of B Back AAA PB Front AFE1 BCE2D First Split PB
  • 23. Final BSP Tree PB PA PC PF PE2 PD PE1 solid solid solid solid solid solid AFE1 BCE2D A BE D CE2 E1 F
  • 24. Leaf Properties & Visibility These batches of polygons “hulls” give us exactly what we need to build a system to throw away nearly all unseen geometry. We need a way (Potential Visibility Set) to know which leafs can be seen by the leaf the camera is in. Knowing this will allow us to throw away many leafs without any costly tests. These leafs will not be processed in any way.
  • 25. Compile Process Everything is nearly the same as the node based compile process. Compiling has changed in two ways. We now send splitters down their own front list. This polygon may continue to be split. All polygons accumulate in non-solid leaves.