Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon
12. January 2016

 

In Part One of our level creation in Blender tutorial series, we created a skybox to define the boundaries of our game level.  In this tutorial we are going to create the terrain for our level.  You will probably be surprised by just how much we can accomplish with almost zero effort.

 

Creating a Height Map

First we need a height map.  A height map is a remarkably simple concept that has been around for ages.  Essentially you are defining the height of a grid of terrain using a simple gray scale image.  You can create this image a couple of different ways.  First you can simply fire up any image editor, even MS Paint, and draw the texture.  The blacker the pixels, the lower the corresponding terrain, while a white pixel is as high as possible.  In addition to painting by hand there are several applications free and commercial that are capable of exporting a height map for you.  Examples include Terragen, Bryce and Geovox although there are many more.

 

For this example I’m simply going to use Paint.Net, but any image editing program would work fine.  Create a new image, while not a requirement, power of 2 ( 512x512, 1024x512, etc ) textures generally perform best.  Next set the base colour to 128/128/128 RBG, like so:

image 

Use the bucket fill tool to fill the entire image with this color.  This will be the neutral value, the resulting terrain will neither be elevated nor depressed.

 

You can then vary the grayscale by either raising/lowering all RGB values ( aka 43,43,43 or 250,250,250 ) or by sliding the V slider under HSV.  Remember, darker the colour, lower the terrain, lighter the colour, higher the terrain. 

 

In the end, I painted this rather simplistic height map.

heightmap

 

This will result in a high border around a pit of utter and complete dispair... muhahahaha.

 

Displacement in Blender

 

Now that we have a height map, it’s time to put it to use.  The good news is, this process is remarkably simple.  First we need something to apply the height map.  A height map needs an underlying mesh to apply to and if there aren’t sufficient vertices to be displaced by the height map, your results aren’t going to be very good.  This means we need a large flat surface with a decent amount of detail...  We need a plane.

I’m building on our scene from Part 1.  Set the 3d cursor to the origin, then create a new Plane via Add->Mesh->Plane.

image

 

Your scene should now look something like this:

image

 

Now we simply want to scale the Plane to the appropriate size, which is going to be entirely dependent on your skybox dimensions.  I personally scaled by a factor of 10.  After scaling it, we need to add details.  To do so, in edit mode, simply apply a subdivision (W->Subdivide)

image

 

Each time you perform this, you will double the mesh density.  I preformed it about a half a dozen times, resulting in a mesh with 32K triangles, which seems about appropriate.

image

While you are here you might as well UV unwrap your plane (U->U).  Also switch to Smooth shading:

image

Or your terrain is going to look VERY edgy and not at all organic.

 

Ok, now that we have our plane to deform, we need to load in our height map.  It doesn’t really matter where you add the texture, but I will go ahead and attach it to our plane.  Switch over to the textures tab, add a new image texture and load our heightmap.  It might make sense to rename it heightmap so it doesn’t get confusing, but you don’t have to:

image

 

Don’t bother setting UV coordinates, we aren’t going to be displaying this texture.

 

Now, in Object mode, with your Plane selected add a Displace modifier:

image

 

Now select your image in the texture field, change Texture Coordinates to UV, then select the UVMap.  If you don’t have the option, you didn’t UV Unwrap earlier!

image

 

Our height map will now be applied to our terrain:

image

 

Now we can use the Strength value of the Displace modifier to determine the strength of the height map on the displacement:

HeightMapInBlender

 

The Video

 

Back To Part One  ||  On To Part Three

Art Design


12. January 2016

 

This tutorial covers the basics of creating game levels in Blender.  There are a set of companion videos on YouTube that cover the same topics.  We will be looking first at creating a skybox to define the boundaries and skyline of our game.  Next we create the terrain of the game using a displacement map and a height map texture.  Finally we show how to paint the terrain using multiple textures.  I assume you have prior experience using Blender.  If you do not, this text based or this video based Blender tutorial series will teach you everything you need to know to follow along here.

 

Creating a Skybox

A skybox is pretty much exactly what it sounds like, a box flipped inside out with a 360 degree sky texture applied to it.  That said, it is quite common to remove one side of the box (the floor) as it is generally never seen.   There are two approaches to the texture map used to texture the inside of the skybox.  First we can use a single texture in the shape of a lower case T.  Or we can use a separate texture for each face of the box.  The advantages of the first approach are a) it’s easier b) it uses less texture memory.  The advantage of the second approach is much higher quality textures.  We will take the first approach in this example, but if there is enough demand I can do a tutorial covering the second method.

 

So first we need a skybox texture or textures.  Generally theses are a sequence of seamless textures representing the front, back, left, right, top and optionally bottom textures in the scene.  For this example I am actually using a cool procedural galaxy skybox generator available here.  Play with the random seed until you get a value you like.  To have it generate a t-shaped texture, make sure that Unified Texture is selected:

image

 

The end result I am working with looks like this:

skybox

 

Ok, now that we have our skybox texture, let’s fire up Blender.  The default scene is surprisingly EXACTLY what we want.  All we need is a simple cube, like so:

image

 

With the cube selected, switch into Edit mode and in the tools (T) panel select Shading/UVs then Flip Direction.

image

This reverses the normals of each face in our cube, effectively turning it inside out.

 

