Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.
Nächste SlideShare
×

BSPTreesGameEngines-1

• Full Name
Comment goes here.

Are you sure you want to Yes No
• Loggen Sie sich ein, um Kommentare anzuzeigen.

• Gehören Sie zu den Ersten, denen das gefällt!

BSPTreesGameEngines-1

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