Basic Terrain Setup

From Shader Forge Wiki
Jump to: navigation, search

This page describes the necessary steps to make your Shader Forge made shaders work with the Unity terrain.


Check List

Naming Convention

Dependency lines at the end of the shader (added manually by text editor)

SplatCount tag at the start of the shader (added manually by text editor)


Background Info

Terrain uses 2 or more shaders, depending on the number of paintable texture you put on the terrain. These are called:


FirstPass

AddPass

BaseMap


FirstPass is the default one, it is applied to all terrain tiles, within the range of Base Map Distance setting (set via Terrain Inspector). Other shaders are defined in this shader. AddPass is only required if you have more than 4 paintable textures. Usually, it is exactly the same as the FirstPass shader, however, you can do different modifications if you wish. BaseMap is applied to all terrain tiles above the Base Map Distance setting. This is a very simple shader that is designed to save performance. It gets its parameters from FirstPass and AddPass shaders.

Terrain script handles filling texture samples to the shader, so your shader needs to adhere to the naming convention. Terrain material will be based on FirstPass shader. Texture samples that have the Unity specific naming convention, will be overridden by the terrain script, any other textures that you setup should be added to the FirstPass material.


Texture Naming Convention

Diffuse texture sample names starts from Splat0 and goes up


Splat0

Splat1

Splat2

Splat3


Normal texture sample names starts from Normal0 and goes up (please note that normal maps won't work, see the unresolved issues section)


Normal0

Normal1

Normal2

Normal3


Splat map texture should be named Control.

You will need to create an empty texture sampler, called MainTex, and a color property called Color. MainTex will be filled inside BaseMap shader, and will act as a low res color map.


Example FirstPass basic diffuse chain setup:

Terrain-DiffuseSetup-FirstPass.png


Example FirstPass basic normal chain setup:

Terrain-NormalSetup-FirstPass.png


Example BaseMap basic diffuse setup:

Terrain-BaseMap-Setup.png


Adding Dependency and SplatCount tags

Dependency keyword should be added to end of the FirstPass shader, just before the Fallback keyword. Once you manually add these to the FirstPass shader, if you open it and compile again, it will delete the modifications. So you will need to modify the FirstPass shader after any adjustments.

Terrain-Dependency-Keyword.png



SplatCount should be added in the tags section of the FirstPass shader.

Terrain-SplatCount-Tag.png


Unresolved issues

Normal maps won't work, because the terrains do not have tangents. Need a way of calculating perturbed normals that point upwards.