BSP technical details (Supplement)-radiosity algorithms in BSP scene
Source: Internet
Author: User
The introduction to radiosity is very simple in my translation of BSP technical explanation, and it is not clearly explained in many places.
Based on the results of your research, we will introduce how to use radiosity In the BSP scenario. Here we will only introduce the key steps. As for the detailed implementation details
For more information, see related code.
Generally, the following steps are required to perform radiosity computing in a constructed BSP scenario:
1. decompose each face in a scenario into patches;
2. Construct a sample array for each patch;
3. Obtain the basic illumination value of each patch;
4. Perform supersample operations on the patch;
5. Obtain the visibility relationship between patches through PVS data, and create a visible patch list for each patch;
6. Simulate the energy transfer process between all patches and perform the radiosity operation.
Next I will introduce each step separately.
In the first step, the energy transfer is performed between patches during the radiosity operation. Therefore, each face must be decomposed into patches.
Patch needs to determine the maximum size of the patch, which is determined by the maximum size of lightmap defined by the engine. In the ID series engine, this value is defined as 64. Therefore
The size of a patch on any axis cannot exceed 64. You can create a patch by knowing this value. To facilitate management, you must first create
First, check the size of each face on the axis. If the size is greater than 64, split the face along the longest axis to obtain two sub-patches. Then
Repeat the above process on the sub-patch until the size of all sub-patches on the face on any axis cannot exceed 64. After obtaining the patch, you need to calculate
The normal status of each patch. Note that face normal cannot be used for all patches on face. A Phong normal algorithm should be used.
Obtain, in order to use this algorithm, the calculation should start from the top-level root patch on face. For the root, use the normal of face. Next
Calculate two sub-patches. You need to use Phong normal to calculate the normal sub-patches. The method is simple. By comparing the sub-patch Center
The coordinates of the coordinates and the coordinates of the centers of the parent patch get a weight value, and then use this weight value to all
The normal vertex is interpolated to obtain the Phong normal of the patch.
Step 2: In lightmap, each pixel is called luxel. Computing lightmap actually gets the color value of each luxel. Therefore, first
You need to create a lightmap for each patch, and then create a sample structure for each luxel in the lightmap. This process is not too complicated.
In the ID engine, each vertex does not have a texture coordinate. It creates a texture coordinate system and a lightmap coordinate system for each face,
To obtain the texture coordinates and lightmap coordinates corresponding to the vertex, you only need to transform the vertex coordinates to the texture space through the matrix,
In order to obtain the sample structure of the patch, we should first obtain the lightmap coordinate system of each patch. Note that this is because
The normal value of patch is Phong normal, not the normal value of face. Obtain the lightmap Coordinate System of the patch and then obtain each vertex on the patch.
After obtaining the lightmap coordinates, you can know how many luxel exists on the patch, and then follow the lightmap
Coordinate axes are used to separate patches and create a sample structure equivalent to luxel.
Step 3: After the above structure is set up, you need to obtain each patch to obtain a lightmap with Direct Illumination. First, you need to obtain all
Light, and then do the following for each light:
1. Obtain the cluster A index of the Light D;
2. Obtain all visible clusters of A through PVS;
3. Traverse every sample on every face in all visible clusters and check whether it can be illuminated by light. If you can use standard
To obtain the color value of luxel.
Step 4: In order to make the lightmap on the patch look more natural, We Need To supersample it to remove the facula and hard edge on the lightmap.
First, compare the color of each sample with the color of the eight samples. If the value is greater than the threshold value, it is required.
Supersample operation, otherwise it is not required. For the sample that requires the supersample operation, first clear its color, and then according to its
The affected lighting types are processed separately. The affected ambient light source is calculated in normal mode, because the ambient light source does not require supersample.
Processing: supersample processing is required for other non-ambient light sources. Generally, the center point of the sample is used for light source calculation.
Coordinates, but this cannot be done when supersample is used. We need to use the vertex coordinates that constitute the sample for calculation and separate them before.
We divide the patch into one sample, and the sample is actually a very small rectangular patch, which consists of four vertices.
For supersample, We need to calculate the normal of four vertices, calculate the color values of each vertex under illumination, and use their arithmetic mean.
The value is used as the color value of the sample.
Step 5. Now we need to perform the last step before radiosity, because the radiosity process is constantly performed between all patches in the scenario.
Until the energy on all patches is balanced, because the energy of the patches can only be obtained from the visible patches,
Therefore, you need to obtain the list of all visible patches for each patch. You can quickly obtain the list of visible patches by using PVS data and
Obtain its shape factor.
Step 6: Now you can perform the radiosity operation on the scenario. First, remove all the lights in the scenario, and then obtain
The initial illumination value is used as the energy required by each patch. In other words, each patch is regarded as the light in the scenario, while
The initial illumination value is used as the illumination value of the light. The following steps are required for each patch:
1. traverse the visible patch list and use the standard illumination formula to calculate and save the illumination value obtained from the visible patch.
2. After step 1 is completed, use the illumination value obtained from the visible patch as the energy required for each patch and re-perform the first step.
3. When the energy required by a patch is smaller than a predefined threshold value, this patch is used to launch the radiosity operation.
From the above introduction, we can see that the entire radiosity operation takes the most time in the last step. Therefore, multithreading can be used to increase the computing speed.
Technology (note that hyper-Threading Technology does not help it) and distributed computing technology to optimize, at the same time, you can also use the progressive refinement algorithm
Computation is accelerated.
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.