figure metadesc_logo_32.png
Imporved Road Material for Unity Game Engine.
THIS IS A ROAD MATERIAL, WHICH CONTAINS “I, L, X, T” FORMS AND IS BASED ON CUSTOM SHADER AND ON SUBSTANCE DESIGNER 5 CREATED MATERIAL. MAINLY THE ATTRIBUTES OF THE SHADER AND THE MATERIAL WILL BE DESCRIBED IN THIS DOCUMENTATION.
Last changed: SEP, 2016
Company: metadesc, Helmut Kleber
Author: M. Sc. Dipl. Ing. Helmut Kleber


Table of Contents


List of Figures


1 Introduction

This road material is a high quality road material, which blends in the terrain texture. The material is based on a custom shader, made in Shader Forge, and the road texture is made in Substance Designer. In the Substance Designer project are no textures externally linked to the project, it just contains noises, patterns, which are inside of this tool. That means, from my side it is fully procedural, but I don’t know how the noises and pattern are built in Substance Designer. The shader and the Substance Designer 5 project is included in this asset, so you can make your changes, if you want.
Configuring the road shader attributes and the Substance Designer material attributes can be time consuming, depends on, what you changes. Changing the road dirt textures to snow needs small changes, but changing the side dirt blending or changing the shader or the Substance Designer material can take much more time.
6 shaders available:
The best detailed, shader noise based, road shader contains 1 color texture, 2 dirt textures (on the side and on the entire road), 1 normal map, 1 side dirt normal map, 1 AO map. The lowest detailed road contains 1 color map and 1 dirt map, where the side dirt and the dirt on the road is the same texture. The optimal road shader have 1 color texture, 1 normal map, 2 dirt textures (on the side and on the road). The texture noise based shaders requires one additional texture for the noise (side noise).


2 How to use it

For the roads the Unity plane mesh were used. Drop the preconfigured prefab in your scene, the dirt must mach together on the ends of the road segments to have a good result. It can still happen, that there will be color intensity differences between the parts. To connect the road segments select the road segment in the scene and type v and use a vertice on the end of the road and drag and drop it to the another road segments end. There can be still a gap between the two segments, in this case you have to manually move the end of the road.
I support X, L, T connections, but they are not the best looking ones. I recommend you to use a spline asset, one that is good for road creation on terrain, so the mesh adapts the terrain and the road and rotation stays stable. My lovely spline tool asset (SplineBlend) is depricaded and so it is not available in the asset store. If you have this spline tool, then you are lucky. I would recommend you to create the L connection with a spline tool instead using the built in variant.
How to adapt the road for your terrain?
I recommend you to use for dirt based road materials the most common terrain textures. After this you can set the road color and then you can set the side dirt blending, blending strenght and color. To choose the right side dirt color was very time consuming for me. After this you can play around with another values (strenght of dirt and dirt opacity strenght from 4 different sides, and more), but then you have to synchronize the T, X, L connection too, and this takes time.
So at all, I didn’t found any good looking road solutions in the asset store, not even for my upcoming strategy game, so I had have to do this one.


3 Principles

The asset contains six different shaders. Three shaders for shader noise based fading at the side and three for texture based fading on the side. Each shader groups are then separated by quality, which can be detailed, optimal or simple. To explain what the shader attributes do, the most detailed shader were selected. The another shader have less attributes, but the attributes have the same impact. The textures were made by the procedural texture generator.

3.1 Road Shader Attributes

The detailed texture based niose shader has seven textures:
To have a better blending on the ground, the side has its own dirt texture and normal map. Additionally the AO map also have a small impact on the side blending. I used the same textures, because of licensing issues, sure is, I can use the Unity standard textures.
The Texture Based Side Noise is under 50% color intensity not visible, above visible. Shader Forge does not allow the transparency for Unity forward based shader, but it allows the opacity mask. That means, the shader is able to switch off or switch on a pixel, but cannot blend between. If you have too dark noise, then you switch off the most pixels and if you have a too bright color, then you see too much pixels. The blending to the ground with opacity mask is still good, and I experienced that it brings better results than blending over the transparency.
figure Shader1.jpg
Figure 2 Shader Textures
There are a lot of shader properties, but there are preconfigured materials in the package, which shows you working configurations. To create another configuration is not simple and needs time. This part gives you an overview to be able to configure your own type of material. Obvious attributes were not explained.
Side Opacity: This defines how far the road is visible on the sides.
Side Noise Intensity: Defines the noise strenght. A higher value can make the road on the side wider and a lower value makes the noise stronger. Side Opacity and Side Noise Intensity should be adjusted together for the side noise.
Center Dirt Intensity: The intensity of the dirt color on the road.
Rotate Side Dirt: Important if you want a direction based dirt, like 90 degree waved sand on the road sides in the desert.
figure SideDirt.jpg
Figure 3 Rotated Side Dirt
Start Blend: Just active, if BlendEndOff has not been activated. Blends the U cord. beginning. It can be used to make the rood one side wider or tighter. EndBlendStrenght sets the intensity of this effect. AddRoadBlend makes the whole end form smaller or bigger. These three attributes should be adjusted together.
EndBlendSwitch: End blending can be swiched to one of the both ends of the road.
BlendEndOff: Switch the end blending on or off.
Dirt1Rot: Rotation of the first dirt.
Dirt1Strenght: Strenght of the first dirt, how far/strong the dirt should blend on the road from the Dirt1Rot angle.
Trans1Rot: Rotation of the road transparency blending.
Trans1Fade: The higher the value the more road will be faded yout from the Trans1Rot angle.
The shader has 4 directional based dirt and road visibility blendings. These were used for corner of the X, T, L roads.
figure Shader2.jpg
Figure 4 Shader Attributes


