Scripted unity terrain question

Is it posible to use a texture2D as heightmap for the unity terrain or it is mandatory to be formated as .raw?

Isn’t it posible to get the color.grayscale range and use it to build the heights array?

If possible, wich image format would be best?

Thanks, Gabriel.

Yes, but you won’t be able to use 16-bit height resolution. http://wiki.unity3d.com/index.php?title=HeightmapFromTexture

–Eric

Ah, so it is possible trough your import script only. Am i right? So in order to use my texture first i have to somehow modify your script so i can pass the texture as parameter from C# get the height information from it and then apply to the terrain tile currently beeing processed…

I never used C# before, is it posible to comunicate with javascript?

Not sure why you’re talking about C# when the script is JS. Also you don’t need to modify it; it works fine as-is (aside from the 8-bit limitation).

–Eric

Sorry, i read the info in the file and i interpreted that you run the script in the editor (so i guess that it works on a terrain that is allready in the scene?). I’m writing a “sort” of procedural terrain generator based in a set of color maps and since i didn’t want to go deeper into vertex and triangles and that GPU stuff that is over my head, i decided to use unity terrain engine insted. I feel more confortable with it. I’m writing that code in C# basically because i was kinda lost on how the data arrays were used to generate the terrain data, so i just used some C# code i found on the net as a point of start to figure out how the terrain engine works.
But if C# can comunicate with JS i could call a method in your script to setup the heightmap for each terrain tile inside the current C# code. Or i could re write it in Js.

What do you think?

If you have control over the terrain generation then you can just use a float array directly. All you need is a 2D array of floats (where 0.0 is the lowest point and 1.0 is the highest point), which you use with SetHeights. If you already know JS then you should just write everything in JS rather than trying to combine different languages.

–Eric

Just to make sure i understand correctly… If i read a normalized value of the texture color (i guess that would be with GetPixel) as a grayscale. Where 255 color value will be 1 normalized. So then i use that number to set a % of the terrain height size?