I would like to render my terrain only with respect to the height values obtained from the height map via HSV Shading. Basically extreme heights will be rendered with brown color, medium heights with green and heights close to sea level will be rendered with blue. Inbetween values will be interpolated. My terrain is too big so I cannot simply paint it with textures(it will take weeks)
Is there a way I can achieve this in unity? I suppose there is no way we can specify shading for the built-in terrain object but rather we should be changing the built-in shader(possibly overwriting it) itself which affects terrain rendering...
Can anyone please explain how to do it in detail?
It sounds like what you really want to do is assign your splatmaps procedurally via scripting, which is entirely possible, although undocumented (and therefore not officially supported by Unity).
You'd need to assign one splatmap texture for each colour you require, then you need to create a c# script which does the procedural splatmapping.
First, make sure you have a reference to the terrainData object that your terrain is using. Eg:
The splatmap data is stored internally as a 3d array of floats, so to declare a new empty array ready for your custom splatmap data, do this:
The three dimensions represent X, Y, and Texture Index (of the textures assigned for terrain painting). X and Y are normalised terrain coordinates, going from 0-1. The value in the 3rd dimension is a "weight" indicating how much of that particular texture is blended in at that particular location on the splat map. The sum of the weights for every texture for any single X,Y value should add up to 1.
You would then want to fill that array with values based on the height reading at each point.
(The splat map is referred to as the 'alphamap' in unity. The terms are interchangable)
The code above makes the blend between the 3 textures over the entire possible height of the terrain. You'd need to change the code if you want the blend to occur over a different range within your height values.
Some of these functions are undocumented. Any future updates of the unity engine might change or remove these functions from the API. This means your project may not work in future versions of the Unity editor, and webplayer builds may not work with future versions of the plugin.
There's an extension in the unity resources called Terrain Toolkit that will do exactly what you're talking about. It worked in Unity 2.x; I haven't yet tried it in Unity 3 yet.
answered Oct 04 '10 at 12:45 AM