One of the road shader graphs in Shader Forge.
figure SFProject.jpg
Figure 5 Shader in Shader Forge


3.2 Procedural Road Texture Attributes

The next picture shows the procedural texture generator attributes. The procedural textures were designed in Substance Designer 5.4, which is available for you. One of the interesting attribute is the seed based randomization. This allows you to roll your road and set the same seed key on the another procedural road textures for I, L, T, X forms. Important to know, L, T, X road segments has no center road separation line and side lines!
The first Size: X scales an invisible rectangle from the center of the road to the outside, which fades out the side lines. Value 1 fully fades out the side line. In case of 0, the center line will be a solid line too. Y nearly no impact, but in case of X is 0, it fades out the line in U coord. direction.
Track Strenght: Defines the strenght of the black tracks on the road. In real life, the bright roads have a black color on the tire trace and on the dark roads this is the part between the tire traces. You can set this behavior by set the tileing number with the Track_Tiling attribute.
The second Size: X blends out the black track from the side to the center. Normaly used to do not have this black trace on the dirt. Y fades out the track from the side. It makes the black track effect more weaker, neraly invisible.
Road_Spitter_Color: The color of the center separation line.
Track_Color: Color of the black traces on the road. (can have another colors, but dark grey, black is common).
Dirt_Color: Color of the dirt on the road and the color of the chaotic traces. Can be disabled by setting the alpha channel to 0.
Pattern Size Width: The spot dirt width.
Pattern Size Height: The spot dirt height.
Dirt Disorder: Disorder the spot dirt.
Side_Color_2: Color of the sides. Needed to get better blending results with the ground.
Dirt1_Right_Y: X has no impact. Y blends less intensive layer over the right side on the side dirt. -0.5 is the highest blending for this value, and is recommended to leave it on this value.
The third size: Internal the procedural material has an irregular side dirt mask, with the color Side_Color_2. This dirt with this mask blends in the side dirt texture. X value blends from the side to the center, value 1 blends to the center. Y blends in U coords, in my cases this value is always on 1.
The transform matrix attributes are used to rotate the things on the road. For T, L junctions it must be done 4 times (rotating 90 degree) to have all the 4 sides for 1 side, to provide maching T sides for a road end.
SideLineColor: The normal road ’I’ can have side lines and here the color can be set for.
figure SDMaterial.jpg
Figure 6 Procedural Texture Generator Attributes


One of the Substance Designer graphs for the procedural textures.
figure SDProject.jpg
Figure 7 Procedural Texture Generator Graph in Substance Designer


4 Evaluation

I uses this approach in my own strategy game, were I have very good results. The following pictures shows how it looks like in an unfinished game.
figure eval1.jpg
Figure 8 In Game Picture 1
figure eval2.jpg
Figure 9 In Game Picture 2


The bridge under the road is too bright for the terrain and road, in this case the color/texture of the brige must be changed.
figure eval3.jpg
Figure 10 In Game Picture 3
figure eval4.jpg
Figure 11 In Game Picture 4


5 Implementation

This road material is based on two main parts, the procedural road texture generation and on the custom shaders. Both can be modified by you, if you have Shader Forge and Substance Designer 5. As described, there are six shaders for different quallity settings and 4 procedural texture generators for I, L, T, X road forms. I do not explain how to modify these projects, but if you have knowledge in Shader Forge and Substance Designer, then you will be able to do the changes. If you need help in this, you can ask me in the forum, but please do not let me explain you how these tools works.


6 Outlook

I use this road asset in my own RTS game, so it will be improved continously. The T, L, X junctions are at the time in a basic form, they will be improved. The “I” form road will have more center line types. Creating more lines for a road is also possible with the Substance Designer.


figure metadesc_logo_32.png