Search Unity

How to create seamless terrain tiles

Discussion in 'Community Learning & Teaching' started by scrawk, Mar 21, 2013.

  1. scrawk

    scrawk

    Joined:
    Nov 22, 2012
    Posts:
    804
    Hi. Ive just uploaded a project on my blog that demonstrates how to create a series of Unity terrain that tile together seamlessly. The project uses a editor script to create a series of terrain from any number of RAW files containing the height data.

    You can find the link here.

    $shot19.jpg
     
    Last edited: Mar 21, 2013
    BerniceChua likes this.
  2. Andrew_atl

    Andrew_atl

    Joined:
    Sep 21, 2010
    Posts:
    103
    Awesome stuff, thanks man.
     
  3. Matro

    Matro

    Joined:
    Mar 15, 2013
    Posts:
    38
    Looks cool but I have been trying to test it with tiles generated from World Machine 2, but all get is "File is not the required size".
    Not sure about the settings in your script vs the settings in World Machine, for making tiles.

    Any help would be welcome.
     
  4. Matro

    Matro

    Joined:
    Mar 15, 2013
    Posts:
    38
    Ok I went to your blog and found your tutorial on how to made the tiles now I need to find a converter from png to RAW.
     
  5. scrawk

    scrawk

    Joined:
    Nov 22, 2012
    Posts:
    804
    Hi Matro. Never used world machine to make terrain tiles so not sure about what the out put from world machine is in this case. Im guessing it would be a series of RAW files. My script should work if this is the case. You just need to make sure that they are 16 bit not 8 bit RAW files. I have not added support for 8 bit files.

    You will get the "File is not required size" error if you try to use 8 bit files. You will also get this error if you dont set the height map res setting to the same size as you raw file.

    This script is rather basic for simplicity.

    I normally split my height maps myself using imageMagicK.

    To convert from png to RAW you can use photoshop if you have it or gimp which is free.

    If your still stuck and you files are not to large you can send me the height maps and I will have a look to see what the problem is. I can then send you back a Unity project file with the terrains tiles
     
    Last edited: Mar 25, 2013
  6. Viking1972

    Viking1972

    Joined:
    Jul 24, 2009
    Posts:
    74
    Very interesting reading

    I finally got a bit of knowledge about how to create terrain using multiple heightmaps - I had a real hard time finding this info.

    Would you make a video tut showing the whole creation process as I'm quite sure that many users would find it easier to understand.
     
  7. Matro

    Matro

    Joined:
    Mar 15, 2013
    Posts:
    38
    ok so I used ImageMagic to cut 1893 x 1893 image to 16 parts at 2049 x 2049 then found a script to use imagemagic to convert it to raw.

    @echo off

    set /p question= Enter Filename:
    if exist %question%.png GOTO NEXT1
    if not exist %question%.png echo Cant find file!

    :exit
    exit

    :NEXT1
    echo Starting to convert...
    convert.exe %question%.png -endian LSB -flip gray:%question%.raw
    if exist %question%.raw GOTO NEXT2
    if not exist %question%.raw echo Failed to convert!

    :exit
    exit

    :NEXT2
    echo %question%.raw has been successfully converted!
    pause
    exit

    What do I need to have my settings set to work?
     
  8. scrawk

    scrawk

    Joined:
    Nov 22, 2012
    Posts:
    804
    Viking - No plans for video tut atm.

    Matro - Nice work using imageMagicK for the convertion, didnt even know you could do that.

    For the settings to create your tiles you need

    TilesX - 4
    TilesZ - 4
    HeighMapRes - 2049
    byteOrder - windows

    The byte order is just a guess for the line 'endian LSB' in your post. You may need to try mac byte order if it doesnt work.
    The rest of the settings like, terrain width and height are really up to you but try

    Terrain width - 2048
    Terrain height - 600
    Terrain length - 2048

    Any settings I have missed out are stuff like detail map res and control map res. You will need to look up the unity manual to see what these do but you can leave as they are.

    Dont forget to set the folder location for your raw files and when you drag the initWorld script on to the world object to set the tilesX and tilesZ to 4
     
  9. scrawk

    scrawk

    Joined:
    Nov 22, 2012
    Posts:
    804
    Just had a close look at the raw file output from world machine. Forgot that world machines file extension is .r16 not .raw

    Ive updated the project to load these files as well. World machines byte order is windows (little endian) so make sure that is set correctly.

    If anyone comes across another 16 bit raw file extension let me know.
     
  10. Matro

    Matro

    Joined:
    Mar 15, 2013
    Posts:
    38
    Still having issues, yet to get to root cause, have you tested the windows byte as I am guessing you are on a Mac.

    As for the world machine .r16 just rename it to .raw the 16, I think is the bit size.

    Oh did you update the files for download or do I just need to add changes to code?
     
  11. scrawk

    scrawk

    Joined:
    Nov 22, 2012
    Posts:
    804
    Im on a windows pc. The byte order has nothing to do with what system your on, its to do with the way the data is encoded in the first place.
    Ive test both on my pc. The script worked fine.

    You can just rename the extension to .raw but Ive updated the project so it will load either .raw or .r16 files. There both the same format just different extensions.

    If you really want to get this sorted you need to send me one of the files so I can have a look to set what the issue is.

    Good luck.
     
  12. Frednaar

    Frednaar

    Joined:
    Apr 18, 2010
    Posts:
    153
    Scrawk,
    I just wanted to congratulate for your blog. One of the most interesting blogs on Unity.
    I have been checking Brunetons work for a long time and wanted to use it for a flight sim, I am glad you are porting it to Unity...

    Please keep on blogging!

    Fred
     
  13. monks

    monks

    Joined:
    Jul 8, 2013
    Posts:
    11
    Really useful this Scrawk! I'm having a bit of trouble downloading the project for this from your blog. The connection keeps timing out. What size are the tiles btw? I read they are 2049. Does Unity only work with 2^n(+1) terrain sizes?

    monks
     
  14. monks

    monks

    Joined:
    Jul 8, 2013
    Posts:
    11
    Hey Scrawk, I'm using your tiled terrain project to set up a world of 8 x 8 tiles. The tiles are 2049 px each, 2m per pixel.
    I changed your initialise world script to an 8 x 8 tile set. I've tried a couple of settings regards detail maps sizes and I've tried 2048 tiles too, but they always give me a line down the edge of tiles. To me, zooming in, it doesn't look as if there's a problem regards the heights, maybe it's a lighting issue. Do you know what causes that?
    I'm using World Machine. I've not set the tiles in World Machine so that adjacent edges share edge vertices in the tiled output options. Did you use that setting?

    $wip_63a.jpg

    monks
     
    Last edited: Aug 10, 2013
  15. scrawk

    scrawk

    Joined:
    Nov 22, 2012
    Posts:
    804
    Hi, Monks.

    Its a bit hard to tell with out looking at the project. Have you added the InitWorld script to the world gameobject ?

    Do you only see the seams in the editor and not in play mode? The InitWorld script sets the neighbours at run time so there will be seams when looking at the terrain from the editor.

    I did not use world machines tile feature. I just worked on a single height map and then split it into pieces with imageMagicK.

    The height maps in the project are 1025 px and the terrain tiles are 2048 m.

    In Unity the terrain size can be what ever you want but the height map res must be a pow2+1 number.
     
    Last edited: Aug 11, 2013
  16. Jiraiyah

    Jiraiyah

    Joined:
    Mar 4, 2013
    Posts:
    175
    Hi sir
    I'm planning on creating a terrain generating system but there is something I can't manage by myself at all simply because I have zero knowledge about it, I would like to use noise generation but, I prefer to have different type of noise generations on compute shader for fast usage, in your website, there is a project with different noise libraries in shaders, problem is, I don't understand shaders at all, I am sure many people would appreciate if there was a free asset library containing all of them in 2D,3D, and 4D in compute shader. Knowing you, writing those compute shaders are child play for you, something that I can't even dream of making single one of them. Can I beg you to develop this asset and share that with community (Perlin, Simplex, Voronoi, and Worley)????
    Thanks sir