Now we need to mark edges to unwrap the UVs.  Switch to Edge select mode and select the following edges:

image

 

Then, still under Shading/UVs, click the Mark Seam button.

image

 

Next select the entire object (A) then click Unwrap.  In the UV/Image Editor, it should look like:

image

 

Perfect, now we just need to import our texture.  In the Material tab of the Properties panel, we first want to enable Shadeless:

image

 

Shadeless prevents the lighting of the scene from interacting with the material, which for a skybox is exactly what we want, otherwise it would be far too dark and unevenly lit.

Now switch over to the textures tab, add an image texture, load our generated skybox texture, then make sure mapping is set to UV, like so:

image

 

In the UV Image editor, with all of the faces of our cube still selected, make our texture active, then using a combination of rotation and scaling, align the UVs to the texture map:

image

 

That’s it, your skybox is now complete.  Of course you probably want to scale it up to a huge size so it envelops your entire scene.

image

 

If you have any unsightly seams, your UV maps is probably off the texture ever so slightly.

 

The Video Version


 

On To Part Two – Terrain

Art Design


4. January 2016

 

I was recently working with a tool that exported it’s level data as a directory full of obj files, literally hundreds of them.  You can import them into Blender using File->Import->Obj, unfortunately there is no way to do a select all.  Apparently in Blender 2.4x if you held SHIFT while selecting OBJ import, it would import an entire directory, but this doesn’t appear to work in modern Blender.  You can also SHIFT+Click multiple files to do multiple selection, but this gets tedious when you have hundreds of them.  Unfortunately CTRL + A doesn’t work…

 

Thankfully Blender is extremely scriptable, so let’s turn to Python for a solution.  The following script will import a directory full of OBJ files into the current scene.

import bpy
import os

def fileList(path): 
    for dirpath, dirnames, filenames in os.walk(path):
        for filename in filenames:
            yield os.path.join(dirpath, filename)

for f in fileList("C:\\file\\path\\here\\"):
    if f.lower().endswith(".obj"):
        bpy.ops.import_scene.obj(f)


Be sure to change the path to your directory and if on Mac OS or Linux, to change the path format /to/this/style. Otherwise this script will chug away importing the OBJ files for you. Hopefully at some point Blender gives you the ability to select all while importing and the need for this script goes away completely.

Art Programming


17. December 2015

 

One of the major weak points for Blender, especially for game developers, is it’s FBX support.  You see, Blender is GPL licensed, which among other things means it can’t link to closed source libraries.  On the other hand, FBX is pretty much the industry standard interchange format these days, but it’s owned by Autodesk.  Autodesk have made an SDK available for years, but due to the GPL, Blender can’t use it.  This means their FBX implementation is a clean room reverse engineering of the format… and this results in… issues.

 

Thankfully, if you are like me and don’t give a damn about the GPL, there is a great option available.  There is a Blender add-on available that makes use of the Autodesk FBX SDK.  The install process is a bit non-intuitive though.

 

First download UmComv, this is a version of the Autodesk FBX SDK compiled for you.  Inside the archive, copy the folder umconv to the root of your Blender directory (same folder as the Blender executable).

 

Next download the addon zip file available here.  Extract the contents of this zip file somewhere, the file you care most about is io_scene_bos_fbx.zip.

 

Next in Blender, go to User Preferences…  Add-Ons and select Install From File…

image

 

In the resulting dialog box, locate and select io_scene_bos_fbx.zip.  Next locate the newly added add-on and make sure it’s enabled:

image

 

Now you will have additional import and export options available in Blender:

image

 

There may still be times where you want to use the built in FBX importer/exporter, but this certainly gives you more options and I have found does a MUCH better job supporting animation and other features.

Art


15. December 2015

 

Via BlenderNation a great collection of Blender materials came to my attention and I figured I would share.  Blender user Mackraken is a bit of a hoarder of materials and this certainly works to our advantage!  He has made a complete collection of shaders available for our use, all nicely organized using matlib.

 

To install, if you haven't already got git installed, install git and make sure it is available in your path.  Next in a terminal/command prompt, change directory to your Blender’s addon folder.  On my system it was D:\Program Files\Blender Foundation\Blender\2.76\scripts\addons

 

Next run the command:

git clone https://github.com/meta-androcto/materials_library.git

 

Now load up Blender.  Go to User Preferences…

image

 

Switch to the Add-ons tab, search for “mate”, click the enabled check box for the entry Material: Material Library Cycles, then click Save User Settings if you wish this setting to persist the next time you load Blender.

image

 

The materials will now be available.  First make sure the Cycles renderer is selected:

image

 

Pick an object you wish to apply a texture to and navigate to the Materials tab:

image

 

If the plug-in install worked properly, you should now have a new field named Material Library VX available:

image

 

In the dropdown, select the category of material you want:

image

 

Next select the actual material you want, then click the indicated icon to make that material active:

image

 

Tada:

image

 

Now keep in mind that Cycles materials will NOT export correctly to any game engines.  Instead you will have to bake your textures for use in real-time.  Don’t worry though, I already got you covered there!

 

Here is a video of the entire process.  Thanks to Mackraken for sharing the results of his hoarding nature!

Art


GFS On YouTube

See More Tutorials on DevGa.me!

Month List