PVSAlgorithm
Type: posting | Source: Sorting | time:
Finally, we finished reading the vbsp and vvis of hl2 and flipped through q3map.CodeThe code of the two is too similar. We can see that the BSP splitting and portal search should have been finalized in Q2. Therefore, the two use the same algorithm. Next I will focus on the calculation of PVS algorithms, becauseArticleIn BSP technical explanation, PVS is calculated by determining some sampling points on each portal and then performing Ray cast to calculate PVS. This method is not guaranteed in speed, and it is also very troublesome to handle. 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 vertices and two sides, the portal located on the opposite side only needs to reverse the vertex order of ploygen. 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 located 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.