Quick drawing and sorting of large-scale grassland

 In the current outdoor scenes of 3D games, the large lush grasses add a lot of color to the game and are an important part of the realism of the player's gaming experience. As we all know, when drawing translucent objects like grass, they need to be sorted from the farthest to the nearest camera, otherwise visual errors will occur. If tens of thousands of grasses are sorted every frame, the CPU overhead is extremely large, even unacceptable. There are three ways to solve this problem:
    one is to sort only the nearby grass, but when the density of the grass is high, there is still a large CPU overhead.
    The second is to use the alpha test method for drawing, so as to avoid the requirement for sorting. However, this method requires extremely high texture quality, and a little carelessness will cause obvious hard edges or flanging on the screen;
    third, through some techniques to achieve fast drawing sorting, not only the real projection drawing order, but also CPU overhead Reduce to an acceptable level.

    Here is a way to implement the third scheme. First, in my terrain editor, the grass data is organized by terrain patch patches. The sorting of the grass becomes a two-step implementation. The first step is to sort the patches that contain grass, and the second is to sort the grass on each patch. Sort, so that at the end, as long as the grass on each patch is drawn in the patch order, the result of sorting all the grass is achieved.
    The key skill here is that sorting the grass on the patch is not done in every frame, nor is it strictly based on the distance to the camera, but according to the position of the camera relative to the patch. +x, -x, +z, -z is sorted in one of the four directions. Only when the camera moves from one quadrant to another quadrant with respect to a patch, the grass on the patch needs to be sorted. When the camera moves continuously, this quadrant change for a particular patch will take a long time to occur, and the further the patch is from the camera, the slower the change. Moreover, the quadrant changes of all patches in the visible area of ​​the camera do not occur at the same time, but are evenly dispersed during the movement of the camera, so there are very few patches that need to be sorted for each frame, which greatly reduces the CPU overhead . The following is the reference picture and the effect comparison chart. The comparison chart is the effect of the same perspective without sorting and sorting.







 

Today, while browsing the www.gamedev.net forum, I accidentally discovered a method that can avoid sorting objects drawn by alpha test such as grass and woods, and can achieve a little trick close to the sorting effect. This method requires two passes to draw and consumes some extra pixel fill rate, but the effect is very good. Consider this method in situations where you can't quickly sort a large amount of vegetation or can't sort such as intersecting patches. Now you can make a wise choice between sorting and unsorted normal alpha test drawing and this two pass alpha test drawing.

    Here is the link address:
    http://www.gamedev.net/community/forums/topic.asp?topic_id=455616

Guess you like

Origin blog.csdn.net/aoying59595512/article/details/8987799