Sign in to follow this  
Brolo

Save HeightMap to file

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this