Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to analyze flat Quadtree terrain and Virtual Texture based on Unity3D

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

How to analyze the flat quadtree terrain based on Unity3D and Virtual Texture analysis, I believe that many inexperienced people do not know what to do. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Terrain rendering has the characteristics of high repetition, free height control, high mapping complexity and coherence requirements. Therefore, it is necessary to use a special drawing method to complete the drawing. The previous terrain rendering method shared by Ubisoft Far Cry 5 uses the QuadTree + Virtual Texture method. This method has many advantages, because QuadTree submits fixed patches, so it can be done in GPU from culling to submitting, which is similar to the GPU Driven Pipeline idea we implemented before, and Virtual Texture can be used to represent all kinds of Geometry information, such as height, diffuse, normal, roughness, etc. Therefore, we also decided to use this technology to realize the rendering and editing of large terrain.

The implementation of quad tree is not difficult for friends with solid algorithm ability, so here we directly skip the basic algorithm principle of quad tree and give some code examples to explain. Because of Virtual Texture enhancements, you do not need to prepare additional information such as Material ID when building a quad tree. You only need to save the location coordinates of the current block, LOD level (for switching LOD), and cache status (for easy recursion). The data structure will also be very simple:

One small detail is that in order to improve the performance of memory allocation, four child nodes are allocated at the same time, which is easy to be habitually missed by many developers who are used to C++ 's advanced features, but the performance is picked out from such small details. So be sure to pay attention to:

Because the manual memory allocation provided by Unity is used, it is entirely possible to use Burst Compiler to speed up the calculation on the CPU side:

When you are ready, submit it directly to StructuredBuffer and other Compute Shader for culling and drawing. The rendering result is as follows (Albedo map is displayed by local UV):

The Procedural Virtual Texture mentioned by Farcry 5 is divided into two parts. The first part, Procedural and Adaptive, basically accounts for 99% of the workload. The main workload lies in a variety of automatic generation, manual high-performance editing tools, and game logic for dynamic loading and unloading as players move; the second part is Virtual Texture, which basically accounts for less than 1% of the workload. In the spirit of picking soft persimmons first, let's simply implement the following part of Virtual Texture.

The so-called Adaptive Virtual Texture sentence summary is: save the map of the object pool. First, open a Render Texture as an Index map and store a Scale Offset, that is, an index pointing to the location of the Atlas. At the same time, open an Atlas, when the local shape is loaded into this part, load the map to some part of the Atlas from the hard drive, and put the location of the newly loaded part in the Index map, that is, use Index map as a jump table. When rendering a terrain, you can directly use the world coordinates of the current terrain as UV to read Index map, which is equivalent to a huge map used by the whole terrain, but most of the middle part of the map is not loaded. The pseudo code for reading the map is roughly as follows:

The physical size of Texture2D _ IndexMap;Texture2DArray _ Atlas; SamplerState sampler_Atlas;float4 _ IndexMap_TexelSize;//Indexmap float4 TexVT (float2 uv) {/ / converts the incoming UV to the absolute coordinates of Indexmap. Uv * = _ IndexMap_TexelSize.zw;// reads IndexMap, XYZW four channels mean: size ratio, horizontal offset, vertical offset, array index float4 scaleOffset = _ IndexMap [(uint2) uv]; / / get the decimal part of the absolute UV and get the local UV offset float2 localUV = frac (uv); localUV = localUV * scaleOffset.x + scaleOffset.yz / / use the converted UV to read Atlas float4 value = _ Atlas.SampleLevel (sampler_Atlas, float3 (localUV, scaleOffset.w), 0); return value;}

This point is also made clear in PPT:

With this flexible space allocation and reuse, you can use the cone to load only the map in the field of view, and if the memory and performance are abundant and the player often needs to rotate the lens at high speed, you can also use camera coordinates to load the map around the camera.

At the same time, PPT sharing also pointed out that because all the pictures close to each other in the world space are also close to each other in IndexMap, when downgrading LOD, you only need to put four-in-one images from four areas into another area, pushing the boat along the river with almost no extra consumption.

Here we give a complete set of API:

Soft persimmons are easy to squeeze. All that's left is hard persimmons. Of course, due to the huge workload, it may take me months or years to build a Virtual Texture with a complete tool process, so here is only an imaginative prototype for learning and discussion purposes.

From the above implementation, it is not difficult to see that the implementation of Virtual Texture is all real-time projection of Render Texture, real-time loading, real-time unloading, real-time merging, so in the design of the stored data format, we do not need to save a whole painted map, because this will lead to the game package completely out of control, we only need to provide the necessary "seed" for painting.

Such seeds are generally sample maps, Blend Mask maps, decal models, etc. These seeds can be reused in large numbers and can be generated using programmed DCC tools. For example, the RT here is mixed sequentially by multiple prepared maps, each of which has a different Tiling density:

Although the Tilling is dense, there is no obvious sense of repetition due to the different Mask used and evenly mixed:

It is obviously not enough to mix with Mask. Irregularities such as stones, dirt roads and moss are often achieved by decals in production. The idea of decal is also relatively simple and rough, directly construct an orthogonal projection matrix above the patch, and "flatten" the Geometry information of the model onto the map:

The decal itself is the model, directly rendering the decal itself.

Eventually the decals are richer:

After reading the above, have you mastered how to analyze the flat quadtree terrain based on Unity3D and the analysis of Virtual Texture? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report