BSP Decompilation

From Valve Developer Community
Jump to: navigation, search


This article or section is a stub. You can help by adding to it.

In the level design within the GoldSrc GoldSrc Engine, understanding the intricacies of Binary Space Partitioning decompilation methods is fundamental. The GoldSrc Engine, the powerhouse behind classics like Half-Life Half-Life and Counter-Strike Counter-Strike, relies on BSP trees to render its intricate 3D environments.

Tree-Based Decompilation Method

The Tree-Based Decompilation Method is a decompiler that operates by processing the BSP tree, specifically focusing on hull 0 (point hull) for each brush model. In the context of this method, the world itself is considered as model 0 and encompasses all brushes not associated with a brush entity. Each brush entity contributes one brush model to the map. The process of generating brushes involves several steps. Initially, the method calculates the bounding box for the model, expanding it by 8 units to accommodate the outermost brush faces in the map. A brush of this size is created and subsequently split into multiple components by navigating the BSP tree. The resulting set of brushes provides an approximate representation of the original map, although it may not be entirely accurate. To enhance the representation, a texturing phase is employed to identify the faces that best match the generated brush faces. If the brush optimization is set to achieve the best texture match, brushes are split further to closely resemble the original brush faces. Additionally, brushes with identical contents and texture properties that form convex shapes can be merged together when brush merging is enabled. Ultimately, the Tree-Based Decompilation Method converts each brush into its map source file representation. Brushes lacking textures on any faces, including those originating as CLIP or NULL textured brushes, are skipped, potentially resulting in some brush entities without any brushes.

Face-To-Brush Decompilation Method

The Face-To-Brush Decompilation Method is an alternative decompiler approach that works by converting each individual brush face in the map into a separate brush. This method utilizes the map's visual meshes used for rendering brush models, excluding CLIP brushes and those with stripped textures, such as NULL. The brush generation process begins by merging faces with matching texture properties, which form a single flat and convex polygon. Each face is then transformed into a brush by cloning the polygon, inverting it, and offsetting it by the inverse of the face normal to create the back face. Additional faces are generated to connect these two faces, resulting in a brush structure. Similar to the Tree-Based method, the Face-To-Brush Decompilation Method also culminates in converting each brush into its map source file representation.


Tree-Based Decompilation Method

  • Limited Accuracy: The Tree-Based method provides only an approximate representation of the original map, which may not be perfectly accurate.
  • Texture Optimization Complexity: Achieving the best texture match can be a complex and resource-intensive process, particularly for intricate maps.
  • Brush Skipping: Brushes with no textures on any faces, including those originating as CLIP or NULL textured brushes, are skipped, potentially resulting in incomplete brush entities.

Face-To-Brush Decompilation Method

  • Potentially Complex Geometry: The method may generate a large number of brushes due to converting each face into a brush, potentially leading to complex geometry in the decompiled map.
  • Resource Intensive: The Face-To-Brush approach might require more computational resources due to its precise conversion of each face.
  • Exclusion of Certain Brushes: CLIP brushes and brushes with stripped textures (e.g., NULL) are not included, which could lead to the omission of important map elements.


Tree-Based Decompilation Method

  • Efficiency: Tree-Based Decompilation is generally more efficient at generating an approximate representation of the map's structure.
  • Texture Optimization: It offers the capability to optimize brushes to closely match the original texture properties.
  • Brush Merging: When enabled, brushes with the same contents and texture properties can be merged to simplify the map.

Face-To-Brush Decompilation Method

  • High Fidelity: Face-To-Brush Decompilation excels in preserving the appearance of brush faces, offering a high level of fidelity to the original map.
  • Individual Brush Faces: Each face is converted into a separate brush, allowing for precise representation of the map's visual appearance.
  • Reduction in Complex Geometry: By converting faces into brushes, it may reduce complex geometry present in the map.


The Tree-Based and Face-To-Brush Decompilation Methods are two distinct approaches to decompiling brush models in the world of mapping and level design.

Tree-Based Decompilation focuses on processing the BSP tree for hull 0, providing an approximate representation of the map. It involves splitting brushes and optimizing textures to match the original map. On the other hand, Face-To-Brush Decompilation method converts each brush face into an individual brush, emphasizing precise preservation of brush faces' appearance.

The choice between these methods may depend on the specific requirements of a project. Tree-Based Decompilation offers an efficient way to approximate the original map's structure, while Face-To-Brush Decompilation prioritizes accuracy by individually converting faces into brushes. The decision on which method to use should be based on the desired level of fidelity and the nature of the project.

See Also