476 Game Development and Simulation with Unreal Technology
FIGURE 7.56: Bush Material Fading Support.
PER INSTANCE FADING FOR ROCK MATERIALS
Great! With our Per Instance Fading set up for the Bush materials, when
we moved around in the level, bushes appear to fade away. What is more, they
will fade away individually instead of as a whole cluster.
Let us establish the same network for our Rock foliage instanced meshes as
well:
39. In the Content Browser, go to your ma te rials folder in which you placed copies
of the Bush and Rock materials.
40. Double-c lick on the M_LScape_Rock material to open it in the Material
Editor. We will now modify the material to supp ort Per Instance Fading.
41. The first difference that you should notice in your Rock Material is that its
Opacity Mask Channel is disabled. This is because this material has its Blend
Mode set to opaque. To allow for the Per Instance Fading support we need
to be able to use the opac ity mask channel.
42. Click on the material node in the grap h editor.
43. With the material node selected, loo k for the Blend Mode in the Details rollout.
44. Open the Blend Mode drop-down and select Masked (Figure 7.57(a)). This will
activate the Opacity Mask channel of your material.
45. Right-cl ick on the graph editor, to the left of th e now-activated Opacity Mask
channel and place a Per Instance Fade Amount expression.
46. Connect the ou tput channel of the Per Instance Fade Amount expression to
Terrains and Landscapes in Un real Engine 477
the Opacity Mask channel o f yo ur material (Figure 7.57(b)).
(a) (b)
FIGURE 7.57: (a) Setting up Masked Blend Mode. (b) Simple Fading Network.
47. Save and Apply your material.
48. Now, g o back to the level editor and move ar ound in the landscape to see the effect
your changes m ade to the visibility of Rock instances.
After moving around in the land scape you should notice that the Rock foliage in-
stances now disappea r from the view individually, instead of as a whole cluster.
Although this look is much mor e desirable than what we were getting before
setting up the Opacit y Mask network, the rock instances still disappear. We
need a network a little bit mor e complicated than what we have set up so far to
achieve the desired look . Let us do that next:
49. Open the SM_LScape_Rock material in the material editor, if you have closed
it.
50. Move the Per Instan ce Fade Amo unt expr ession below the Texture Sample
expression that has Rock Base Color texture (Figure 7.58).
51. Place an Add expression to the right of the Rock texture’s Texture Sample.
52. Connect the Alpha channel of the Rock Base Color Texture Sample to the A
channel of the Add expression .
53. Place a Constant expression (by holding the 1 key and left-clicking) to the left
of the Add expression.
54. Type the value of 0.5 in the R value of the Constant expression and connect its
output to the B channel of the Add expression.
55. Place a Multiply expression to the right of both the Add and the Per Instan ce
Fade Amount expressions.
56. Place a Clamp expression to the right of the Multiply exp ression and make the
following connections (Figure 7.58):
Multiply A Output of Add
Multiply B Output of Per Instance Fade Amount
Multiply out put Inpu t of Clamp expression
Clamp output Op acity Mask channel of material node
57. Save and apply your material.
478 Game Development and Simulation with Unreal Technology
FIGURE 7.58: Setting up the Complete Fading Network for Rock Materials.
58. Now, in the editor viewport, move around in the landscape and see how this ef-
fect makes each rock instance fade, before it is completely culled, to make for a
smooth transition.
What Happened in TUTORIAL 7.8. . .
Congratulations! You just learned how to populate your landscape with lots of
static mesh instances, also known as foliage instances. As we discussed, using
the Foliage System in UE4 has two primary benefits. The first advantage is in
regards to speeding up the process of populating your vast outdoors levels with
lots of props, since the process is basically like painting on the landscape.
However, the second and most im portant advantage of using the Foliage Sys-
tem is in its e fficiency in rendering in stanced static meshes, by means of cluster
instancing. We learned, in this chapter, that UE4 utilizes the cluster instancing
to render all of the instanced static meshes in a cluster with one, single, draw
call. Moreover, foliage instances may also be set up to be culled. Th at is, when
a cluster of foliage instances is far enough, it may b e set up to b e ignored by
the render ing pipeline. However, for the culling to work efficiently, one must
make su re that the material for such instances is set up to support fading of the
Terrains and Landscapes in Un real Engine 479
instances from view before they are completely culled.
In this tutorial I emphasized both of the aforementio ned advantages. We
learned how to first set up our instance meshes in the Foliage System and how
to paint them on ou r landscape. We also lea rned how to set up the mater ia ls ap-
plied to our foliage static meshes properly to support fading and cullin g by the
Foliage System.
ORGANIZING ASSETS
First, an d before we delved into our foliage setup, we organized our assets to
be used in this tutorial. We were going to use two static meshes for our fo liage
instances, a Bush static mesh and a Rock static mesh. Luckily, the Starter Content
comes eq uipped with these two meshes. In o rder to preserve the original meshes,
we made a copy o f each of these static meshes into our own Meshes folder.
These static meshes have a material applied to them. We were going to make
changes to the materials later in the tutor ia l to support fading and culling. In order
to pre serve the original materials in the Starter Contents, we made copies of the
static mesh materials for both the Rock mesh and the Bush m esh into o ur own My
Materials folder. Once we had th e copies of these materials, we applied them
to the copies of their respective meshes.
ADDING FOLIAGE ME SHES
Now, with our static mesh co pies ready and proper material copies ap plied, it
was time to set them up in the Foliage System. We added our copy of the Rock
and Bush static meshes to the Foliage System.
SETTING FOLIAGE MESH PROPERTIES
We wanted to give some random look to the placement of the rocks as they are
being painted. There fore, we set up the Random Pit ch to allow for up to 45
.
Next, we made the Z offset to allow for -15 units of placem ent, making some of
the rock instances look partially buried. To make the size of instances vary, we
also a llowed that Foliage Paint Tool to scale the instances between 20% to
80% of the actual mesh size. Finally, for a sparse place ment we used a value of
5/Kuu
2
for the density of the rock instanced m eshes.
We on ly changed two of the settings for the Bush instanced foliage meshes.
We set the density of the Bush in stances at 3/Kuu
2
and their scale to vary between
50% to 150% of the origina l Bush static mesh size.
PAINTING FOLIAGE MESHES
As you noticed, placemen t o f the foliage instanced meshes in the landscape
was pretty straightfo rward. All we needed to do was to set up our brush
size an d then paint the instances onto the landscape by h olding Control and
Left-Clicking on the lan dscape. To remove instances, we pressed the Shift
key and Left-Clicked on the landscape.
480 Game Development and Simulation with Unreal Technology
I wanted to avoid placing any rock or bushes onto the road mesh we placed
in the landscape in Tutorial 7.7. This was a fairly easy task to do by using the
Filter in Foliage System. All we needed to do was to uncheck the Static
Mesh in the Paint Mode. This will avoid paintin g foliage instances if the brush
covers static meshes in the level.
SETTING THE CULLING MECHANISM
The first task to perform to enable culling in the Foliage S ystem is to set the start
and end cull distances. Bu t befo re setting our cull distances, we mad e two minor
changes to our cluster sizes for the Rock and Bush static meshes. By default the
Cluster Radius is set to 10,000 world units. Our landscape is relatively small,
and I wanted us to see the culling effect better over the co urse of th e next few
steps. So we simply re duced the Cluster Radius for both of our meshes to 2,000
world units to make smaller clusters of foliage instances in the landscape .
Our n ext order of business was to go to the Show Instanc e Setting sec-
tion of each foliage static mesh, and set the Star t Cull Distance and the
End Cull Distance properties. We set the St art Cull Distance to 2,000
and the End Cull Distance to 4,000 for both the SM_LScape_Rock and
SM_LScape_Bush meshes.
Setting the start and end cull distance will trigger the engine to perfo rm two
tasks. When each cluster reaches the Start Cull Distance the engine will start
calculating the fading per instance process. This is a value that is ca lc ulated for
each in stance in the cluster and supplied to the Unr eal Engine’s Mate rial Editor
via a Per Inst ance Fade Amoun t material expression. When a cluster reaches
the End Cull Distance, the rendered will cull it, in its entirety, from the view.
So far in our progress, we saw the second effect –i.e., after zooming out in the
editor viewport cluster s disappeared (Fig ure 7.55(b)). But w hat happened to the
instance fading? Well, the materials for neither Bush nor Rock instan ces support
fading, yet. T hat is why foliage instances in the landscape suddenly disappeared
once you walked away from them. We set up the fading support in the materials
next.
PER INSTANCE FADING FOR THE BUSH MATERIAL
As it turns out, supporting per instance fading is relatively easy to set up in the
material editor. We first supported fading for the bush material, since it alrea dy
had an O pacity Mask network.
The Bush material is ma de of a texture sample that represents leaves’ colors
and texture. However, upon close inspection, y ou will notice that th is texture also
has an Alpha channel that is fed to the Opacity Mask channel of the material.
When applied to the Bush Static Me sh, this material will make only the leaves
and branches of the mesh visible and masks th e rest of the mesh as completely
transparent.
Well, this is perfect for our use in th e fading support network. We created
a Per Instance Fade Amount expression in the material editor. The o utput
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.35.185