Planetside Software Forums

General => Terragen Discussion => Topic started by: Falcon on August 14, 2009, 08:59:23 AM

Title: Heightmap (greyscale) export - another option
Post by: Falcon on August 14, 2009, 08:59:23 AM
There have been various postings in this forum, none of which gave me what I needed, so I experimented myself.

The problem is: Export any terrain (not just a heightfield) as a heightmap image (i.e. a greyscale image with colour == altitude).

The solution I came up with, and which might be useful for someone else is this:
Use a Distance Shader.

Create two cameras. Both must have the same coordinates in X and Z. Set one (I call it "distance") to 0 in Y and rotate it 90/0/0. Set the other to some arbitrary high Y (higher than your terrain), like 5000 or so. Set this to orthographic and rotate it -90/0/0.

Now on your terrain shaders, add a Distance Shader. Use the "distance" cam as its point, and use Z (planar) as the method. Set the near and far distances so it works for your terrain (leaving near at 0 and setting far to the max displacement of your terrain seems to work fine).

This should give you a nice altitude-dependent shading, and if you render it (shadows off, sunlight off, atmosphere off) with the ortho camera, you get a heightmap at any point of your terrain you want, in any resolution you want.


I use this to have both a heightmap I can use in a 3D game engine and a beautiful TG2 render of the same terrain.
Title: Re: Heightmap (greyscale) export - another option
Post by: Matt on August 14, 2009, 05:50:52 PM
That's good advice. Thanks for sharing.

It's best to save as EXR if you can use that. The EXR data will be linear. But if you need to use an 8-bit format (e.g. BMP or TIF), make sure you set the following in your render settings: Gamma Correction 1, Contrast 0, Soft Clip Effect 0, and make sure camera exposure is 1. That will give you linear data in your 8-bit image.

Also disable atmosphere.

Matt
Title: Re: Heightmap (greyscale) export - another option
Post by: j meyer on August 15, 2009, 09:48:47 AM
Good advice indeed,thanks!
Title: Re: Heightmap (greyscale) export - another option
Post by: Falcon on August 23, 2009, 04:31:28 PM
After using this method several times:

Matt is correct, exporting as OpenEXR and then converting to 16bit RAW (the heightmap format my game engine of choice, Unity3D uses) gives the  best results. It also gives you some control during the 16bit conversion, especially the ability to stretch the heightmap out so it uses all available values, giving you the greatest contrast.

Also, unclamping the min and max colours is recommended, I got some weird min/max results without (perfectly flat stretches).

And yes, turn everything off that you don't require. Atmosphere especially.

I get great results with detail 0.8, AA set to 4. Didn't notice any difference when using higher values for either. Did some renders with detail 0.6 and did not liked them as much.
Title: Re: Heightmap (greyscale) export - another option
Post by: Oshyan on August 24, 2009, 04:40:30 AM
Couldn't you just feed your shader network into the Shader input of a Heightfield Generate, Generate, then Save File As (right-click the node in node network)?

- Oshyan
Title: Re: Heightmap (greyscale) export - another option
Post by: kirk12 on August 24, 2009, 09:19:02 AM
Output heightmaps is very essential task for me currently. I started to learn Terragen quite recently and not sure I understand it right. Could somebody who already tested it upload an example tgd file please.
Title: Re: Heightmap (greyscale) export - another option
Post by: Falcon on August 24, 2009, 05:42:00 PM
Quote from: Oshyan on August 24, 2009, 04:40:30 AM
Couldn't you just feed your shader network into the Shader input of a Heightfield Generate, Generate, then Save File As (right-click the node in node network)?

As I understand it, that would limit me to the heightfield's dimensions. Also, it would not allow me .exr output, which I've come to rather enjoy. Finally, since I also generate texture and vegetation distribution maps this way, this approach gives me identical output maps for all of these.

But yes, I figure that would also be possible if it's more useful for your case.
Title: Re: Heightmap (greyscale) export - another option
Post by: Oshyan on August 25, 2009, 01:00:27 AM
I believe you can actually save heightfields as EXR, or at the least as TER which is 16bit. You can convert to 16 bit TIFF from TER if need be. Also you can adjust the area and position from which the heightfield will be drawn. I would only suggest keeping with your method in your case because you are also doing texture, otherwise the method using a heightfield generator is easier and just as effective.

