Heightmap (greyscale) export - another option

Started by Falcon, August 14, 2009, 08:59:23 am

Previous topic - Next topic

Falcon

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.

Matt

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.


Falcon

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.

Oshyan

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

kirk12

August 24, 2009, 09:19:02 am #5 Last Edit: August 24, 2009, 09:20:50 am by kirk12
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.

Falcon

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.

Oshyan

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

Hetzen

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.

domdib

September 16, 2009, 08:46:36 am #9 Last Edit: September 23, 2009, 10:34:35 am by domdib
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

Oshyan

That seems very odd actually. Can you share the TGD?

- Oshyan

domdib

I've posted it to you privately, as it contains some NWDA packs.

Oshyan

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

domdib

My apologies - I seem to have been mistaken about this problem. .TER files seem to export fine.

bac9-flcl

July 08, 2011, 02:07:46 pm #14 Last Edit: July 08, 2011, 02:09:49 pm by bac9-flcl
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?