Version: 2023.2
Stamp Terrain
画笔

地形图层

A Terrain Layer is an Asset that defines a Terrain’s surface qualities. A Terrain Layer holds Textures and other properties that the Terrain’s Material uses to render the Terrain surfaces. Because Terrain Layers are Assets, you can reuse them on multiple Terrain tiles.

You can add Textures to the surface of a Terrain to create coloration and fine detail. Terrain GameObjects are often large, so it’s best to use a base Terrain Layer with Textures that tile over the surface and repeat seamlessly. You can use multiple Terrain Layers, each with different Textures, to build up interesting, varied Terrain surfaces.

The first Terrain Layer you apply to a Terrain automatically becomes the base layer and spreads over the whole landscape. You can paint areas with other Terrain Layers to simulate different ground surfaces, such as grass, desert, or snow. To create a gradual transition between grassy countryside and a sandy beach, you might choose to apply Textures with variable opacity.

带有沙地纹理的地形
带有沙地纹理的地形

创建地形图层

要直接从 Terrain Inspector 中创建地形图层,请单击 Terrain Inspector 顶部工具栏中的画笔图标,然后从下拉菜单中选择 Paint Texture。在 Terrain Layers 部分底部,单击 Edit Terrain Layers 按钮,然后选择 Create Layer

在 Terrain Inspector 中创建图层 (Create Layer)
在 Terrain Inspector 中创建图层 (Create Layer)

To edit terrain layers from an overlay:

  1. In the Terrain Tools overlay, select Materials Mode Material Mode Menu button. Materials Mode tools display at the end of the Terrain Tools overlay.
  2. From the available Materials Mode tools on the Terrain Tools overlay, select Paint Texture Paint Texture.
  3. In the Tool Settings overlay, select Edit Terrain Layers.
Create Layer in Overlays
Create Layer in Overlays

选择 Create Layer 时,Unity 会打开 Select Texture2D 窗口。在此处,选择要用作地形图层__漫射 (Diffuse)__ 通道的图像。要将__法线贴图 (Normal Map)__ 或__遮罩贴图 (Mask Map)__ 纹理分配到地形图层,请在 Project 视图中选择相应的地形图层,并使用其 Inspector 窗口。

或者,若要创建未自动与地形关联的地形图层资源,请右键单击 Project 窗口,然后从上下文菜单中选择 Create > Terrain Layer。然后,在 Inspector 窗口中,为新地形图层配置各种属性。

For information about how the number of Terrain Layers affects rendering performance, see Rendering performance. Even assigned Terrain Layers that you don’t actually paint onto the Terrain tile might impact the rendering performance.

添加地形图层

最初不会为地形指定地形图层。默认情况下,在添加地形图层之前会使用棋盘纹理。

在项目中创建地形图层后,单击 Edit Terrain Layers 按钮,然后选择 Add Layer 以打开 Select TerrainLayer 窗口。双击此窗口中的地形图层,将其添加到您的地形。

地形图层属性

Depending on the Material set in the Terrain Settings and the Render Pipeline in use, you might see different options and properties in the Inspector.

Inspector 中的地形图层设置
Inspector 中的地形图层设置
属性 描述
Diffuse 漫射纹理表示地形图层的基色纹理。漫射纹理的 Alpha 通道具有不同用途,这取决于用来渲染地形的活动可编程渲染管线和着色器。

例如,高清渲染管线 (HDRP) 和通用渲染管线 (URP) 使用 Alpha 通道来获得平滑度。但是,如果地形图层上有遮罩贴图纹理,则会将漫射纹理的 Alpha 通道用于密度值。
Color Tint 如果分配了漫射纹理,地形图层设置中将显示一个名为 Color Tint 的新字段。单击拾色器字段并选择要使用的颜色。

Color Tint 是 HDRP 和 URP 中可用的功能。
Opacity as Density 指定是否使用存储在地形图层漫射纹理的 Alpha 通道中的值来渲染地形图层,而不是使用通常的泼溅贴图权重或遮罩贴图的高度值。Unity 使用 Alpha 通道值作为图层混合的阈值。

Opacity as Density 是 HDRP 和 URP 中可用的功能。禁用地形的地形光照材质上的 Enable Height-based Blend 选项时,以及将漫射贴图和遮罩贴图纹理分配给地形图层时,此选项可用。
Normal Map The Normal Map Texture contains the normal information for your Terrain Layer. Unity uses this information in lighting calculations.

