|
Hello, 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? Best, Ates Akaydin
(comments are locked)
|
|
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. For example:
(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. Important Note: 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. That was really cool!
Mar 10 '10 at 12:09 PM
Lipis
Vote for this! Accept this! Make proper use of Unity Answers! Aaaaah!
Feb 21 '11 at 09:34 AM
taoa
This doesn't work for me... It just throws a blotched mess of paint, that has nothing to do with height. Any insight?
Jun 04 '11 at 04:13 PM
Flafla2
For me, the splat map was mirrored. Just change "terrainData.GetHeight(x,y)" to "terrainData.GetHeight(y,x)" and its all good
Jun 17 '11 at 07:57 PM
Precursor
How would you change the code to accomidate for more textures? I know more than 4 textures would require a new Lerp and Normalize function, but how can you implement Lerp for a "Vector" of > 4 dimensions?
Feb 23 at 11:43 AM
Dunlain
(comments are locked)
|
|
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.
(comments are locked)
|
