Unity Terrain Optimze

来源:互联网 发布:监控 linux 编辑:程序博客网 时间:2024/06/16 16:04

1、Important Fact

Resolution

Property:Function:Terrain WidthSize of the terrain object in its X axis (in world units).Terrain LengthSize of the terrain object in its Z axis (in world units).Terrain HeightDifference in Y coordinate between the lowest possible heightmap value and the highest (in world units).Heightmap ResolutionPixel resolution of the terrain’s heightmap (should be a power of two plus one, eg, 513 = 512 + 1).Detail ResolutionResolution of the map that determines the separate patches of details/grass. Higher resolution gives smaller and more detailed patches.Detail Resolution Per PatchLength/width of the square of patches renderered with a single draw call.Control Texture ResolutionResolution of the “splatmap” that controls the blending of the different terrain textures.Base Texture ResolutionResolution of the composite texture used on the terrain when viewed from a distance greater than the Basemap Distance (see above).More About this:

DETAIL RESOLUTION
Now we’re getting to the grass. In the example, the parameter Detail Resolution is set to 64. This means that in any direction, there will be 64 “patches” of grass. We had 512 quads in any direction on the terrain, but we’ll have only 64 grass patches. That means that each grass path will cover 64 quads. How does this work? Unity will actually store a 64×64 pixel bitmap whose pixels values indicate the quantity of grass in each spot. This means:
Higher detail resolution = higher patch of grass vs. terrain quad density = more draw calls.


DETAIL RESOLUTION PER PATCH
Now there’s yet another parameter that we can set: Detail Resolution per Patch. In previous versions of Unity this was fixed at 8, but you can now increase the value. This parameter controls how blocks in the detail bitmap are grouped to be sent to the graphics card as a single draw call (or actually a couple). If this value were set to 1, then each pixel in the detail map would result in one or more draw calls. For our 64×64 map, this will mean at least 4096 draw calls (and probably double or triple that). The lowest value is 8, and that means (64/8)*(64/8) = (at least) 64 draw calls. So:


Lower detail resolution per path = more draw calls per patch

If you’re not too bothered with the exact placement of your grass, then you can increase the parameter’s value. On the other hand, if you must have fine control on where your plants live, say, on the banks of a river, then you’ll need a higher detail resolution and a lower detail resolution per patch.

According to what I understand, the terrain detail/grass data is represented in a 2D array. So each element of the array represents a small square on the terrain, a chunk of grass/detail. As we know, the bigger the array/resolution, better precision we have positioning the grass. However, it is not feasible to draw chunk by chunk: in a 1024x1024 resolution it would result at least in 1 Million drawcalls (if we draw the whole terrain). So, Unity batchs those chunks based on the "Detail Resolution Per Patch". If you have it set to 8, in a 512x512 detail res map, we would have (512x512) / (8x8) = 4096 batchs (and at least 4096 drawcalls). This way, in order to reduce drawcalls, you should increase "Detail Resolution Per Patch", for instance to 128 (the maximum). In a 512x512, it would be (512x512) / (128x128) = 16 batchs. Since it seems Unity needs a couple of draw calls to draw a single batch (someone correct me if I'm wrong) it would take 32 drawcalls to draw the whole grass in the scene.

The ideal number for "Detail Resolution Per Patch" depends on the density of your detail. You don't want to send a huge amount of triangles (very dense grass) to the GPU. But my guess is that you might be able to set it to 128 in most cases.


Detail Resolution Changer:
Ever had to change the detail resolution texture, and then realized all your work will be erased if you change it from the terrain menu? This script will transfer all detail info to your new resolution of choise. You need to save this in a folder called "Editor" (Script plsase see url below)

参考文档:

http://docs.unity3d.com/460/Documentation/Manual/terrain-OtherSettings.html

http://www.independent-software.com/removing-grass-from-a-terrain-in-unity/

http://answers.unity3d.com/questions/29663/detail-resolution-per-patch.html

http://forum.unity3d.com/threads/small-terrain-scripts.43085/

0 0
原创粉丝点击