• If you don’t assign a Normal Map Texture and enable instancing in the Terrain Settings, the Terrain uses the normals generated from the Terrain heightmap.

• If you assign a Normal Map Texture and enable instancing, Unity uses the Normal Map Texture instead of the normals generated from the heightmap.

• If you disable instancing on the Terrain, the built-in Terrain Material uses normals generated from the Terrain geometry, even if you assign a Normal Map Texture on the Terrain Layer.
Normal Scale 如果分配了法线贴图纹理,地形图层设置中将显示一个称为 Normal Scale 的新字段。该字段值用作法线贴图中的法线值的缩放因子。值为 0 意味着法线贴图中存储的法线的缩放比例为 0,而值为 1 意味着法线处于完整缩放比例或发挥完整影响。

不同 Normal Scale 值的示例和结果:
Normal Scale = 0 • 将未打包的法线值乘以 0。
• 法线的强度(即长度)将为 0,并且对光照计算没有影响。地形上的网格三角形实际会使用网格法线来进行光照计算。
Normal Scale = 1 • 将未打包的法线值乘以 1。
• 法线的强度将为 100%。
Normal Scale = 2 • 将未打包的法线值乘以 2。
• 法线的强度将为 200%,并显示为 Normal Scale 为 1 的法线的两倍。
Normal Scale = –1 • 将未打包的法线值乘以 –1。
• 法线的强度将为 100% 但是为负,使法线指向与 Normal Scale 为 1 的法线相反的方向。
Mask Map TerrainLit 着色器(这是高清渲染管线 (HDRP) 和通用渲染管线 (URP) 的一部分)使用此遮罩贴图纹理 (Mask Map Texture) 数据。自定义地形着色器也可能将此纹理用于用户自定义的目的,例如环境光遮挡或基于高度的混合。

对于 HDRP 和 URP TerrainLit 着色器,遮罩贴图纹理的 RGBA 通道对应于:
R 金属度
G 环境光遮挡
B 高度
A 平滑度(漫射 Alpha 将变成密度)
Channel Remapping 如果分配遮罩贴图纹理,地形图层设置中将显示一个称为 Channel Remapping 的新标题。单击该标题旁的三角形可以显示最小和最大 RGBA 值的字段。Unity 使用这些范围值来重新映射遮罩贴图纹理的每个通道中的值。
Specular 地形图层的镜面高光颜色。
Metallic 地形图层的总体金属度值。
Smoothness 地形图层的总体平滑度值。
Tiling Settings 适用于地形图层使用的所有纹理的平铺设置。
Size 地形空间中纹理的大小,以及纹理平铺的频率。
Offset Unity 应用于地形图层中每个纹理的采样位置的基本偏移。

纹理绘制

Unity 将您添加的第一个地形图层应用于整个地形。如果添加多个地形图层,请使用 Paint Texture 工具将后续纹理应用于地形。

如果您添加一个没有任何地形图层的新地形瓦片,并在此瓦片上进行绘制,系统会自动将所选地形图层添加到新的地形瓦片。因为这是第一个地形图层,所以该纹理成为基础图层,并填充整个地形瓦片。

在 Terrain Inspector 中的 Brushes 下,有一个框中会显示可用的画笔,而且其下还有 Brush SizeOpacity 选项。请参阅创建和编辑地形以了解关于这些工具的更多信息。

渲染性能

分配给一个地形瓦片的地形图层数可能会影响渲染器的性能。地形图层的建议最大数量取决于您的项目使用的渲染管线

  • If your Project uses the Universal Render Pipeline (URP) or Built-in Render Pipeline, you can use four Terrain Layers per Texture pass, with no limit on the number of passes. This means that though you can to use as many Terrain Layers as you want, each pass increases the time spent rendering the Terrain. For maximum performance, limit each of your Terrain tiles to four Terrain Layers.

  • If your Project uses the High Definition Render Pipeline (HDRP), you can add up to eight Terrain Layers per Terrain tile, and the system renders them in a single pass. No additional passes are possible. If you add more than eight Terrain Layers, they appear in the Unity Editor but are ignored at run time.


  • 2021–01–27 页面已修订

*更新了有关 Color Tint 和 Opacity as Density 属性的信息

TerrainLayer

Stamp Terrain
画笔