UE5 - Misc

Tips

UI

  • Selection
    • Box Select
      • Hold Ctrl + Alt + LMB clcik and drag

Material Graph

  • Reroute
    • You can add a reroute node by double clicking the connection line
  • Debug nodes
    • You can use the debug nodes under Debug to visually debug values. Lets say that you want to view the object bounds you can connect the output of an Object Bounds node to an Debug Float 3 node.
    • Debug >
      • Debug Scalar Values
      • Debug Float 2 Values
      • Etc …
  • Material Attributes
    • If you want the result node of a material to be a material attribute:
      • Details > Material >
        • Use Material Attribute : On
  • Asset Editor Open Location
    • This controls where an asset editor will open (including plugins, editor settings, etc)
    • Edit > Editor Preferences > General > Appearance > User Interface >
      • Asset Editor Open Location:
        • Default
        • New Window
        • Main Window
        • etc

Landscape

Quick Setup

  • Create a Level
    • Add lighting actors
  • Create a Landscape
    • Switch to Landscape Editing Mode
      • Shift + 2 (or use the mode dropdown)
    • Create new Landscape
      • In the landscape pane, make sure the Manage mode is selected and click the create button in the bottom left.
    • Do some sculpting
      • Make sure sculpt mode is active (in the landscape pane) and do some quick sculpting to get some shapes to work with
  • Create a Material
    • RMB click in the Content Browser > Add Material
      • Call it “M_Landscape”
      • Open the material in the material editor
    • Use Material Attributes
      • We are going to use material attributes in this material
      • Select the “M_landscape” result node (the only node that exists in the graph if the material was just created)
      • In the Details pane Material >
        • Use Material Attributes : Enable it
    • Add textures
      • We are going to create two material to blend between a “Grass” and a “Dirt” material
      • We are using megascans so find some nice textures
        • Drag in the base color and the normal map of the “Grass” and “Dirt” material respectively
      • We might want to change the Material Expression Texture Sample from “From Texture Asset” to “Shared: Wrap”
    • Add a Make Material Attributes node
      • press tab over an empty space in the graph and start typing “mate…“and select MakeMaterialAttributes from the list
      • With the “m"ake material attributes” node selected press Ctrl + D (since we need one for each material)
      • Connect the base color & normal of the textures to the corresponding input of the “make material attributes” node
    • Add a Landscape Layer Blend node
      • Press the tab and stat typing “land…” select “Landscape Layer Blend”
      • Add Layers
        • With the Layer Blend node selected…
        • in the details pane Material Expression Landscape Layer Blend > Layers…
        • Click the + icon 2 times to add 2 layers
        • Open the added layers rollout and call the first layer name “Grass” and the second “Dirt”
    • Connect Material Attributes to Layer blend
      • Connect the “grass” material attributes to the input of the layer blend we called “grass” and do the same for the “dirt”.
    • Connect Layer blend to result node
      • Connect the ouput of the layer balen to the input of the
    • Save the material
  • Assign the material
    • In the outliner select the landscape (Note we are still in the Landscape mode)
    • In the details > Landscape >
      • Landscape Material : assign the material we just created
    • Create Layer info
      • In the Landscape pane > Layers you will find the 2 layers we created in our material
      • On the first layer (which in our case is “Grass”) click the + on the right hand side of the layer
        • Select Weight-Blended Layer (normal)
        • Save the layer info in the proposed folder (or select where you want it)
        • Repeat this process for the “Dirt” layer

Virtual Textures

Setup virtual textures

