SlideShare ist ein Scribd-Unternehmen logo
1 von 25
Downloaden Sie, um offline zu lesen
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.

Weitere ähnliche Inhalte

Was ist angesagt?

Tema 8 S.Diedrico Part 1
Tema 8 S.Diedrico Part 1Tema 8 S.Diedrico Part 1
Tema 8 S.Diedrico Part 1qvrrafa
 
2. desarrollo de una piramide recta
2. desarrollo de una piramide recta2. desarrollo de una piramide recta
2. desarrollo de una piramide rectaBoris Cabrera
 
3 . encontrar la longitud verdadera de una línea
3 . encontrar la longitud verdadera de una línea3 . encontrar la longitud verdadera de una línea
3 . encontrar la longitud verdadera de una líneaBoris Cabrera
 
4. proyecciones multiples del punto
4. proyecciones multiples del punto4. proyecciones multiples del punto
4. proyecciones multiples del puntoBoris Cabrera
 
Proyecciones multiples del plano
Proyecciones multiples del planoProyecciones multiples del plano
Proyecciones multiples del planoBoris Cabrera
 
Generalidades del plano
Generalidades del planoGeneralidades del plano
Generalidades del planoBoris Cabrera
 
120. adaptador rectángulo a círculo
120. adaptador   rectángulo a círculo120. adaptador   rectángulo a círculo
120. adaptador rectángulo a círculoBoris Cabrera
 
Proyec de la línea dado su orientación
Proyec de la línea dado su orientaciónProyec de la línea dado su orientación
Proyec de la línea dado su orientaciónBoris Cabrera
 

Was ist angesagt? (12)

Tema 8 S.Diedrico Part 1
Tema 8 S.Diedrico Part 1Tema 8 S.Diedrico Part 1
Tema 8 S.Diedrico Part 1
 
Grade 7 perspective
Grade 7  perspectiveGrade 7  perspective
Grade 7 perspective
 
2. desarrollo de una piramide recta
2. desarrollo de una piramide recta2. desarrollo de una piramide recta
2. desarrollo de una piramide recta
 
3 . encontrar la longitud verdadera de una línea
3 . encontrar la longitud verdadera de una línea3 . encontrar la longitud verdadera de una línea
3 . encontrar la longitud verdadera de una línea
 
4. proyecciones multiples del punto
4. proyecciones multiples del punto4. proyecciones multiples del punto
4. proyecciones multiples del punto
 
Marquilla
MarquillaMarquilla
Marquilla
 
2. líneas frontal
2. líneas frontal2. líneas frontal
2. líneas frontal
 
Proyecciones multiples del plano
Proyecciones multiples del planoProyecciones multiples del plano
Proyecciones multiples del plano
 
Generalidades del plano
Generalidades del planoGeneralidades del plano
Generalidades del plano
 
120. adaptador rectángulo a círculo
120. adaptador   rectángulo a círculo120. adaptador   rectángulo a círculo
120. adaptador rectángulo a círculo
 
Proyec de la línea dado su orientación
Proyec de la línea dado su orientaciónProyec de la línea dado su orientación
Proyec de la línea dado su orientación
 
5. línea inclinada
5. línea inclinada5. línea inclinada
5. línea inclinada
 

Andere mochten auch

Pitch For Media
Pitch For Media Pitch For Media
Pitch For Media HR162033
 
Artículo 3 garantías de los estudiantes
Artículo 3 garantías de los estudiantesArtículo 3 garantías de los estudiantes
Artículo 3 garantías de los estudiantesadriana margarita
 
Dia mundial del medio ambiente
Dia mundial del medio ambienteDia mundial del medio ambiente
Dia mundial del medio ambienteyesebeth
 
קו למושב 787 , 13/06/2013
קו למושב 787 , 13/06/2013קו למושב 787 , 13/06/2013
קו למושב 787 , 13/06/2013eshaki
 
Integración educativa
Integración educativaIntegración educativa
Integración educativafran melendez
 
Riscos da obesidade
Riscos da obesidade Riscos da obesidade
Riscos da obesidade Pedro Otavio
 
Successes and challenges in organizing R4D platforms and taking a more integr...
Successes and challenges in organizing R4D platforms and taking a more integr...Successes and challenges in organizing R4D platforms and taking a more integr...
Successes and challenges in organizing R4D platforms and taking a more integr...CIALCA
 
