I recently read a paper in i3d last year, shadow caster culling for efficient shadow ing. I think it's good. Here is a brief summary. The basic principles of algorithms are easy to understand, as shown in. It can be seen that for camera under a specific frame, the visible ry element is a finite subset of the entire scenario, the Shadow calculation must also be a subset of these visible geometric element sets. Therefore, shadow is generated.
When map is used, you can only draw the shadow caster projection that has an impact on the shadow runner er that currently needs to calculate Sm to SM (for example, in the figure, you can only draw C to SM )., while C0, C1... CN can be omitted ).
The core of this algorithm is to calculate such an optimized caster set to avoid unnecessary caster rendering. The basic process of the algorithm is as follows:
- First, determine the set of shadow referers.
- Create a Caster Mask by using the aggreger for use when the caster is rendered to the SM in the next step.
- Use the caster mask and the culling operation to perform efficient caster Rendering
- General shadow ing operations
The most important part is the second step, that is, how to use the javaser set to create a Caster mask for the next step of rendering the shadow. Here, the mask is actually a stencel buffer or texture that contains the projection of the caster to be drawn. Its usage principle is the same as that of occlusion culling. The worker set here is the result set for cropping the scene in the current camera, which requires the engine's cropping system to have such a set extraction function. There are four methods for generating caster mask:
Bounding Volume mask
This is the most direct and conservative method. It uses the bounding body of the ry element to project and generate a mask. Here, you can have multiple options for the type of the surrounding body, such as AABB, sphere, and OBB. Of course, different types of surrounding boxes also have different effects on the final precision.
Geometry mask
This method further improves the accuracy of the bounding body, and directly uses the ry element to draw to generate a mask. Compared with BVM, the accuracy has improved a lot, but the problem that comes with it is the rendering efficiency, however, it also has another advantage: For those body elements that are both caster and Cycler, you can update and write the data into the SM while generating the mask, save some operations for the next generation of SM.
Geometry & bounding volume mask
In view of the advantages and disadvantages of BVM and GM, the two can also be used in combination. In this method, we need to classify the reciver set and extract the intersection between the handler er and caster from it. We need to use the GM method for these ry to avoid the write of depth in the next SM; other ry structures are operated using the BVM method. The temporal coherence method is used to determine the object meta that needs to be drawn using geometry mask, if a volume er is visible in the SM of the previous frame, it is regarded as a volume er & caster in the current frame, and the mask is updated using the GM method.
Fragment mask
The most accurate of the above three methods should be the geometry mask method, but in some cases it will still get the results of over-conservative mask, in this way, the subsequent generation of SM is not much more efficient, as shown in the following figure:
A large surface in the figure may be a large terrain in the scenario (the whole terrain belongs to a single ry element, that is, the preceding geometry Unit). Under the current camera, only a few of them are visible. However, in this case, both BVM and GM need to completely draw it into the mask. However, because of its large size, the whole mask may be directly filled up, as a result, all the caster will need to be drawn and will not play the role of caster culling. In this case, the more accurate method is to extract the visible Camera part and write it into the mask. There are two methods:
- Subdivide large objects and process them into multiple independent and small ry elements. In this way, although it cannot be completely accurate, it can at least reduce the scope of useless areas written to the mask to improve the crop intensity of the next caster culling.
- The Operations compared by pixel are used to precisely extract the visible part, which is equivalent to a quasi shadow ing operation in advance. For example, for Pixel a in a ry element, You need to determine whether it is a receiver point in camera, this may need to record some geometric meta projection information under the current camera (if G-buffer is available, it can be directly used ), then, Project A in light space to camera space and make a series of judgments to get the results. If it is a volume er, update it to the mask. If not, discard it. In this way, the exact mask can be calculated.
Among the above methods, although the last method has a high precision, it is complicated to operate and has a great impact on engine changes. The final result may be worth the candle. I personally think that the third method is more practical. If there is a well-developed culling System in the existing engine, its application is not too complicated and its performance should be improved.