Apr 26, 2017

Terrain Tutorial Part 2: Creating and Applying A Material To Your Terrain


First off I want to apologize for this second half of the tutorial both because it took me so long to get posted and because it is nothing like what I had intended.  My goal for this second half was to show you how to create a material that would randomly generate a terrain based on several textures that you would choose.  Sadly though I was faced with the bane of all programmers, the bug that by no logical reasoning should be there but yet still is.  Because of this I will be explaining something that has been explained thousands of times before.  The one upside to this is that while i was trying to create something new for you guys I did discover something else cool that I will be posting about within the next few days so you have that to look forward to.


First off open up the project we were using last time and create a new material.  For those who do not know this can be done in your content browser by right clicking and selecting Material.  Once this is done go ahead and open up your material so we get get started.  I will be using 3 textures in my material but you can use as many as you see fit.  Once you have your textures selected, import them into your project and drag them into your material and do the same for the texture normals if you have them.  Once this is done you should have something similar to this.

Once you have this complete go ahead and add something called a LandscapeLayerBlend.  This node allows you to have more than one texture per material which unless you want a single texture your entire level, you will be needing.  After adding this click on it and look at the Details tab.  In the section called Material Expression Landscape Layer Blend there should be a plus symbol.  Click this once for Each Doing this should change the node so that there is one input for each of your textures.  If you want you can also change the names in the node for each input in the section called Layer Name in the details tab.  After this duplicate the layer blend so that you have one for textures and one for normals and then plug them in.  Once thing you want to make sure of is that you have your textures and normals in the same order.  Next take the output from each of the nodes so and plug them into your material node so that the texture blend node is going into the Base Color and your normals are going into your normals.  This is the basic structure for your material.

This is the stage when you should give your material a test.  WARNING, unless you are running a rig with a fair amount of ram make sure to save BEFORE loading your material to the terrain as it may cause Unreal to crash.  As a rule of thumb you should save often when doing anything with terrain since rendering the changes takes a lot of power and has a chance to overload weaker computers.  With that warning out of the way we can continue.  Once attached to your terrain, go the modes tab and click on the Landscape section and from there click on Paint.  You should then see a section called Target Layers with what looks like three different materials in it.  They should be labeled what ever you labeled them as in your Landscape Layer Blend node.  Next to each one you should see the plus symbol.  Clicking this should give you two options.  If you used normals for your textures click on Weight-Blended Layer and if you did not use them select Non Weight-Blended Layer.  This should bring up something asking you to select a place to save the layer info.  You will need to repeat this for each texture you used in your material.  After this save again and paint a little of each of your textures near your character and try out the game.  This will give you a good idea of the tiling of each of your textures.

Chances are you are not happy with the tiling of your texture and here is where I explain how to fix that.  Go back into your Material and add a TextureCoordinate node.  If you look at this node in the Details tab you can change the UTiling and VTiling which is how you scale your texture.  You can create as many of these as you want so you can scale each texture seperately or give them all the same scale.  The smaller the number you change it to the bigger the tiling will be and the bigger the number, the smaller the tiling.  Since I am a sucker for detail I am going to create a node for each texture.  One thing to remember is to make sure you attach both the texture and its matching normal to the TexCoord node so that they are both scaled.  

Lastly, since this is a desert I think we should give our terrain a little roughness.  This is a very simple thing to do but can make your terrain look better by magnitudes.  All you have to do is create a Constant node and in the details tab, change its value to 0.7 or something of the like.  Feel free to experiment and find what you think looks good.  Once you set the value attach it to the Roughness input on your material node.  With that your terrain material is done, all that is left is for you to paint it on any way you see fit.

No comments :

Post a Comment