Author Topic: Heightmap (greyscale) export - another option  (Read 28975 times)

Offline Oshyan

  • Planetside Staff
  • *
  • Posts: 12141
  • Holy snagging ducks!
Re: Heightmap (greyscale) export - another option
« Reply #30 on: August 14, 2012, 08:33:08 AM »
Glad to hear that you like TG's terrain generation functions. :)

You can adjust both the size of the area that is exported (in meters) and the resolution of the export by changing the corresponding values in the Heightfield Generate. The combination of the two essentially controls "points per area". The real problem is that standard heightfields and projections aren't really appropriate for representing complete planets. The most common approach would be to use polar projection to translate a spherical projection to a square image, but TG2 doesn't support that at this time. The only option I can think of to meet your needs would be to export individual large tiles. That would be tedious, but if you can find a reasonably large tile size that still exports properly it might not be too bad.

- Oshyan

Offline mavor

  • Member
  • *
  • Posts: 5
Re: Heightmap (greyscale) export - another option
« Reply #31 on: August 16, 2012, 06:16:14 AM »
Hey I was able to finally resolve my problems.

Here's how I was able to get a final output of .png heightmap files to use for my game project.

First, I generated the terrain + shaders of the planet. I used the planets pack as a starting point and then tweaked some things.

I attached a heightmap generator node to the end of my node chain, right before the data hit the planet object. I then generated a #### x #### sized heightmap from the shader data (set total size of sampled area to give me continent sized artifacts). I then generated the heightmap as a .exr.

I then downloaded and installed GDAL (http://www.gdal.org/) in preparation for the next step.

Using Photoshop, I opened up the .exr file and saved it as a 32-bit TIF file (I might be losing some height data from this... oh well).

Then, using GDAL's command line utility, I sectioned off my heightmap into 5 altitude "zones" (if you need more precision, you can splice it into more zones). I then used GDAL's "translate" utility to output my slices as .png files.

Example. gdal_translate -b 1 -scale 10000 15000 -of PNG "HeightTest.tif" ./pngOutput10k15k.png

Finally I was left with multiple .png images that, when taken together, contain a large (enough) portion of the .exr data for me to then use in my project. (tutorials and info on how to work with and extract .png pixel data are way more easier to find).

Now, i'm sure using the Open Exr source code there is a way to directly extract each 4 byte chunk of pixel data from the exr image and directly extract that data, but I couldn't find any tutorials or people who had a clue how to do so over the course of five days. Perhaps someone with better knowledge of C++ and such not could figure this out.

Hopefully this helps someone else interested in extracting terragen heightmap data and using it in some other project.

PS. Alpine fractals are really fun. :)
PPS. The ability to generate a heightmap with less precision would be nice..
« Last Edit: August 16, 2012, 07:29:57 AM by mavor »

Online bobbystahr

  • Member
  • *
  • Posts: 8915
  • Turn, and face the Strange Ch Ch Changes...D Bowie
Re: Heightmap (greyscale) export - another option
« Reply #32 on: August 16, 2012, 02:16:38 PM »
congrats...looks like you found a way...well done
something borrowed,
something Blue.
Ring out the Old.
Bring in the New

bobbystahr