Search Unity

Import Heightmap HowTo or Tutorial

Discussion in 'Editor & General Support' started by amherst, Apr 17, 2009.

  1. amherst

    amherst

    Joined:
    Dec 9, 2008
    Posts:
    30
    Hey all,

    I'm trying to figure out how to import into Unity RAW heightmap files of real earth terrain that I have. I've been learning piece by piece from various posts and basic overall ideas on the documentation how to accomplish this but does anyone know of a tutorial or HowTo that explains it all completely?

    I'm using PhotoshopCS2 on a Mac.

    Specifically I'm trying to figure out:
    -How do the dimensions I use in Unity for "Terrain-->Set Resolution" relate to my image size, image resolution, etc. in Photoshop? It seems like my terrain resolution is too small b/c my peaks are very pointy, but my guessing method of choosing terrain size is not very scientific.
    -What difference does byte order make in exporting from Photoshop and importing into Unity?

    Here are two wonky terrains I imported:
    For the first one I'm thinking that the problem here is that my Unity terrain is too small. But how do I figure out the right values for Terrain width, height and length?



    The second terrain exhibits two problems I'm stumped on. The first is that the peaks are all quite pointy. I'm thinking this is because my terrain size values in Unity are too small but I can't figure out how to pick the right size. The image in Photoshop has pixel dimensions of 513x513 and resolution of 72pix/in:



    The second problem with this terrain is that it's actually importing flipped across the median x axis of the image. Also, what's low land dark in the photoshop image comes out white in Unity and vice versa.

    Photoshop image:



    Same terrain in Unity from top view:




    Any advice would be greatly appreciated! Thanks!
     

    Attached Files:

  2. jossiejojo

    jossiejojo

    Joined:
    May 24, 2009
    Posts:
    35
    Shame noones answered this question...I'm having similar troubles importing heightmaps and the reference guide doesnt explain any of this stuff... :cry:
     
  3. D-Wang

    D-Wang

    Joined:
    May 20, 2009
    Posts:
    3
    Hey,

    I just ran into these problems myself and manages to find a couple work arounds you can try.

    In Photoshop, make sure under Image > Mode you have it set to Greyscale and 16 bits/Channel

    When you save as a .raw, leave the byte order set to Mac.

    the flipped x axis can be fixed simply by mirroring your canvas horizontally in photoshop before you save it out.

    In Unity I set the width and Height to the dimensions of the map, so if your heightmap is 512x512, set the width and height values to 512, as well as the Terrain size X and Z values... the Y value is your height. Try lover values to eliminate your sharp peak problems.

    Hope some of this helps.
     
    Snas likes this.
  4. gabrielh

    gabrielh

    Joined:
    Feb 24, 2008
    Posts:
    51
    I don't know if this is really true, but from what I tried it seems that heightmaps have to be square and powers of 2 (e.g. 512x512). I had similar (and worse) problems trying with a 2904.8 x 3166.6 pixel image and once setting to 512 x 512 it was solved...
     
  5. jossiejojo

    jossiejojo

    Joined:
    May 24, 2009
    Posts:
    35
    I'm having the devils own job getting .raw files into unity...I wonder if its something to do with using a PC as you sound like youre using macs.

    Its hard enough finding software that will save 8bit raw files. My photoshop CS2 doesnt give the option.
    I bought fractscape and that does allow saving heightmaps as .raw files for unity but unity doesnt see the resulting files in the explorer and when it does import them they look very smoothed out and unreal.

    Its a bit of a nightmare really.

    I do think this is something that could be improved in future versions of Unity...

    I'm getting best results importing heightmaps into Bryce then saving as 3ds meshes - but you lose a lot of detail that way...
     
  6. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,146
    Any chance you could post the .raw file, what you see in Fractscape, and what you get in Unity? It should be identical, since Fractscape is in fact using Unity terrains (in "high detail" mode anyway; "low detail", which can only display up to 129x129, uses a standard mesh with no LOD).

    --Eric
     
  7. jossiejojo

    jossiejojo

    Joined:
    May 24, 2009
    Posts:
    35
    Hi Eric

    Ive spent a bit longer with Fractscape which is very good btw and got some better results

    Can you explain the best way to convert a png heightmap to a raw file using Fractscape in order to preserve the most detail??

    It would be good to check I'm doing it right and might help others
     
  8. Arcanor

    Arcanor

    Joined:
    Nov 4, 2009
    Posts:
    264
    I am also seeing this "flipped X axis" problem when importing RAW files created in L3DT. As a workaround I took the RAW file into Photoshop and re-saved it after flipping it vertically.

    I totally agree that the Unity documentation should really have an instruction page on this, as most projects using landscape terrains are likely to want to use imported RAW heightmaps.

    Hopefully the buggy RAW heightmap importer will be "un-flipped" in the next Unity release.
     
  9. RoyS

    RoyS

    Joined:
    Jan 12, 2009
    Posts:
    651
  10. spoof

    spoof

    Joined:
    Feb 14, 2010
    Posts:
    14
    Hi guys, just noticed the post, probably a bit late, i'm sure ye have all moved on from this, but for those future searchers, my method for making a heightmap in photoshop for unity which has never failed is:
    Set up document in Photoshop, grayscale, 300 pix/inch, 16bit, size of n^2 + 1 square(i.e. 513x513 or 1025x1025) this is different to other terrain generating software where the size is usually n^2 square. of course you can set the size to anything you want at this stage and just re-size before you save, often i will leave at some arbitrary large size because i will be importing some other image to use as a reference.
    Now that you have your document set up you can of course go ahead and place any other image you want in this document or just create your own from scratch.
    To explain what i mean, i have been using sketchup to create a terrain, from this i generate a heightmap with a .png extension, i do this by positioning my camera directly overhead (in parallel projection), the terrain model has a black to white gradient applied to it (how to do that is a whole different issue, too long to discuss here). Anyway with my camera positioned over the model, i save a 2D image of my view with .png extension.
    I place this into my photoshop document i set up earlier, re-size it to what i want, (has to be n^2 + 1) and save as photoshop RAW.

    Some problems i ran into at times was when i tried to make the heightmap a non square size, as in 257x513. The results were crazy. But what i did figure out was that you can still have a terrain which is 256x512 and import a heightmap which is 513x513(re-sized from 257x513) and it will look fine once you have imported it. :D
     
  11. dredawg

    dredawg

    Joined:
    Jun 6, 2010
    Posts:
    19
    The problem actually lies in the L3DT export options. If you click the options button next to the RAW filetype in the dialog box, you will see it defaults to a 'invert Y-Axis' set to true.

    I exported my Huge map split up as tiles and began refining a select few. I wasted a considerable amount of time working on a mirror image of my terrain map.