1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Stuck, Having problems with creating your mod? Let us help you: Mod Support
  3. The ingame repository is currently offline for maintenance. Downloading and installing the mods manually via our website will still work: Repository
    Dismiss Notice

[Tutorial] Adding heightmap roads using blender

Discussion in 'Content Creation' started by LJFHutch, Oct 5, 2015.

  1. LJFHutch

    LJFHutch
    Expand Collapse
    Environment Artist
    Staff Member

    Joined:
    Aug 4, 2012
    Messages:
    645
    images_finishedterrain_road_view.jpg

    This guide will serve to explain the various components included in the zip file (if you are interested in trying this technique I strongly recommend opening up the .blend included, it's fully set up to render the roads out) and how the roads in this example were created. This method has some really nice advantages over others:


    • It's fast (lots of roads can be blocked out quickly)
    • You can preview the roads and drastically alter them without damaging your terrain as with traditional sculpting
    • You can easily add camber
    • You can give the roads curvature
    • The results will be silky smooth (the main road surface will be roughly as good as a basic mesh road)


    Setup of the .blend file


    There are some crucial things that go into making the whole thing work correctly:

    • In render settings you must set it to output 16bit, RGBA, .PNG
    • Render settings: disable anti-aliasing
    • Scene: disable rendering of the sky
    • Scene: disable colour management settings; gamma=1, display device=none, view=default, look=none, color space=linear
    • Your camera and terrain must be set up correctly
      • blender will render out the scene and normalize (lowest point will be black, highest will be white) it so you need to have a "range" object (in my scene I have constructed a ramp from 0m to the 120m - the extents of my terrain's heightmap) or it will create the resulting image in a way that the lowest road is at 0m and the highest 120m (or whatever your terrain is setup as) and your roads will be extremely wrong when placed over your original heightmap
      • ensure your terrain and it's UV map is positioned and rotated correctly
      • for best results make your terrain match exactly pixel to vertex to your source heightmap
      • make sure you select Z as the direction for your displace modifier and UV for texture coordinates as well as setting the strength so that your terrain is properly scaled in terms of it's height
    • The material of your roads and other elements in the render should be shadeless
    • The curves: in settings set Twisting to Z-up. This will make each point independent from each other (mostly).

    images_node_setup.jpg
    This shows the render node setup of the .blend file. This will be used to render out the heightmap.


    The spline roads


    The methods for creating the roads here are similar to what you'd do if you were making mesh roads, the difference is that we will be using them to form the heightmap.

    To begin with we are using bezier curves as the shaping guide for the roads combined with a mesh that will be arrayed along the curve and deformed so it's shape matches. Take a look at the modifiers used. One of the

    images_modifiers_setup.jpg
    Modifiers used to create the road

    images_splineroad_extruding.jpg
    A road is created by extruding control points in a bezier curve

    Components

    There are three components that go into creating the basic road shape:

    • A bezier curve: this is what we will use to control the road, a few control points and blender does the rest
    • A basic section of road acting as a master road (this will be linked to ("object data" link) and used by many roads across the map, so to change the roads we just edit this object)
    • A linked copy of the master road that will be used for the road itself

    images_road_elements.jpg
    This shows the elements of the road: orange is the master road, yellow is the bezier curve and black is the resulting mesh road object with modifiers applied

    components_explanation.jpg
    Here is a diagram showing the relationship

    Where you have intersections you can use a separate manual object to manually model over the joins to smooth them over.


    Exporting the heightmap


    This part can be as simple or as complex as you want it to be. Essentially you render only the layers with your roads on them and then export that out (disable the layer with the reference terrain on it).
    Optional: after exporting the heightmap you can delete the road edging from the objects and render again to get a mask of where the actual road surface is (the road object contains the road itself but also some side area that should be dirt or gravel).


    Combining the roads and the heightmap


    Open up your original heightmap in an image editor that supports 16bit images (I'm using a development version of Gimp but Photoshop works as well with a bit of tweaking the colour profiles). After that this is the process:

    • import your road export (“blender_roads_out.png”)
    • duplicate this layer twice, call each “blur minor” and “blur major” or something understandable
    • blur each layer by some amount (I used 2px for minor and 15px for major) and then copy and paste each onto itself about 4 times to get some more opacity in the layers

    images_combining_roads_and_terrains.jpg
    This shows how the roads are added to the terrain (the white layer is not used, simply used to show how the layers added affect the heightmap)

    Note for Photoshop users - Photoshop will always add an alpha channel to PNG files when saving them, even if it's not there. If you try to import one of those, you will end up with a flat terrain ingame.
    Before saving, flatted the image, then save your PNG. This way the PNG will be 'Greyscale' without Alpha and will be imported correctly.


    Editing the overlay map


    You will also want to editor your overlay texture so the changes made show up ingame. For this example I've just done this in a fairly simple way; imported the heightmap (blender_roads_out.png) and use it as a mask for some dirt colour and your heightmap area mask to put down asphalt colour.

    This image is of the “gimp_overlay.xcf” file that was used to edit the overlay image.


    Editing the material masks


    This can be done ingame but it can be faster and more accurate to do it beforehand.
    Since we're only adding one terrain layer this is pretty easy. We simply open up each of the other layers and add the area of the exported layer (blender_roads_asphalt_area_out.png) before saving it out again. Finally we do the opposite for the layer we're creating (gimp_material_asphalt_out.png). The thing to keep in mind here is that where there is white on one image there can be no white in any other image or you'll get conflicts.
    Our output layers are as follows:

    • gimp_material_asphalt_out.png
    • gimp_material_grass_out.png
    • gimp_material_rock_out.png

    images_material_editing.jpg
    This shows the rock material with the roads added as black (asphalt)


    End result


    images_finishedterrain_overlay.jpg
    This shows the finished result previewed in Blender

    images_finishedterrain_wireframe.jpg
    This shows the wireframe of the terrain

    images_finishedterrain_solid_road.jpg
    You can see the road has some curvature and camber.

    Source


    I have also attached the source files so you can use the .blend for your own projects and look at the other files such as the GIMP xcf files used to combine the roads and heightmap.
     

    Attached Files:

    #1 LJFHutch, Oct 5, 2015
    Last edited by a moderator: Aug 7, 2016
    CRAZY RACER, MxT333 and RyvyLo like this.
  2. KennyWah

    KennyWah
    Expand Collapse

    Joined:
    Jan 16, 2013
    Messages:
    2,108
    I'll need to take a look at this sometime.
     
  3. Aboroath

    Aboroath
    Expand Collapse

    Joined:
    Aug 25, 2013
    Messages:
    3,700
    Thank you!
     
  4. DoullPepper

    DoullPepper
    Expand Collapse

    Joined:
    Nov 15, 2014
    Messages:
    589
    Wouaaah! Humm for a first look, it is for people how have a good level in blender yet :confused: It is for the moment a chinese tutorial for me :p, but in studying it, maybe it will be clear!

    Thanks a lot to share your technics!:D
     
    ¿Carbohydration? likes this.
  5. Occam's Razer

    Occam's Razer
    Expand Collapse

    Joined:
    Aug 7, 2013
    Messages:
    717
    Hutch, this is a godsend. It aught to make smooth, flowing roads much simpler to build.

    One question: is it possible to build the entire landscape and road inside Blender, then render for import? I'm working on a few 'civilized' maps, ones that neither need nor can use terrain generating programs. When I attempt to export a full render of the landscape in your test file and immediately move it over to Torque, it comes out flat and, after vastly multiplying its height, jagged. Is there some modification I didn't notice made in GIMP?
     
  6. DerpSheep

    DerpSheep
    Expand Collapse

    Joined:
    Nov 22, 2014
    Messages:
    116
    Sticky please?
     
  7. LJFHutch

    LJFHutch
    Expand Collapse
    Environment Artist
    Staff Member

    Joined:
    Aug 4, 2012
    Messages:
    645
    Sort of, I've never had much luck making full terrains inside blender, though it's certainly possible. I think the biggest issue is the lack of tools for texturing the terrain and automating the process; I still haven't found anything that comes close to World Machine for making the base terrain.

    Ah yeah sorry, I should have written at the top; this is purely for adding roads to an existing terrain.
     
  8. DoullPepper

    DoullPepper
    Expand Collapse

    Joined:
    Nov 15, 2014
    Messages:
    589
    Hello!

    Excuse me for the noob blender question...

    I don't understand how to link the plane to the spline correctly. I have tryed some test and the plane never follow the spline. It is the "this will be linked" that I don't know how to do. :(

    Please can you explain a little for that?
     
  9. Occam's Razer

    Occam's Razer
    Expand Collapse

    Joined:
    Aug 7, 2013
    Messages:
    717
    In this context, 'linking' may be better referred to as 'parenting.' Select the object you'd like to deform, then while holding Shift, select the curve you'd like to deform it. Then hit Ctrl+P and select 'Curve Deform' from the popup menu.

    You may also want to select the curve, and in the properties window, select 'bounds clamp' and 'stretch.' You'll probably also want to set 'twisting' to 'Z-up.'
     
  10. DoullPepper

    DoullPepper
    Expand Collapse

    Joined:
    Nov 15, 2014
    Messages:
    589
    Ok it work but there was an another thing,it is stupid but my curve and my plane had'nt the same coordinate so it worked not :p
     
  11. LJFHutch

    LJFHutch
    Expand Collapse
    Environment Artist
    Staff Member

    Joined:
    Aug 4, 2012
    Messages:
    645
    This is done with modifiers, take a look at the included .blend file to see how they are set up. Basically there are two parts:

    • Array modifier: this duplicates the mesh for the length of "Fit Curve" (the spline/bezier curve you're using)
    • Curve modifier: this deforms the extruded mesh to fit the curve.

    I have updated the tutorial to explain this a little better.

    That is the correct way to do it. All of my roads and their bezier curves are at 0,0,0.
     
  12. Occam's Razer

    Occam's Razer
    Expand Collapse

    Joined:
    Aug 7, 2013
    Messages:
    717
    Just for a bit of clarification, what tweaking do Photoshop's color profiles need?
     
  13. ned228

    ned228
    Expand Collapse

    Joined:
    Jul 17, 2014
    Messages:
    243
    Hi I am trying to import the height map into blender and this happens. The terrain get all stretched out. This even happens even if I try to copy the settings of your blend file. in my own. Could you tell me how to get this to work.
     

    Attached Files:

    • Screenshot (8).png
  14. mtchll3

    mtchll3
    Expand Collapse

    Joined:
    Mar 31, 2014
    Messages:
    310
    After some playing around, I have managed to get the height map working and I started playing around with the road then I realized that if you take reasonably extreme a curves, up and around, it will rotate the road heaps. this is quite annoying. this is an awesome way of doing things, I think I'll do some more fiddling and see what i can make
     
  15. LJFHutch

    LJFHutch
    Expand Collapse
    Environment Artist
    Staff Member

    Joined:
    Aug 4, 2012
    Messages:
    645
    You need to make sure it's using linear colours, by default it'll use gamma correction and stuff and this distorts the heightmap pretty badly.

    Check the settings of the displacement modifier and compare it to the one in my file. It looks like it's set to too much. Alternatively it could be that your terrain is scaled too small.

    Select the curve and go to the curve settings and set Twisting to Z-up. This will make each point independent from each other (mostly).
     
  16. mtchll3

    mtchll3
    Expand Collapse

    Joined:
    Mar 31, 2014
    Messages:
    310
    There is one last problem I am having, the render in blender out put isn't the same as the input even after modifying brightness and contrast to try and make them the same, and when imported into torque 3d ends up being being like stairs, flat, slope flat, or is to boxy and not smooth.

    the one that appears to have less contrast is the output
     

    Attached Files:

    • newtest5out.png
    • test terrain4.png
  17. LJFHutch

    LJFHutch
    Expand Collapse
    Environment Artist
    Staff Member

    Joined:
    Aug 4, 2012
    Messages:
    645
    Sorry I missed your post: are you rendering out the entire terrain? It should still be ok but I would suggest only using the imported terrain for reference on where to put the roads, including them in the render ought to work but could result in a loss of information.

    As to why it isn't rendering properly that is a bit of a mystery. It may be because there is no longer a max/min height reference (if you look at the example scene I have a ramp that's about 1px wide on one side of the render) but a more likely explanation is that it's not set to linear colour. Make sure everything is either turned off or set to linear in the "scene" tab, if you aren't sure check your file against the example one on the OP.

    I hope this helps and sorry for the delay.
     
  18. mtchll3

    mtchll3
    Expand Collapse

    Joined:
    Mar 31, 2014
    Messages:
    310
    After playing around i had to modify the curve to be logarithmic or of the like to get a similar output, but even so, based on previous attempts, it seems like there's less colour like its 16 instead of 24 or something as it turns into a stair case when i import it and scale it to be the same height is the original.
     
  19. Dummiesman

    Dummiesman
    Expand Collapse

    Joined:
    Sep 16, 2013
    Messages:
    4,071
    Here is a Python script I created to assist users using image editors that don't support 16 bit image editing.

    Here are the changed steps:
    -Export only the roads portion of your heightmap from Blender as a Targa RAW B/W
    -Export your original heightmap as a 16 bit RAW file

    Call the Python script like so (NOTE: Requires Python 3):
    Code:
    python.exe heightmap_merge.py <your_RAW_file_name> <your_TGA_RAW_file_name> <size>
    Where RAW file name is your original RAW heightmap
    TGA RAW filename is the B/W Targa RAW of your roads exported from Blender
    Size is the size of the heightmap. e.g. 512, 1024, 2048

    Afterwards, upload "merged.raw" to http://danieljon.es/dummiesman/ , and replace the TER file within your terrain folder.
    Unfortunately, the only downside of this method is that you'll lose terrain materials.
     

    Attached Files:

    #19 Dummiesman, Apr 18, 2016
    Last edited: Apr 18, 2016
  20. LJFHutch

    LJFHutch
    Expand Collapse
    Environment Artist
    Staff Member

    Joined:
    Aug 4, 2012
    Messages:
    645
    It should be 16 bits (this might need to be set up inside blender though, make sure it's rendering 16 and also that you're saving a 16 bit .png), what did you do between exporting from blender and importing to beamng? Ensure that every time you edit it you're in a program set to 16 bit (current stable gimp can only use 8bit).