This document discusses BSP trees in 3D game engines. It describes how leaf-based BSP trees represent geometry as solid volumes rather than polygons. The trees are constructed by recursively splitting geometry using partitioning planes until each leaf node represents either empty or solid space. This allows for efficient collision detection, line of sight queries, and culling of unseen geometry during rendering.
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.
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
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.