Jump to content
  • Advertisement
Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

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
                // Advance past this run of 0s
                curPos += curVisList[curByte];
                // 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.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!