Terrain Mesh Blending

ONLINE
Status:

Here you will find information on how to use the terrain blending asset. This site uses animated .gif images to simplify the setup process. Please make sure, your browser supports this format.

If you have questions visit the forum or contact the author by using the links below.

Release Notes:

  • v 1.4  - Automatic texture properties. New online-manual. Automatic normal map. Linear + exponential blending gradients. Updated messages.

Contents

  1. Setup

  2. Script

  3. Materials

  4. Overlay Shaders

  5. Custom Shaders

UP

Setup

In this section you will learn how to setup the blending with an existing terrain in five easy steps. This is a short, basic setup guide. For more information on using all of the components, see the 'Script' and 'Materials' sections.

Add the script

To enable terrain blending, the first thing you have to do is add the 'terrainBlendMapGenerator.cs' script to your terrain object. Simply select your terrain in the scene hierarchy and click 'Add Component' in the inspector, below the terrain settings. In the dialog that appears, search for 'TerrainBlendMapGenerator.cs' and add it. The script should now appear below the terrain components and display a warning that blend materials are missing.

adding the script

Create Materials

The blending only works with materials that use one of the included terrain blending shaders. To create one of these materials, go to the asset browser and create a new material. Now select this material and change the shader to a terrain blending shader (in 'Custom/TerrainMeshBlend/'). This shader has to match the terrain shader you are using. Default is standard.

You can also change the shader of an existing material to a terrain blending shader.

creating a blending material

Assign Blending Textures

Select the blending material and scroll down until you find the slot for 'Terrain Texture'. Click 'select' and select the texture of your terrain, with which this material should blend. If 'Automatic Texture Data' is enabled in the script settings (default), the script will automatically update texture position, size, normal map etc. So assigning the correct texture is all you have to do for now.

Assigning blending texture

Add Materials To The Blending List

In the next step, all materials, that should blend with this terrain have to be added to the 'Blend_Materials' list. Select the terrain and scroll down to the 'Blend_Materials' list of the 'TerrainBlendMapGenerator' component. Now you can simply drag and drop all materials, that should blend with this terrain into this list. The 'Materials Missing' warning should now disappear.

Alternatively, you could also change the 'Size' of that list and assign the elements by using the material fields.

Adding materials to the blending list

Apply Materials

All objects that should blend with the terrain have to use a terrain blending material.

You can either:

- change the objects material to a terrain blending material by changing the materials shader or

- drag and drop a terrain blending material onto your object in the 'scene' view

Now that your object is using a terrain blending material, it is ready for blending. To apply the blending effect, simply select the terrain again and click 'Reresh'. This automatically adjusts most settings, so that all blending materials from the list blend seamlessly.

Note: in some situations you have to adjust material settings manually. For more information, see the 'Materials' section.

Apply materials

If 'Show Messages' is enabled, the script will inform you about errors and what to do next.

Modify Blending

You can modify the blending effect of each blending material. Use 'Blend', 'Blend Offset' and 'Blend Gradient' to adjust the blending falloff.

For more information see the 'Materials' section.

Adjust blending effect
UP

The Script

To enable the terrain blending effect, the blending script has to be attached to a terrain object. This script is called'TerrainBlendMapGenerator.cs' and is located in 'Assets/Laxer assets/Terrain Mesh Blending/Scripts'. Drag and drop this script onto the terrain object or add it by using 'Add Component'.If the terrain is selected, this script will show you errors, warnings or instructions.

Properties:

Terrain Blending Script Component

Script: This is a field, that is used for the editor only. Do not change it.

Blendmap: The blendmap is a texture that stores all the height data of the terrain. The assigned blendmap will be updated automatically after painting the terrain or clicking 'Refresh'. This texture is stored in your 'Assets' folder.

BlendNormalMap: This texture is similar to the blendmap. The only difference is, that it stores the normals of the terrain surface.

Auto Refresh: If enabled, the blending data (blendmap + blendnormalmap) will be updated automatically after the terrains heightmap has changed. To apply all texture properties after modifications to the terrains textures, you have to click 'Refresh'.

