# BSP Trees and Potentially Visible Sets

This topic is 4518 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

So I'm loading version 30 BSP files (from ID software, used in Quake 1 and Half-Life) into my engine, I have the geometry loaded and rendering, I have the BSP Tree loaded and traversing, and I have the vis list (list of Potentially Visible Sets or PVS for each leaf of the BSP tree) loaded and a decompression algorithm written for it because in the vis list 0s are run length encoded. So them I implemented some rendering functions to use all this. But I don't get a solid render from any point in the map. I have a few questions but the first and most important is does any one know about the visList in this file format, if my understanding is correct then the PVS I am getting from my decompression function are incorrect. The PVS for those who don't know is a list of length numLeaves. There is one such list for each leaf. The list, once decompressed, is an array of bools, one for each leaf, if the corresponding bool is true, then the leaf is visible from the leaf the list is meant for. So, if you get the PVS for leaf[0] the first element in the PVS MUST be true, since you are in the leaf it MUST be visible to you! That last part is simply my understanding of it, and if that last part is true, then my PVSs are incorrect. So I was wondering if: a) Any one knew the file format and could shed some light on my decompression function. And b) If any one knew of any tools or quake 2 / half-life commands or tools to view the PVSs in/for those engines so I can actually check my data and see if they PVS are right or not. Here is my decompression function:
bool* BSPManager::getPotentiallyVisibleSet(__int16 leafIndex)
{
bool *pvs = NULL;
bool *curPos = NULL;

{
pvs = new bool[numLeaves];
memset(pvs, 0, numLeaves);
curPos = pvs;

byte *curVisList = (visList+(leaves[leafIndex].visOffset));

// Loop through all the relavent bytes in the compressed list
for(int curByte = 0; curByte < (numLeaves+7)/8; curByte++)
{
// Check for a run of 0s
if(curVisList[curByte] == 0)
{
// Advance to the RLE count byte
++curByte;
// Advance past this run of 0s
curPos += curVisList[curByte];
}
else
{
// Iterate through this byte with bit shifting till only 0s
for(byte bit = 1; bit != 0; curPos++, bit <<= 1)
{
// Test a bit w\ the bit mask
if(curVisList[curByte] & bit)
*curPos = true;
}
}
}
}
return pvs;
}


Also, it is my understanding that with this BSP format version, the BSP tree it's self IS used for rendering, so as I traverse the tree I render out the faces it points to.

1. 1
Rutin
42
2. 2
3. 3
4. 4
5. 5

• 9
• 27
• 20
• 14
• 14
• ### Forum Statistics

• Total Topics
633390
• Total Posts
3011631
• ### Who's Online (See full list)

There are no registered users currently online

×