Lets setup virtual textures to blend the materials with the landscape.

  • Enable Virtual Textures
    • Project Settings > Engine > Rendering >
      • Virtual Textures >
        • Enable Virtual Texture Support : On
  • Note!
    • Virtual Textures also works with static meshes, not only on landscapes
    • Meercat Weta example is using that

  • Setup Virtual Textures
    • Create a folder
      • In the content browser create a folder where we will create our VT
      • Call it VirtualTextures
    • Create Virtual Textures
      • Step in side the create folder, RMB click > Textures > Runtime Virtual Texture
        • Call the first on VT_Height
        • Duplicate it (Ctrl + D) call it VT_Material
      • Setup the VT_Height
        • Open up the VT_Height (double click it)
        • Size > Size of virtual texture in tiles : 10 (will result in 1024)
        • Layout > Virtual Texture Content : World Height
        • Save it
      • Setup the VT_Material
        • Open up the VT_Material (double click it)
        • Size > Size of virtual texture in tiles : 10 (will result in 1024)
        • Layout > Virtual Texture Content : Base Color, Normal, Roughness, Specular (default)
        • Save it
    • Add & setup Virtual Texture Volume
      • Add a Runtime Virtual Texture Volume (actor) to the level
        • call it “RuntimeVirtualTextureVolume_height”
      • Set Virtual Texture
        • With added node selected in the world outliner, go to the details panel
        • In the property Virtual Texture use the drop down to select “VT_Height”
          • (or drag and drop from the content browser)
      • Set Bounds Align Actor
        • In the property Transform From Bounds > Bounds Align Actor
          • Use the picker (pick actor from scene) and pick the landscape in the 3d view
          • Or use the drop down to select your landscape
        • Click Transform From Bounds > Set Bounds
          • This will setup the transform to encompass the landscape
      • Duplicate the Runtime Virtual Texture Volume
        • Select “RuntimeVirtualTextureVolume_height” in the outliner
        • Duplicat it call it and call it “RuntimeVirtualTextureVolume_material”
        • In the details panel set the Virtual Texture to “VT_Material”

Setup landscape Material

  • Setup landscape material
    • We need to setup the material so that the VT knows what to capture
    • Open up the landscape master material
    • Press tab and start typing “run…” and select “RuntimeVirtualTextureOutput”
    • Connect the outputs to the RuntimeVirtualTextureOutput
      • BaseColor
      • Specular
      • Roughness
    • Get the height information
      • Creat a Absolute World Position node
        • Press tab start typing “wo…” select “WorldPosition”
      • Component mask the Z channel
        • Press tab start typing “com…” select “ComponentMask”
        • Connect the output of the “WorldPosition” node to the input of the “Component mask”
        • On the component mask, enable the B (and disable R & B) since we only are interested in the Z (height value)
      • Connect the output of the component mask to the WorldHeight input of the RuntimeVirtualTextureOutput
    • Convert the Normal space
      • Convert space
        • The normal is in tangent space but the VT are expecting it to be in world space, so we need to convert it.
        • Press tab start typing “tra…” select Vector Ops > “Transform”
        • Make sure Source is “Tangent Space” (Default)
        • Make sure Destination is “World Space” (Default)
      • Connect the output of the transform vector node to the normal input of the RuntimeVirtualTextureOutput
  • Draw landscape in VT
    • Setup the landscape to draw in the virtual textures
      • Select the landscape in the outliner
      • In the details panel scroll to Virtual Textures
      • Click the + icon to add 2 items
      • Select the VT_Height & VT_Material respectively.
      • You should now se a small little preview of the VT on the thumbnail nect to the VT we just specified

Setup mesh material

  • Organize the material
    • Open the Master material of the mesh you want to blend with the landscape
    • In our case we are using a megascans material
    • To keep it tidy select all nodes except the result node and press “C”
      • This will create a comment box around, lets give it the name “Original Material”