Automatic Color Correction: If enabled, the 'Color Correction' field of all blending materials from the list will be updated automatically. This is used to adjust the brightness in 'linear' or 'gamma' rendering. The alpha value of 'Color Correction' is used for this purpose.

0 = gamma rendering, 1 = linear rendering.

Automatic Texture Data: If this is enabled, the script will automatically update position, size, normal map, metallic, smoothness etc. of the terrain textures, that are used by blend materials from the list.

This makes the setup of terrain blending materials easier, since you only have to assign the correct terrain texture to the 'Terrain Texture' slot of each material. All other data will be updated automatically after clicking 'Refresh'.

Show Messages: If this is enabled the script will show you errors, warning, hints or information, like in the screenshot.

Blend Materials: This is a list of all blending materials, that should be linked to this terrain. The script will automatically adjust the properties of these materials when clicking 'Refresh'. Materials that are not in this list will not blend properly. Add all blending materials for this terrain to this list. These materials have to use one of the included terrain blending shaders. For more information see the 'Materials' section.

REFRESH: Automatically refresh all blending data and materials associated with this terrain.

UP

Materials

Blending only works with materials that use one of the included blending shaders.These are:- Custom/TerrainMeshBlend/Standard- Custom/TerrainMeshBlend/Standard Overlay- Custom/TerrainMeshBlend/Full Standard- Custom/TerrainMeshBlend/Legacy Diffuse- Custom/TerrainMeshBlend/Legacy Diffuse Overlay- Custom/TerrainMeshBlend/Legacy Specular- Custom/TerrainMeshBlend/Legacy Specular Overlay(It is possible to create custom shaders. A tutorial is included in the README.pdf, deferred shaders are not supported)To change the shader of a material use the dropdown 'Shader' at the top of the materials settingsEach blending material can blend with one texture of a terrain. All materials that should blend with a terrain have to be assigned to a list called 'Blend_Materials'. This list is part of the 'TerrainBlendMapGenerator' component. This component will automatically adjust all blending settings when clicking 'Refresh'. For more information see the 'Script' section.

Object Properties:

This is an example of the standard terrain blending shader. The other shaders use similar properties.

Color: Default color of the object.

Albedo: Default texture of the object

Bump Map: Default normal map of the object

Smoothness: Default smoothness of the object

Metallic: Default metallic of the object.

Terrain Blending Properties:

Terrain texture: The terrain texture that this material should use for blending. The script needs this texture to automatically adjust all other settings. IMPORTANT! this has to be the exact same texture that the terrain is using (not a copy). Tiling and offset is handled also by the script.

Terrain Bump Map: The bump map of the terrain texture. The script can set this texture automatically.

Terrain Smoothness: 'Smoothness' of the terrain texture. The script can set this automatically.

Use Alpha Smoothness: This defines whether the 'terrain texture's alpha or a the 'Terrain Smoothness' value should be used as smoothness. 0 = fixed value, 1 = texture alpha.

The script can NOT set this value automatically!

Terrain Metallic: 'Metallic' of the terrain texture. The script can set this automatically.

Color Correction: If there is a visible edge between the object and the terrain, you can use this to optimize the blending. The alpha is used to adjust the color to either 'linear' or 'gamma' space and is set by the script.

Blend: The range of the blending effect in units. Use this to shrink or expand the blending effect.

Blend offset: The height offset of the blending effect. Use this to show more or less of the terrain texture.

Blend Gradient: Switch between linear or exponential blending gradient.

UP

Overlay Shaders

Overlay shaders are transparent overlays of the blending effect. These can be used on top of any shader.To use an overlay shader, create a material with one of the included overlay shaders. Then create a copy of the object you want to blend with the terrain (CTRL + D on Windows). Now you can use the overlay material for this copy to create the blending effect.

UP

Custom Shaders

This asset comes with a tutorial on how to create custom terrain blending shaders. This tutorial is not part of the online documentation and can be found in the 'Readme.pdf' file.Custom shaders can be easily created by copying shader code sections into other shaders. Deferred shaders are not supported. Terrain blending only works with shaders, that use forward rendering(This does not mean, that you can't have blending using deferred rendering. Only that blending materials - like transparent materials - will use the forward rendering path).

UP