Bump mapping for built-in Unity terrain
This is a feature that a lot of Unity users gripe about, so I thought I would post our solution for it. In the .zip file (download below) you’ll find a shader replacement and a C# script for sending the bump maps to the shader.
To use it simply attach the C# script to your terrain object and add the shader replacement in your assets folder. You will probably need to restart Unity after this so that the shader replaces the built-in.
The script allows 4 bump map slots. These slots correspond respectively to up to 4 terrain textures. For each of these bump maps you also need to specify the tile size which should match the same as the terrain texture. You will also notice seperate specular levels for each texture.
It is fully integrated with Unity 3.0′s surface shaders so it reacts correctly with all lights, shadows, etc. It also exposes a means of sending textures and values to the built-in shaders, so let us know what you guys end up doing with this.
Note: The bump maps won’t affect the base map, so you’ll need to set the base map distance high.
Enjoy!







7 Comments on "Bump mapping for built-in Unity terrain"
quick question. Is a bump map the same as a normal map. and what is the spec value supposed to be?
Hi Pat – I tend to use these terms interchangeably since they do the same thing – add lighting detail that doesn’t exist in geometry. In this script, you should use a normal map and not a grayscale heightmap.
I also tend to group parallax and displacement mapping together since they do the same thing – add depth and shape detail that doesn’t exist in geometry.
The spec value is the specular lighting value – In the screenshot above the specular value is what makes the rocks look shiny. Hope this helps!
Is it possible to use 8 normals?
or is there a reason for the 4 limitation?
Im loving this btw its VERY! much lacking in Unity and Im still confounded as to why Unity haven’t sorted this out.
Yes, it is possible, but tricky. 4 textures are chosen because Unity uses 4 textures per pass. As soon as you use a 5th texture on your terrain, you get a second pass. Because of the way this effect has to be hacked into Unity, you would have to set up the shader to be able to differentiate between the first and second pass so it knows what bumpmaps to use. I would just keep grass and dirt textures non-bumped, and save the 4 bumps for rock or stone textures that need it most.
Of course – Unity could just build it in and we wouldn’t have to go hacking around!
hello, i can´t get it to run. it is not compatible with Unity 3.3.0?
regards.
something strange happened…i pressed the Play Button, and the terrains got Dark. i pressed Stop, and later, turn the Directional light, and now appears the Bump effect,but the lighting is wrong. it is full bright and lighted when the light is pointing horizontally instead to the floor :S
help please.
sorry, i had a mistake (i forgot to change the “Texture Type” in the Inspector to “Normalmap”).
THANKS YOU A LOT FOR THIS SHADER!!! IT IS A GREAT CONTRIBUTION!!
by the way, you can put the command “[ExecuteInEditMode]” before the line “public class CustomTerrainScript : MonoBehaviour {” , to execute the Script in Edit Mode too, in this way you don´t need to press Play to see the changes each time that you modify the Script.
i also put the lines (for each Spec variable, in the Update() Function):
if(Spec0<0)
Spec0=0;
to reset to zero the Spec value when it is negative (the texture appears Black in the terrain).
Regards!