Section 3 lighting operations in indoor scenarios
Radiosity algorithms were first proposed by Goral, Cindy M, Torrance, kenth E, Greenberg, Donald P, battaile, and Bennett in the paper modelling the interaction of light between diffuse surfaces. They use radiosity to simulate the transfer of energy between the diffuse reflection surface. The diffuse reflection surface is opposite to the light on the surface for the same reflection in all directions, it only transmits reflected light in the reflection direction. Due to the characteristics of the diffuse reflection surface, this means that the surface looks the same for all viewing angles, so that only one illumination operation is required for each surface in the scenario, this technology can also be used in the pre-rendering of scenes, so it is used by a large number of 3D games.
Next, I will briefly explain how radiosity works, and focus on how to use the BSP tree to accelerate radiosity computing. For more information about radiosity, see the previous chapter. The radiosity technology is designed to make the illumination in a scenario look more realistic and smooth. If we use a illumination model that keeps moving forward without considering reflection, when the light in the scene illuminates an object in the scene, it does not calculate the light reflected in the distance, so that the shadow in the scene looks very sharp and the object surface looks very unreal. To use the radiosity technology, we need to divide the scenario into a small part. Each part is called a patch, and each patch has an initial energy level, if it is not a light, it is usually 0. There are many ways to allocate the energy in the scenario. Here we will use the method called interactive radiosity. The process of this method is that we start to send energy from the patch with the highest level of unsent energy in the scenario. After the energy passes, the level of the patch that no longer sends energy is set to 0, repeat this process until the energy level of each patch in the scenario is smaller than a predetermined value.
When energy is sent from one patch (j) to another patch (I), we use the following formula:
Bi = Bi + Bj * fij * AI/AJ
Here Bi = patch (I) Energy Level bj = patch (j) Energy Level
Ai = patch (I) effect region AJ = patch (j) effect Region
Fij = coefficient between patch (I) and patch (j)
In the formula, fij is determined by the following formula:
Fij = (COS qI * Cos Qj)/D2 * hij
Here, fij = the coefficient between patch (I) and patch (j)
Qi = angle between patch (I) and patch (j) normal
Qj = angle between patch (I) and patch (j) normal
D = distance between patch (I) and patch (j)
Hij = visibility coefficient between patch (I) and patch (j. If there is only one ray between two patches, this value is 1 and 0 if there is no light. Generally, because every Patch Is Not A vertex but a region, there are many lines of light.
From the above formula, we can see that radiosity computing is very time-consuming in the scenario. The complexity of this function is O (N3), where N is the number of patches in the scenario. For each patch in a scenario, you need to send at least one ray to other patches. Therefore, you need to track and compute almost all polygon in the scenario. In the above formula, the calculation of the coefficient h is very time-consuming. Next we will take a look at how to optimize its calculation in the BSP tree.
Radiosity computing in the BSP Tree
Before performing illumination computing in a scenario, we need to divide the scenes into patches. One method is to set each patch to a predetermined size at the beginning. When calculating the energy of each patch, if the energy on the patch is large enough, separate the patch. However, this method is very time-consuming. Therefore, we must look for a better method to optimize the computing through the BSP tree.
In the general algorithm of radiosity, each light source in a scenario is regarded as one or more patches. Here we can improve it by placing each light source in the leaf node where it is located, next, each Light Source sends its own energy to all patches in the scenario. When this process is completed, the radiosity computing will end. To make the final results look better, you can use a technology called progressive refinement to make small changes to this method. During each process, a high-energy patch in the leaf node sends energy to other low-energy patches, the result is that the high-brightness patch sends energy to the patch in the shadow. This is because there is no truly dark place in real life, and it is more or less to obtain the light reflected by some other objects.
Because computing is very time-consuming and requires optimization, the PVS information obtained when the BSP tree is rendered can be used to remove some useless calculations when selecting which patches will receive energy. This is because the same method is used for Ray Tracing during PVS calculation.
The algorithm for allocating energy through scenarios is as follows:
L function radiosity
L parameter:
L tree-BSP tree for radiosity calculation.
L return value:
L none
L function:
L send energy between patches in the scenario.
Radiosity (tree)
1 For (each leaf L in tree)
2 For (each light S in L)
3 For (each leaf V that is in L's PVs)
4 send S's energy to the patches in V
L Statement 5 below is used to allow the map editor to check the rendering effect of the scene at any time. If he feels that he is good enough, he can interrupt the propagation of energy.
5 while (not looks good enough)
6 For (each leaf L in tree)
7 For (each leaf V that is in L's PVs)
8 send energy from the patch with the most unsent energy in L
To all patches in v.
Complexity Analysis
The operation cost of this function is too high. It can be called the time killer. In the worst case, every ray of light has to detect every polygon in the scenario. In this case, the complexity is O (N3 ), here N is the number of patches in the tree. In general, optimization can reduce a large amount of computing, but it cannot be calculated because it depends on the complexity of the tree structure.
The above function provides a method that makes full use of the advantages of the BSP tree to accelerate illumination operations in scenarios, especially to significantly reduce the amount of light tracing computing, in addition, the map designer can decide to interrupt the rendering loop if the rendering effect is acceptable during scene rendering. The pre-rendering of the map is too convenient, and the running time can be determined based on the rendering effect.
Section 4 Pre-rendering of the BSP Tree
Now we need to complete a complete BSP engine preprocessing process. The following algorithm shows how to render the scenario to the BSP tree.
L function render-scene
L parameter:
L scene-rendered scenario
L return value:
L a BSP tree.
L Function
L pre-rendering to obtain a BSP Tree Containing scenario information.
Render-scene (scene)
L use the object in the description scenario to render the BSP tree.
1 geometrypolygons = {}
2 For (every object o that contains scene elements)
3 geometrypolygons = geometrypolygons u o. polygonset
4 GENERATE-BSP-TREE (tree. rootnode, geometrypolygons)
L allocate sampling points on leaf nodes.
5 distribute-Sample-points (tree. rootnode ,{})
6 trace-visibility (tree)
7. For static objects in each scenario, object o
8 For every polygon P in object o
9 push-polygon (node, P)
L The create-patches function is an undefined function. Because our solution is not very efficient, we did not detail it.
10 create-patches (tree)
11 radiosity (tree)
Complexity Analysis
The function complexity is as follows:
Worst-case Function Description
GENERATE-BSP-TREE O (n2 lg n) O (n2) n is the number of polygon in the scenario
Distribute-Sample-points Q (NP + XY) q (NP + XY) n indicates the number of polygon in the tree, and P indicates the number of typical points in the tree, X and Y are the width and height of the split face.
Trace-visibility O (n2) O (n lg n), where N is the number of polygon in the tree.
Radiosity O (N3) O (n2 lg n) n indicates the number of patches in the tree.
In general, this column shows the time that the algorithm usually needs to run. The biggest impact on the algorithm time is the function radiosity, which makes the complexity of the entire algorithm tend to O (N3 ).