Usage of PVS data

Source: Internet
Author: User
Tags bit set
In. the information used for Visibility Detection in the BSP file is stored in a string of bytes, and each bit in the bytes represents a cluster, this is because the number of PVS information for Visibility Detection in the BSP tree is very large, and this method can be used to quickly access and minimize the amount of stored information. The following is an example of this structure. You can use two methods to calculate the number of bytes to be read: Use numofclusters * bytespercluster; or use the length of this structure to subtract two integer bytes. The pbitsets in the structure are dynamically allocated and the calculated bytes are saved. This structure may be the least understandable Part Of The. BSP file format. I will introduce it in detail using some code.
Struct tbspvisdata
{
Int numofclusters; // number of clusters
Int bytespercluster; // bytes (8 bits) in the Cluster's bitset
Byte * pbitsets; // array of bytes holding the cluster vis.
};
To demonstrate what cluster is and how to use it, let's take a simple example. When we perform rendering, we first need to know which leaf node we are in, the leaf node of the BSP Tree stores a series of information about the plane, the brush, and the cluster in which it is located. Once it is detected by comparing the position and split area of the camera, we need to traverse all the leaf nodes to check which clusters are visible to our clusters. After the detection is completed, we can use the cluster's surrounding box and the camera's visual plane to detect, renders the cluster within the video range of the camera.
Assume that there are clusters A, B, and C. Each cluster is saved as one of the bit sets in the in-place set. A bit set is a huge list of binary numbers, each cluster stores a single-digit list. 1 or 0 on each digit indicates whether the cluster represented in the list is visible (1) or invisible (0 ). In most cases, a map contains more than 32 clusters, so a 32-bit integer number cannot be used for representation. This is also why multiple bytes are used for representation in the cluster. Next let's take a look at how it works.
For cluster A, B, and C, the following shows how to represent them in a single set:
L ABC
L 000
The above 0 represents the location of a cluster. Now let's assume that
1. clustera can see B but cannot see C;
2. clusterb can see B and C;
3. clusterc can see B but cannot see.
The bit set saved by each cluster is as follows:
L a 110
L B 111
L c 011
What does this mean? For cluster A, the first digit is 1, which indicates that it is visible, while the second digit is 1, which indicates that cluster B is visible to it, however, if the third digit is 0, it indicates that cluster C is invisible to cluster A due to blocking of walls or other objects. Using this method can get a very good speed.
To check whether a cluster is visible to other clusters, you can perform shift and simple bit operations. The basic rules are as follows:
Int visible = pbitsets [currentcluster * bytespercluster + (testcluster/8)] & (1 <(testcluster & 7 ))
If the returned result is not 0, testcluster is visible to currentcluster. In the formula, we divide the value by 8 because we use eight bytes to store PVS data. In the above formula, the first part is to index the cluster array to obtain the correct bit set, and then use a binary and operation to obtain the correct result. The following is the code for specific detection:
Inline int isclustervisible (tbspvisdata * ppvs, int current, int test)
{
If (! Ppvs-> pbitsets | current <0) return 1;
Byte visset = ppvs-> pbitsets [(current * ppvs-> bytespercluster) + (test/8)];
Int result = visset & (1 <(Test & 7 ));
Return (result );
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.