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

Offline Falcon

  • Member
  • *
  • Posts: 144
Heightmap (greyscale) export - another option
« on: August 14, 2009, 12:59:23 PM »
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.

Offline Matt

  • Planetside Staff
  • *
  • Posts: 3100
  • I'm the crazy one
Re: Heightmap (greyscale) export - another option
« Reply #1 on: August 14, 2009, 09: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
Just because milk is white doesn't mean that clouds are made of milk.

Offline j meyer

  • Member
  • *
  • Posts: 2098
    • orkwarts
Re: Heightmap (greyscale) export - another option
« Reply #2 on: August 15, 2009, 01:48:47 PM »
Good advice indeed,thanks!

Offline Falcon

  • Member
  • *
  • Posts: 144
Re: Heightmap (greyscale) export - another option
« Reply #3 on: August 23, 2009, 08: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.

Offline Oshyan

  • Planetside Staff
  • *
  • Posts: 12264
  • Holy snagging ducks!
Re: Heightmap (greyscale) export - another option
« Reply #4 on: August 24, 2009, 08: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

Offline kirk12

  • Member
  • *
  • Posts: 13
Re: Heightmap (greyscale) export - another option
« Reply #5 on: August 24, 2009, 01:19:02 PM »
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.
« Last Edit: August 24, 2009, 01:20:50 PM by kirk12 »

Offline Falcon

  • Member
  • *
  • Posts: 144
Re: Heightmap (greyscale) export - another option
« Reply #6 on: August 24, 2009, 09:42:00 PM »
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.

Offline Oshyan

  • Planetside Staff
  • *
  • Posts: 12264
  • Holy snagging ducks!
Re: Heightmap (greyscale) export - another option
« Reply #7 on: August 25, 2009, 05: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

Offline Hetzen

  • Terragen Alpha Tester (Win)
  • ***
  • Posts: 1617
Re: Heightmap (greyscale) export - another option
« Reply #8 on: August 25, 2009, 07: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.

Offline domdib

  • Member
  • *
  • Posts: 1777
Re: Heightmap (greyscale) export - another option
« Reply #9 on: September 16, 2009, 12:46:36 PM »
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
« Last Edit: September 23, 2009, 02:34:35 PM by domdib »

Offline Oshyan

  • Planetside Staff
  • *
  • Posts: 12264
  • Holy snagging ducks!
Re: Heightmap (greyscale) export - another option
« Reply #10 on: September 17, 2009, 04:50:00 AM »
That seems very odd actually. Can you share the TGD?

- Oshyan

Offline domdib

  • Member
  • *
  • Posts: 1777
Re: Heightmap (greyscale) export - another option
« Reply #11 on: September 17, 2009, 09:59:53 AM »
I've posted it to you privately, as it contains some NWDA packs.

Offline Oshyan

  • Planetside Staff
  • *
  • Posts: 12264
  • Holy snagging ducks!
Re: Heightmap (greyscale) export - another option
« Reply #12 on: September 18, 2009, 05: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

Offline domdib

  • Member
  • *
  • Posts: 1777
Re: Heightmap (greyscale) export - another option
« Reply #13 on: September 22, 2009, 09:10:15 PM »
My apologies - I seem to have been mistaken about this problem. .TER files seem to export fine.

Offline bac9-flcl

  • Member
  • *
  • Posts: 1
Re: Heightmap (greyscale) export - another option
« Reply #14 on: July 08, 2011, 06: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?
« Last Edit: July 08, 2011, 06:09:49 PM by bac9-flcl »