Save HeightMap to file

Started by
1 comment, last by meeshoo 13 years, 4 months ago
Hi all!

I need to save a procedurally generated heightmap (stored as float[]) to grayscale texture. I'm currently using the Texture2D.SetData<> method, Color format for texture and clamping array values to float.MinValue, float.MaxValue... but this give me weird results.

Thanks a lot!
Advertisement
I answer myself:

It's simply.

Since pixels from texture gets values between 0 and 255 for rgba channels, transposing the height values to [0, 255] is enought to construct the gray Color (r = g = b ) wanted to set texture data.

Cheers
255 levels of height won't cut it in all circumstances. You might want more, and that means using 16 bit instead of 8 for representing them. That really should be enough for anything you can imagine game related. The way you encode it in the file it depends. Personally, I would just have a file with 16 bpp, but if you want to stick with your channels you can store the major byte in red channel and the minor one in the green channel, or really any other combinations would work.

This topic is closed to new replies.

Advertisement