Mask from the VT height

  • Create a mask from the height of the VT
    • Sample the heigth of the VT
      • We are going to control the blending using our VT height information
      • Press tab start typing “vir…” select Virtual Texture > “RuntimeVirtualTextureSampleParameter”
        • We choose a parameter to be able to specify which VT we want to use
      • Call the parameter it “VT Height”
      • Make sure that the parameter Virtual Texture > Virtual Texture Content is set to World Height
    • Get the world positon of the material
      • Create an “Absolute World Position” node
        • Press tab start typing “wo…” select “WorldPosition”
      • Component mask the Z channel
        • Press tab start typing “com…” select “ComponentMask”
        • Connect the output of the “WorldPosition” node to the input of the “Component mask”
        • On the component mask, enable the B (and disable R & B) since we only are interested in the Z (height value)
    • Calculate where the mesh intersects the landscape
      • Subtract the world Height of the VT from the world position of the material
        • Create a subtract node
          • press tab, type “-” (minus or dash) select Math > Subtract
        • Connect the output of the component to the “A” input of the subtract node
        • Connect the output of the “RuntimeVirtualTextureSampleParameter” to the “B” input of the subtract node
    • Control the mask blend start (factor in the scale of the mesh)
      • Theory
        • Here we will add a parm to control where the mesh will start to transition from the landscape material to the mesh material.
        • We will make sure that the height of the vt mask (that we will expose as a parameter) will be in relation to the size of the mesh. This means that if you have two instances of the same mesh and you set the scale of one of the mesh to double the size of the first, the “height” of the parameter on the material will “reach” the same “height” of the to meshes.
        • Steps
          • We will start of with the value that we calculated in the earlier step. (Subtract the VT world height from the absolute world position of the material (of the pixel being shaded)) which will give us a position where the mesh intersects the landscape
          • To this we will add the “height” (z component) of the object bounds of the mesh. This will basically shift the “intesection value upwards” (to cover the entire mesh)
          • Then we will add a parm to let the user control the start of the blending.
          • We will then multiply this parm with the with the z component of the object bounds node…
          • …And subtract this from the height value
          • This means that it we enter a value of 2 to the parm the mask will start in the middle of the mesh no matter the size of the mesh.
      • Get the Z (height) bounds value
        • Create an Object Bounds node
          • Press tab and start typing “objectb…” select Vectors > ObjectBounds
          • This will give us the object bounds of the mesh that material is assigned to
        • Get the Z value
          • Press tab start typing “com…” select “ComponentMask”
          • Connect the output of the “Object Bounds” node to the input of the “Component mask”
          • On the component mask, enable the B (and disable R & B) since we only are interested in the Z (height value)
      • Add the Z value to height
        • Create and Add node
          • Hold “A” and LMB click the node graph
        • Connect the output of the subtract node to the A input
        • Connect the output of the component masked (Z) object bounds node to the B input
      • Create a parameter to control when the blend starts
        • Add a parameter node
          • Hold “S” and LMB click, call it “Virtual Blend Height”
          • Set the default value to 1.05
        • Add a multiply node
          • Hold “M” and LMB click the node graph
          • Connect the output of the component masked (Z) object bounds node to the A input of the multiply node
          • Connect the output of the parameter to the B input of the multiply node
      • Subtract the parm value from height
        • Create a subtract node
          • Connect the output of the Add node we created earlier to the A input of the subtract node
          • Connect the output of the multiply node to the B input of the subtract node
    • Control the falloff (blur)
      • Add a parameter node
        • Hold “S” and LMB click, call it “Virtual Falloff”
        • Set the default value to 100
      • Create a divide node
        • press tab and type “/” select Math > Divide
        • Connect the output of the subtract node to the A input of the divide node
        • Connect the output of the “Virtual Falloff” parameter node to the B input of the divide node
    • Clamp the values
      • Press tab and start typing “sa…” select Math > Saturate
      • connect the output of the divide node to the input of the saturate node

Remove landscape stretching

  • Remove the height texture stretching
    • Theory
      • The virtual texture will be “projected” top down (z axis) so to avoid texture stretching on the blended texture of the mesh we can do the following setup.
      • What we will do is to get the vertex normals of the mesh, component mask the Z value and where the Z is pointing straigh up we will get white and down we eill get black. We can the use tis to mulktiply with to remove the stretching.
    • Get the Normal Z component
      • Add a vertex Normal node
        • Press tab and start typing ‘ver…’ select Coordinates > VertexNormalWS
      • Component mask the Z axis
        • Press tab start typing “com…” select “ComponentMask”
        • Connect the output of the “VertexNormalWS” node to the input of the “Component mask”
        • On the component mask, enable the B (and disable R & B) since we only are interested in the Z
    • Control the effect
      • Add a Parameter to control the effect
        • Hold S and LMB click
        • Call it “Virtual Side Amount”
      • Multiply the Z component
        • Add a multiply node
          • Press M and LMB click
        • Connect the output of the component mask to the A input of the multiply node
        • Connect the output of the Parameter node to the B input of the multiply node
        • Add a saturate node to clamp the output
          • press tab start typing ‘sa…’ select Math > Saturate
          • connect the output of the multiply node to the input of the saturate node
    • Mask the VT height value
      • Theory
        • We will multiply the VT height mask with the output of what we created in this setup
        • Since the output of the VT height is white on the top and black on the bottom. we will invert this, multiply it with the value we calculated in this setup, then invert it once agian, so that we can use it to mask the material.
      • Invert the VT height mask value
        • Create a One Minus node
          • Press tab and start typing “1-…” select Math > OneMInus
        • The last node of the setup we did to calculate the VT height mask is a saturate node.
          • Note not the saturate node we created in this section
        • Connect this saturate node to the input of the One Minus node
      • Multiply the inverted VT height value
        • Create a Multiply node
          • Connect the output of the One MInus node to the A input of the Multiply node
          • Connect the output of the saturate node (the one we created in this set up, where we “Mask the height value”)
        • Create on more One Minus node
        • Connect the output of the Multiply node to the input of the One Minus node
      • The output of this One Minus will later be connected to the Alpha input of Blend Materials Attribute node, and will control the blending of the landscape material (comming from the material virtual texture) and the Megascan material applied to the mesh.