- Oshyan
Title: Re: Heightmap (greyscale) export - another option
Post by: Hetzen on August 25, 2009, 03:46:57 AM
I would have thought the .ter from the heightfield generate would be a lot more accurate, especially if you want to use the map in a 3D app to position objects accurately.

Also, it would be very easy to align your image projection up with the heightfield generate coordinates.
Title: Re: Heightmap (greyscale) export - another option
Post by: domdib on September 16, 2009, 08:46:36 AM
There is one problem with the option to export to TER discussed by Oshyan, which is that it suffers from holes in the terrain. It may be the heightfield I am trying to export is too complex (3 heightfield shaders followed by an Alpine), but unfortunately I see those tell-tale spots and streaks of absolute black in the exported heightfield that basically disfigure any possible render with ray traced shadows on - and in this case I need RTS on, as the scene relies on GI for its effect.

EDIT: I've checked, and the complexity doesn't seem to be the problem (except inasmuch as extreme displacements might be caused by an Alpine) Also, changing the resolution or saving to EXR instead makes no difference.


See below
Title: Re: Heightmap (greyscale) export - another option
Post by: Oshyan on September 17, 2009, 12:50:00 AM
That seems very odd actually. Can you share the TGD?

- Oshyan
Title: Re: Heightmap (greyscale) export - another option
Post by: domdib on September 17, 2009, 05:59:53 AM
I've posted it to you privately, as it contains some NWDA packs.
Title: Re: Heightmap (greyscale) export - another option
Post by: Oshyan on September 18, 2009, 01:42:26 AM
Alright, thanks. I'll continue via email then. If the resulting problem can be verified I will post about it here, with any solution that is also found.