01 ambiente-preservação-e-biodiversidade-versão-2016
01 ambiente-preservação-e-biodiversidade-versão-201601 ambiente-preservação-e-biodiversidade-versão-2016
01 ambiente-preservação-e-biodiversidade-versão-2016José Montanha
 
The role of complementary and alternative medicine (CAM) in Germany – A focus...
The role of complementary and alternative medicine (CAM) in Germany – A focus...The role of complementary and alternative medicine (CAM) in Germany – A focus...
The role of complementary and alternative medicine (CAM) in Germany – A focus...home
 
Mufti muhammad taqi usmani 14 02-12
Mufti muhammad taqi usmani 14 02-12Mufti muhammad taqi usmani 14 02-12
Mufti muhammad taqi usmani 14 02-12SYED AMMAR BUKHARI
 
Edraak-Certificate
Edraak-CertificateEdraak-Certificate
Edraak-CertificateAya Ahmed
 
Artículo 2 acciones pedagógicas
Artículo 2 acciones pedagógicasArtículo 2 acciones pedagógicas
Artículo 2 acciones pedagógicasadriana margarita
 
Las CoPs para la mejora de la Administración Pública
Las CoPs  para la mejora de la Administración Pública Las CoPs  para la mejora de la Administración Pública
Las CoPs para la mejora de la Administración Pública Departament de Justicia
 

Andere mochten auch (20)

Pitch For Media
Pitch For Media Pitch For Media
Pitch For Media
 
Artículo 3 garantías de los estudiantes
Artículo 3 garantías de los estudiantesArtículo 3 garantías de los estudiantes
Artículo 3 garantías de los estudiantes
 
BIO DATA. AHMED
BIO DATA. AHMEDBIO DATA. AHMED
BIO DATA. AHMED
 
Dia mundial del medio ambiente
Dia mundial del medio ambienteDia mundial del medio ambiente
Dia mundial del medio ambiente
 
קו למושב 787 , 13/06/2013
קו למושב 787 , 13/06/2013קו למושב 787 , 13/06/2013
קו למושב 787 , 13/06/2013
 
Integración educativa
Integración educativaIntegración educativa
Integración educativa
 
Riscos da obesidade
Riscos da obesidade Riscos da obesidade
Riscos da obesidade
 
Successes and challenges in organizing R4D platforms and taking a more integr...
Successes and challenges in organizing R4D platforms and taking a more integr...Successes and challenges in organizing R4D platforms and taking a more integr...
Successes and challenges in organizing R4D platforms and taking a more integr...
 
01 ambiente-preservação-e-biodiversidade-versão-2016
01 ambiente-preservação-e-biodiversidade-versão-201601 ambiente-preservação-e-biodiversidade-versão-2016
01 ambiente-preservação-e-biodiversidade-versão-2016
 
The role of complementary and alternative medicine (CAM) in Germany – A focus...
The role of complementary and alternative medicine (CAM) in Germany – A focus...The role of complementary and alternative medicine (CAM) in Germany – A focus...
The role of complementary and alternative medicine (CAM) in Germany – A focus...
 
Mufti muhammad taqi usmani 14 02-12
Mufti muhammad taqi usmani 14 02-12Mufti muhammad taqi usmani 14 02-12
Mufti muhammad taqi usmani 14 02-12
 
Arte terapia
Arte terapiaArte terapia
Arte terapia
 
Edraak-Certificate
Edraak-CertificateEdraak-Certificate
Edraak-Certificate
 
Artículo 4 debido proceso
Artículo 4 debido procesoArtículo 4 debido proceso
Artículo 4 debido proceso
 
O primeiro automóvel
O primeiro automóvelO primeiro automóvel
O primeiro automóvel
 
Artículo 2 acciones pedagógicas
Artículo 2 acciones pedagógicasArtículo 2 acciones pedagógicas
Artículo 2 acciones pedagógicas
 
Lac operon
Lac operonLac operon
Lac operon
 
Motiffs
MotiffsMotiffs
Motiffs
 
Polysaccharides
PolysaccharidesPolysaccharides
Polysaccharides
 
Las CoPs para la mejora de la Administración Pública
Las CoPs  para la mejora de la Administración Pública Las CoPs  para la mejora de la Administración Pública
Las CoPs para la mejora de la Administración Pública
 

Ähnlich wie BSP Trees in 3D Game Engines

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
 

Ähnlich wie BSP Trees in 3D Game Engines (10)

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

BSP Trees in 3D Game Engines

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