BSP technical explanation (Supplement)-PVS Algorithm

Source: Internet
Author: User
Finally, I finished reading the vbsp and vvis of hl2 and flipped through the q3map code at will. I found that the codes of the two are too similar. We can see that in BSP division, the portal search should have been finalized in Q2, so the two use the same algorithm. Next I will talk about the PVS algorithm, in my translated article "BSP technical details", PVS is calculated by determining some sampling points on each portal and then performing Ray cast to calculate PVS, the speed of this method is not guaranteed, and the processing is also very troublesome. The ID obtains PVS by performing clip on the polygen of each portal. The speed is indeed better than the previous method.
A lot. Next I will introduce the algorithm in detail. If you are not familiar with BSP, You need to clarify several concepts: one is cluster. For indoor scenarios, it is completely composed of clusters, simply put, you can think of it as a room in the scenario, and the other as a portal. The cluster in the scenario is connected by a portal as a whole, and you can think of it as a door or window in the room. During PVS computing, the entire scenario has been divided into BSP trees. After the portal is searched, the cluster and leaf node are connected.

 

1. First, perform preprocessing on all the portals so that one portal can only be associated with one cluster. The purpose of this operation is to obtain a one-way portal, that is to say, the portal is visible only on one side. This is done to facilitate processing. We know that a portal is usually connected to two clusters and generally uses the portal on the front of the plane where the portal is located. To achieve the above purpose, we need to divide the portal into two sides, since each plane in BSP stores two sides, the portal on the opposite side only needs to reverse the ploygen
Vertex order. It is specified that a portal is only associated with the luster in the normal direction of its plane, and the number of portals saved after preprocessing is twice that of the original one.

2. Next we need to classify the portal. With simple knowledge, we know that since every portal is one-way visible, only the portal located in the visible direction of the portal (called the front direction) can be visible, we need to obtain and save a list of front portals for each portal.

3. Next, we need to remove the invisible portals in the front portal list of each portal. We know that the scenario is completely composed of cluste connected by one portal. For a portal, the portal located in the same cluster must be visible, the most basic requirement for other portals to be visible is that they can be connected to the cluster through other portals, therefore, through the portal connection, we can remove the portals that are not connected to the current portal from the front portal list and save them to the floodportal list.

4. After the above processing, we have removed most of the invisible portals. The visible portal must be included in the flood portal list. Therefore, we need to use a more precise method for inspection. For ease of description, I assume that the current calculation of the PVS Portal is a. Any portal connected to the cluster CA of A is called B. Note that B must be visible, therefore, the cluster CB where B is located must be visible, but other portals connected to CB may not be visible. to check whether B is visible, we assume that the portal selected is called C. Now, the problem is simplified to knowing whether a and B are visible to C. The algorithm is as follows:
Select a vertex on a and a vertex on B to form a clip plane. To ensure this is a valid clip plane, we need to check it, to simplify the process, we first need to ensure that the normal direction of clip plane must be directed to the external side of portal a, that is, all vertices on a are located on the back of clip plane.
Second, we need to ensure that all vertices on portal B are on the front of clip plane, this ensures that when you select an edge on the leftmost side of a, it must form a clip plane with a vertex on the rightmost side of B, when you select an edge on the rightmost side of A, you must construct a clip plane with the leftmost Vertex on B, merge all clip plane to obtain the largest visible frustum from A to B. Only the portal located inside frustum is visible. After this frustum is set up, we can use it to perform clip operations on the polygen of C. After C clip, if there is no polygen inside the frustum, it is invisible, otherwise, portal C is visible and the visible polygen is saved. When C is visible, we need to check the portal connected to C. The method is the same, but the above portal B is changed to C and you must note that, build the polygen of frustum using C. It should be the polygen data after clip. By performing recursive operations on the flood portal list of a through the above method, a real visible portal set is obtained and saved to the VIS portal list. It also needs to be pointed out that the process of establishing clip plane actually takes two times. The first time is from A to B, and the second time is from B to, the reason for this is that not all the extreme points are located on B, or it may be located on a. Therefore, two operations are required.

Q: How to generate frustum Based on AB?
A: If both portal a and portal B are in a quadrilateral, the four frustum faces are like this. The left side of a and the right side of B constitute a plane, the right side of a and the left side of B constitute a plane, and the upper and lower directions are the same. In this way, a frustum is formed. However, when the portal is composed of multiple vertices, there will be no more than four frustum surfaces, which will form a multi-faceted frustum.

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.