- Oshyan
Title: Re: Heightmap (greyscale) export - another option
Post by: domdib on September 22, 2009, 05:10:15 PM
My apologies - I seem to have been mistaken about this problem. .TER files seem to export fine.
Title: Re: Heightmap (greyscale) export - another option
Post by: bac9-flcl on July 08, 2011, 02:07:46 PM
I apologize for bumping the old thread, but can anyone explain how to export terrain to any bitmap format? I've searched for documentation and tutorials (this thread was one of the links I was repeatedly pointed to) and unfortunately never found any clear explanation on how to do this. The only file format I've managed to save apart from .tgd is .ter (though I'm sure it's useless since the size of it is only 1kb). The only node related to export I've found is LWO, and I don't even know where to connect it. (

Would you kindly explain to me, which nodes I should connect or what tool I should find to export heightmap in any image format?
Title: Re: Heightmap (greyscale) export - another option
Post by: Henry Blewer on July 08, 2011, 04:12:42 PM
These were done by Walli. I have not viewed them in a while. I am 80% sure he covers how to export bitmap/tiff files for landscapes.

http://www.planetside.co.uk/content/view/58/27/
Title: Re: Heightmap (greyscale) export - another option
Post by: Oshyan on July 15, 2011, 07:52:20 PM
To export a heightfield, right-click a Heightfield Generate node in the Node Network view and choose Save File As. Give it a name with a TER or EXR extension. TER is the Terragen heightfield format, supported by many heightfield editors, and convertible to TIFF with TerraConv: http://koti.mbnet.fi/pkl/tg/TerraConv.htm
EXR is a high accuracy image format supported by many advanced image editors, e.g. Photoshop.

- Oshyan
Title: Re: Heightmap (greyscale) export - another option
Post by: Pyronious on June 09, 2012, 08:27:40 PM
Thanks Oshyan.

Just tested this in 2.4.32.1 and the TER export works fine and can be converted to TIFF using the tool you linked to.

However, EXR export appears broken in this release. Using the EXR method creates a solid white image.
Title: Re: Heightmap (greyscale) export - another option
Post by: Matt on June 09, 2012, 11:07:11 PM
The values in the exported EXR are heights in metres. This is so that there is an unambiguous mapping between elevation and pixel values, without any messy conversion settings. Some values might be negative; others might be greater than 1. However, many EXR image viewers will treat a pixel value of 1 as "white", which is reasonable enough, but that means you won't see most of the information that is in the file, even when it is there. You can make this information visible by adjusting the levels (if editing in 32-bit) or by importing into your image editor with a much lower exposure setting.

Matt
Title: Re: Heightmap (greyscale) export - another option
Post by: Pyronious on June 09, 2012, 11:12:57 PM
Thank you for the clarification. For future reference:
Thanks again.
Title: Re: Heightmap (greyscale) export - another option
Post by: bobbystahr on June 11, 2012, 11:44:07 AM
That was very helpful...I've just created some dispersal maps with that technique...thanks very much Matt and Pyronious
Title: Re: Heightmap (greyscale) export - another option
Post by: Wolfos on June 29, 2012, 01:45:38 PM
Sorry for bump, but I just get this solid gray render. No contrast at all.
Every program that can import Terragen maps is Windows only and Terragen only exports to the useless .ter format (which can be converted by, YOU'VE GUESSED IT! A WINDOWS ONLY APPLICATION!).

Why can't Terragen just export like all other programs? It's basically useless now when you want to do anything except for a render in Terragen. For Mac, there's only a single 'alternative', and that's the ancient Bryce (which probably doesn't work in later versions of OS-X anyway).
Title: Re: Heightmap (greyscale) export - another option
Post by: cyphyr on June 29, 2012, 01:58:39 PM
Right click on the Heightfield load or Heightfield generate and select "save file as", then choose .exr from the save as type dialogue. Exr files can be opened in Photoshop and converted to other formats easily. If the exr image you open up is all white or all black look at images>adjust>exposure (or levels) in photoshop.
Job done :)
Richard

Ah I should have read the previous replies,
You'll need to make sure the Heightfield generate is the last node in your terrain generation stack just before the compute terrain. You'll also need to position it over the area of interest.
Title: Re: Heightmap (greyscale) export - another option
Post by: mavor on August 14, 2012, 02:30:07 AM
Ok I got everything working... except I want to clamp the heightfield generator to just generate what's on my planet instead of an infinite heightmap. How do I do this? At every size I tested, I always end up with half-made continents on the edges of my heightmap (because it just keeps generating and generating)...

Any ideas? I want to push what is on my planet to a map.. nothing more nothing less :)
Title: Re: Heightmap (greyscale) export - another option
Post by: Oshyan on August 14, 2012, 02:39:00 AM
You cannot generate export an entire planet into any format at this time.

- Oshyan
Title: Re: Heightmap (greyscale) export - another option
Post by: mavor on August 14, 2012, 02:54:33 AM
Then is there any way to somehow clamp the heightmap generation to the size of the planet without getting the half-formed continent edges?
Title: Re: Heightmap (greyscale) export - another option
Post by: Oshyan on August 14, 2012, 03:00:43 AM
I'm not really clear what you mean. Heightfield generation is planar, I suspect it's not going to work well past a certain (large) size. What are you intending to use the output for? Even if it did work, you're looking at a tremendously large data set for any reasonable level of detail.

- Oshyan
Title: Re: Heightmap (greyscale) export - another option
Post by: mavor on August 14, 2012, 03:02:56 AM
I will use a 1/100th accuracy (or lower accuracy if required) version of a planet created using the procedural planet generation kit for a 2d tiles-based game i'm setting up. ;) Exact accuracy is not very important to me.
Title: Re: Heightmap (greyscale) export - another option
Post by: Oshyan on August 14, 2012, 03:25:00 AM
And you need it to cover an entire planet? Quite honestly it sounds like your needs *might* be better served by a dedicated heightfield modeler, particularly one with tiled output, for example World Machine or L3DT. I don't know exactly what the limitations of heightfield export are in TG, but I think you'll have a tough time getting the data that you want, unfortunately.

- Oshyan
Title: Re: Heightmap (greyscale) export - another option
Post by: mavor on August 14, 2012, 04:13:04 AM
Oshyan, it seems to me that terragen just has the better procedural generation tools.. L3DT and world machine are fine and dandy, but they don't have the believability of well-designed terragen continents/planets... :)

**Edit: Perhaps the ability to control how much height resolution for every given point there is would allow something like this to be more possible...
Title: Re: Heightmap (greyscale) export - another option
Post by: Oshyan on August 14, 2012, 04: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
Title: Re: Heightmap (greyscale) export - another option
Post by: mavor on August 16, 2012, 02: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..
Title: Re: Heightmap (greyscale) export - another option
Post by: bobbystahr on August 16, 2012, 10:16:38 AM
congrats...looks like you found a way...well done