Unity Terrain Optimze
2015-10-16 11:06
555 查看
1、Important Fact
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://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/
Resolution
Property: | Function: |
---|---|
Terrain Width | Size of the terrain object in its X axis (in world units). |
Terrain Length | Size of the terrain object in its Z axis (in world units). |
Terrain Height | Difference in Y coordinate between the lowest possible heightmap value and the highest (in world units). |
Heightmap Resolution | Pixel resolution of the terrain’s heightmap (should be a power of two plus one, eg, 513 = 512 + 1). |
Detail Resolution | Resolution of the map that determines the separate patches of details/grass. Higher resolution gives smaller and more detailed patches. |
Detail Resolution Per Patch | Length/width of the square of patches renderered with a single draw call. |
Control Texture Resolution | Resolution of the “splatmap” that controls the blending of the different terrain textures. |
Base Texture Resolution | Resolution of the composite texture used on the terrain when viewed from a distance greater than the Basemap Distance (see above). |
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/
相关文章推荐
- Cg shader with single texture
- Unity Shader Example 1 : Texture
- Cg per-pixel lighting with vertex lights
- Unity卡牌循环滚动点击
- Cg two-sided per-pixel lighting
- Cg per-pixel lighting
- Unity 3d脚本加密方案
- Cg two-sided per-vertex lighting
- unity警告“Tiled GPU perf. warning: RenderTexture color surface (0x0) was not cleared/discarded, doin”
- Unity项目开发准则(转)
- unity游戏与我
- Unity_NGUI原理机制
- Unity3D中级开发工程师面试指导
- Unity初级工程师面试指导
- Ubuntu Unity 桌面快捷键切换窗口技巧
- Unity 3D Android对dll加密和重编译mono源码进行解密
- 转自:Unity3d MonoDevelop格式化代码
- unity学习
- 漫步Unity3D(一)
- 最近整理Unity4.x 项目升级Unity5.0 过程中出现的各种常见问题