Get material from VT

  • Get the Material data from the virtual texture
    • Create a VT for the material data
      • Now we need to get the material data from our virtual texture
      • Press tab start typing “vir…” select Virtual Texture > “RuntimeVirtualTextureSampleParameter”
        • We choose a parameter to be able to specify which VT we want to use
      • Call the parameter it “VT Material”
      • Make sure that the parameter Virtual Texture > Virtual Texture Content is set to Base Coilor, Normal, specular, Roughness
    • Create material attributes from the VT
      • Press tab start typing “mak…” select Material Attributes > MakeMaterialAttributes
      • Connect the Base Color, Specular, Roughness and normals from the VT to the make material attributes node
  • Convert (material) normal space
    • The normal data in the virtual texture is in world space but the normal data of the material is in tangent space To be be able to blend them correctly we need to transform the normal of the material to world space
      • Since the node that is connected to the result node of the material is a material attributes node we need to break it to get to the normal data
    • Add a Get Material Attribitus node
      • The easiest way is to click on the output of the original node (the one that feeds into the result node) drag out and release
      • In the pop menu start typing ‘ge…’ select Material Attributes > Get Material Attributes
      • With the get material attributes selected, in the details panel under the Attribute Get Types click the + to add an attribute to get
      • From the dropdown select Normal
    • Transform the space
      • Click on the Normal output (on the get material attributes node) drag out and release
      • Start typing ‘tra…’ select Vector Ops > Transform
      • As we can set teh default setting Tangent -> World space is wahr we want
    • Add a Set Material Attributes node
      • From the MaterialAttributes output (of the get materials attributes node) drag out and release
      • Start typing ‘se…’ select Material Attributes > Set Material Attributes
      • With the set material attributes selected, in the details panel under the Attribute Set Types click the + to add an attribute to get
      • From the dropdown select Normal
  • Blend The material
    • We are using a Megascans material and we can see that a material attributes node is connected to the result node of the material
      • We will blend in the landscape material inbetween the material attributes node and the result node
    • Create a Blend Material Attributes node
      • Press tab start typing “blendm…” select Material Attributes > “BlendMaterialAttributes”
      • Connect the output of the blend materials attributes node to the result node of the material
    • Connect the output of the Make Material Attributes node (the one we use to make materials attributes from the VT Material) to the A input of the Blend Materials Attributes node
    • Connect the output of the Set Material Attributes node (the one we use to convert the normal of the original material to world space) to the “B” input of “BlendMaterialAttributes” node
    • Connect the output of the saturate node to the “Alpha” input of the “BlendMaterialAttributes” node
      • This will control the blending of the materials
  • Convert output normal space
    • Since we have converted the normal to world space when we did the blending (of the virtual texture and the material) and the material expects the normal to be in tangent space we need to convert it back.
    • Lets copy the setup we did earlier (when we converted the normal of the material from tangent space to world space)
      • Select the Get Material Attributes, Transform Vector & the Set Material Attributes nodes (that we did in step Convert (material) normal space above)
      • Duplictae them (Ctrl + D)
    • Place them after the Blend Materials Attributes node
    • In the Transform Vector node we want to change the Source to World Sapce and the Destination to Tangent Space
    • Connect the output of the Blend Materials Attributes node to the input of the Get Material Attributes node
    • Connect the output of the Set Materials Attributes node the the input of the materiasl result node

M_landscape
Ctrl-C
Example of a landscape material setup, very WIP
M_landscape_vt
Ctrl-C
Example of a landscape material setup with vt, very WIP

M_virtual_texture
Ctrl-C
Example of a VT setup, very WIP

Optimization

Stats

  • FPS
    • Ctrl + Shift + H