Unreal Engine 4 Tutorials

Continuously expanding content! 2019.01.05

Do you like it?

Donate us:

Mutable for Unreal Engine 4

Last Update: 2019.03.31

https://www.patreon.com/sorosmark


Unreal Engine 4 – Post Process Lens Distortion

Tutorial / 11 hours ago

In this breakdown we will create a post process lens distortion effect in Unreal Engine 4.

Setting up Material Domain

First, we create a basic material and set ‘Material Domain’ to ‘Post Process’.

Screen Position Center

With ScreenPosition we get the viewportUV data. Now with “component mask” we mask  layer B to only have the information of R and G.
Then we need ‘Add’ set on -0.5.  

Creating Radial Gradient

Create a radial gradient to adjust the radius and falloff. For this you can use the “RadialGradientExponential” node.
Add the result of the ‘Screen Position -Center’ to ‘UVs’. (Keeps the Center Position at 0)
Next, create a scalar parameter for AreaRadius(value=2) and AreaFalloff(value=2) so that you can expose the parameter and adjust it later within the material instance.
With the radius we can adjust the size of the gradient from its center. Use density to adjust the hardness of the gradient.
Last but not least, we add a Switch Parameter Node  with “OneMinus” after AreaRadius to invert the radius and switch between Barrel Distortion and Pincushion Distortion.

Multiplying UV Coordinats with our Radial Mask

Multiply the UV cords with the radial gradient and add an intensity function with a scalar parameter called ‘intensity’ and multiply again.  

(Be sure to use 1 as default when you multiply nodes!)

Substracting from UV

Lastly, we subtract the multiply intensity node from our RG component mask node.
The subtraction result will go into the PostProcessInput0 Node and then in our shader.

Material Instance

Save the material and create a material instance of it.
Open it to see the scalar parameter you created earlier. You can now adjust values and distortion.

(For the Barrel Distortion we must uncheck “Invert” and set the value “AreaFalloff = 2” and “AreaRadius =2” )
(For the Pincushion Distortion we must check “Invert” and set the value “AreaFalloff = 1” and “AreaRadius =2” )

Creating and Assigning Material to Post Process

Now you can put a  “PostProcessVolume” into the scene and assign the material in the “Post Process Materials” Slot.

Endresult!

And this is your end result!
If you have any questions feel free to send me a message! 🙂

(Screenshot of the lens distortion material)

Project textures

What is the HowTo about?

Mutable allows to project textures on materials through the Texture Project node. This might be very useful to create tattoos, wounds, dirt, images on clothes… Texture Project nodes are ruled by Projector values, which can be Projector Constants or Projector Parameters. The Projector Constant node allows the developer to set the position/rotation/scale of the image projection to a fixed value (not editable by the end-user). The Projector Parameter allows the end-user to set the pos/rot/sca of the projection by adjusting the widget in the viewport.

This HowTo shows 2 examples of Projectors. The simplest one projects a texture on a shirt, without toggleable or editable parameters. The second one makes the projection toggleable and allows to select between two different textures.

Constant Projector

In this example we’ll create a basic projection of a texture on the shirt of a character.

What assets are needed?

All the assets from the basic customizable character HowTo.

All the assets to create a Shirt, as seen in the remove mesh HowTo.

A texture with the image to be projected with its alpha channel (if needed). In this example, we’ll use this Fleur-de-lis texture.

The object of this example can be found as Bandit_Projector_Static in MutableExamples/HowTo

Steps

1- Create a basic Customizable Object with the base body and a Child Object inside it for the shirt.


2 – Create a Texture Project nodeCreate a Project Constant node and connect it to the Texture Project node. Import the texture for the projection and drag it inside the object. Connect the Texture to the ‘Image 0’ connection in the Texture Project node.

This will create the projection with the texture we’ve set and with the values from the Projector Constant node.


3 – Connect the skeletal mesh of the shirt to the Texture Project node to set the mesh that will be affected by the projection.


4 – Create a Texture Layer node and add a new Layer inside of it. We are blending the projected image from the Texture Project node with the base color of the shirt. Set the blending effect of the new layer to Modulate (or whathever you need). Import/Drag and drop the base color texture from the shirt and connect it to the Texture Layer. Connect the Texture Project node to the ‘Layer 0’ of the Texture Layer. In order to mask the texture, we can get the Alpha channel from the projected image. To do that, create a Texture To Channels node and connect it to the Texture Project nodeConnect the alpha channel (A) to the ‘Mask 0’ connection in the Texture LayerConnect the Texture Layer to the shirt Material’s color paramter.

The graph should look similar to this:


6 – When the Projector Constant node is selected, you can edit the pos/rot/sca of the projection with the widget in the Preview Viewport tab. Save and compile.

Selectable Constant Projector

In this example, we’ll expand the previous example of projecting textures. We’ll create a Group and a Child Object inside the shirt object in order to make the projection toggleable. To make this, we’ll need to edit the shirt material through an Edit Material node. Also, we’ll create a Texture Switch with an Enum Parameter in order to make the two different textures selectable.

What assets are needed?

All the assets from the basic customizable character HowTo.

All the assets to create a Shirt, as seen in the remove mesh HowTo.

Two different textures with the images to be projected with their alpha channel (if needed). In this example, we’ll use these two textures.

The object of this example can be found as Bandit_Projectors_Static_Selectable in MutableExamples/HowTo

Steps

1- Create a Group node and set it as ToggleConnect it to the shirt objectCreate a Child Object and connect it to the new group.


2- Create an Edit Material node connected to the Child Object. Select the parent’s material (the shirt material) and select all the blocks from this material that will be affected by the projection (in this case, we’ve selected all the shirt blocks).


3- Connect the Texture Project node to the Color parameter of the Edit Material node. Get the alpha channel of the projection with the Texture To Channels node and connect it to the Color Mask connection in the Edit Material node.


4- Create a Projector Constant and connect it to the Texture Project node.


5- To set two selectable textures, (from the previous example) replace the texture node connected to the ‘Image 0’ connection in the Texture Project node for a Texture Switch nodeAdd 2 new elements inside the Texture Switch node and connect the two Textures to each oneCreate an Enum Parameter node and connect it to the Switch Parameter in the Texture Switch node. Name the Enum Parameter and add 2 new elements inside of it. Name the two elements as they will be the selectable options in the viewport tab.

The whole node graph should look like this:


6 – Save and compile. With the Projector Constant node selected, you can adjust the pos/rot/sca of the projection in the viewport. Now, the projection is toggleable and, when active, two textures can be selected.

Projector Parameter

The previous examples are made with Projector Constant values that can be edited by the developers in the Customizable Object. There is a way to make the projector editable in the Object Instance and, therefore, accessible to the player in the game. This can be done with Projector Parameters.

The object of this example can be found as Bandit_Projector_Movable in MutableExamples/HowTo

Steps

We’ll take the same graph structure as the previous example, but making the projector affect directly the base mesh (the body).

1 – From the basic body character, add a toggleable Group and a Child ObjectCreate an Edit Material node to edit the body material and a Texture Project node as in the previous example. Connect the Texture to be projected in the Texture Project node. Create a Projector Parameter node and connect it to the Texture Project node.

The graph should look like this:


2 – Name the parameter. Save and compile. Now, when the Child Object is active in the Instance Viewport, a 3D widget can be adjusted on the character in real-time.

Adding angle fading

Another option of the Texture Project node, available in both Constant and Parameter options, is to set an angle range in the mesh where the projection is done or not. This is useful when tricky angles of the projection affect side or back parts of the mesh.

Steps

Having a functioning graph structure with a Texture Project:

1 – Create a Float Constant node and connect it to the ‘Fade Start Angle’ connection in the Texture Project node. Set the value of the Float to 25.


2 – Create another Float Constant node and connect it to the ‘Fade End Angle’ connection in the Texture Project node. Set the value of the Float to 45.


3 – Save and compile. The angle range will set when the projection starts to fade off:

You can adjust the fading angles to your needs.

Cylindrical Projector

Texture projectors have two ways of projecting onto the model’s geometry. So far we’ve used the planar projection type, but there’s also the option to use cylindrical projection.

What assets are needed?

All the assets from the basic customizable character HowTo.

A texture with the image to be projected with its alpha channel (if needed). In this example, we’ll use this Santiago cross texture.

The object of this example can be found as Bandit_Projector_Cylincrical in MutableExamples/HowTo

Steps

We’ll show how to make a cylindrical projector and how to automatically adjust it to a character’s skeleton bone.

1 – In the Mutable Editor, select the Projector Parameter Node, and in the Graph Node Properties, select the Cylindrical Projection type in the Projection Type drop down list.


2 – The gizmo of the projector will turn into a cylinder with two orange stripes.

The orange stripes describe the projection angle, i.e. the span around the cylinder surface where the texture will be projected onto the geometry inside the cylinder volume. The projection angle starts at the positive y axis arrow(green arrow) and spans at both sides:


3 – Set the projection value to 120 degrees, and now, with the help of the gizmo, position the cylindrical projector around the left arm of the character:


4 – Press the Compile button, the projected texture will show up around the character’s arm:


5 – To avoid most of the work of step 3, a snap to bone functionality is available in the Projector Parameter Graph Node Details tab: by selecting from the Projector Bone drop-down list the bone you want the projector to match, the projector gizmo will match that bone’s transform:


——————————————————————————————————————-

Animation Retargeting (Different Skeletons)

Note: This feature is not available before Engine Version 4.5

Animation Retargeting (Different Skeletons) is a feature that allows animations to be reused between characters that do not share the same Skeleton asset, unlike Animation Retargeting which involves retargeting animations between characters that share the same Skeleton asset.

The process of retargeting animations between characters that have different Skeletons uses an asset called a Rig to pass Bone information from one Skeleton to another. After selecting your Rig, you will share it between your Source Skeleton and a Target Skeleton (the Skeleton you wish to retarget animations to). Once you have done so, you will then match up the Target Skeleton’s Bones to the Nodes stored in the Rig.

Once all the Bones in the Target Skeleton have been setup in the Rig, you can then retarget animations that are used by your Source Skeleton to your Target Skeleton. You can even retarget entire Animation Blueprints along with all its associated data, which saves time if you want to quickly move all animation assets from one Skeleton to another.

Getting Started

In order to get started with animation retargeting between different skeletons, you will need to select a Rig asset for both Skeletons to share. This section will show you how to access the Humanoid Rig that comes as part of the Engine Content and assign it for use.

We are also going to use two asset packs that are available for free via the Marketplace that have multiple skeletons and animations in it that we can use to retarget. If you have two Skeleton Assets ready to use, you can skip the note below and use your assets. If you do not, you can follow along with the steps by adding the two packs outlined in the note below.

In this example, we are using the following assets which are available for download via the Marketplace.

  • The Source Skeleton we are using is the UE4_Mannequin_Skeleton that is included in the Animation Starter Pack.
  • The Target Skeleton we are using is the SWAT_Skeleton that is included in the Mixamo Character Pack.

Once you have installed the packs above, you can add them to a project via the Add to project button in the Unreal Launcher.

The Animation Starter Pack includes several animations that we will retarget for a character from the Mixamo Character Pack.

Also, your version of Unreal Engine 4 may vary from the one depicted above.

The steps below will show you how to access the default Rig and retarget animations:

  1. Inside the Content Browser under the Game/AnimStarterPack/UE4_Mannequin/Mesh folder, open the UE4_Mannequin_Skeleton asset.
  2. Click the Retarget Manager button, then under Set up Rig, click the Select Rig dropdown and select Select Humanoid Rig.

    Click image for full view.

  3. Click Save then close the window.
  4. In the Content Browser under the Game/MixamoAnimPack/Mixamo_SWAT/Anims folder, open the SWAT_Skeleton asset.
  5. Click the Retarget Manager button, then under Set up Rig, click the Select Rig dropdown and select Select Humanoid Rig.

    Click image for full view.

  6. With the Rig assigned, next you will need to match up the Bones from the Target to the Nodes on the Rig.
  7. Use the drop-down menus to select the Bones on the Skeleton that are similar in location to the Bones (Nodes) on the Rig.

    Click image for full view.

    In the image above, on the left is our Source Skeleton (with Show Bone Names enabled) and on the right is the Target Skeleton (also with Show Bone Names enabled). In the center is the Set up Rig window and we are specifying which Bones from our Target Skeleton are the same (or similar to in location) as the Bones on our Source Skeleton.

    While the naming conventions for each Skeleton may differ, you can see where each bone is on each Skeleton and match them up accordingly. You do not need to specify all Bones and some tweaking may be needed based on your needs.

  8. Continue to specify each Bone from the Target Skeleton to a corresponding Node on the Rig.The table below demonstrates the setup for the UE4_Mannequin_Skeleton and SWAT_Skeleton
    Node (Rig) Bone (Skeleton)
    Root None
    Pelvis Hips
    spine_01 Spine
    spine_02 Spine1
    spine_03 Spine2
    clavicle_l LeftShoulder
    upperarm_l LeftArm
    lowerarm_l LeftForeArm
    hand_l LeftHand
    clavicle_r RightShoulder
    upperarm_r RightArm
    lowerarm_r RightForeArm
    hand_r RightHand
    neck_01 Neck1
    head head
    thigh_l LeftUpLeg
    calf_l LeftLeg
    foot_l LeftFoot
    thigh_r RightUpLeg
    calf_r RightLeg
    foot_r RightFoot

    There are two configurations that can be used when setting up the Rig, Base or Advanced. The Base Configuration (denoted in the chart above) uses the key elements that are needed to ensure the animation is successfully retargeted. The Advanced Configuration allows you to include and specify additional Bones that should be included as part of the retargeting process.

    In the example above, the left and right hands were included as part of the retargeting process however individual fingers were not. Retargeting an animation with the Base Configuration will ensure that the base motion is copied to the new Skeleton, however if the Source Skeleton had animated fingers and the Target did not, the retargeted animation would not animate the fingers and you would have stiff looking hands.

  9. Click the Show Advanced button to toggle Advanced configuration.
  10. Specify Bones from the Target Skeleton to a Node on the Rig for the Advanced Configuration.
    Node (Rig) Bone (Skeleton)
    index_01_l LeftHandIndex1
    index_02_l LeftHandIndex2
    index_03_l LeftHandIndex3
    middle_01_l LeftHandMiddle1
    middle_02_l LeftHandMiddle2
    middle_03_l LeftHandMiddle3
    pinky_01_l LeftHandPinky1
    pinky_02_l LeftHandPinky2
    pinky_03_l LeftHandPinky3
    ring_01_l LeftHandRing1
    ring_02_l LeftHandRing2
    ring_03_l LeftHandRing3
    thumb_01_l LeftHandThumb1
    thumb_02_l LeftHandThumb2
    thumb_03_l LeftHandThumb3
    lowerarm_twist_01_l LeftHand
    upperarm_twist_01_l LeftArm
    index_01_r RightHandIndex1
    index_02_r RightHandIndex2
    index_03_r RightHandIndex3
    middle_01_r RightHandMiddle1
    middle_02_r RightHandMiddle2
    middle_03_r RightHandMiddle3
    pinky_01_r RightHandPinky1
    pinky_02_r RightHandPinky2
    pinky_03_r RightHandPinky3
    ring_01_r RightHandRing1
    ring_02_r RightHandRing2
    ring_03_r RightHandRing3
    thumb_01_r RightHandThumb1
    thumb_02_r RightHandThumb2
    thumb_03_r RightHandThumb3
    lowerarm_twist_01_r RightHand
    upperarm_twist_01_r RightArm
    calf_twist_01_l None
    ball_l LeftToeBase
    thigh_twist_01_l LeftUpLeg
    calf_twist_01_r None
    ball_r RightToeBase
    thigh_twist_01_r RightUpLeg

    You may encounter situations where there may be additional Bones in one Skeleton that are not included in the other; you can omit these as adjustments can be made to the Target Skeleton to account for this.

    For this example, you can also leave the IK bones to None on the Mixamo character as IK retargeting is still in development.

  11. In the Content Browser, under Game/AnimStarterPack, select an animation that you want to retarget to the new Skeleton.
  12. Right-click on the animation and choose Retarget Anim Assets -> Duplicate Anim Assets and Retarget.
  13. In the Select Skeleton window, you should see your Skeleton in the upper portion of the window, select it and click Select.
    Retarget11_2.jpg
  14. A copy of the animation you selected to retarget will be created in the same folder of your Target Skeleton.
    This new animation can now be used with your character.

Retargeting Adjustments

When setting up a Rig to share between Skeletons, you may encounter situations when one Skeleton has additional Bones that the other does not have (in the Getting Started section, if you used Skeletons specified in the example, you may have noticed extra Bones in the Mixamo Skeleton’s hands for example). This can sometimes cause issues but can be fixed by recursively setting translation retargeting to the Skeleton.

For example, here is a shot before adjustments:

Notice how the fingers appear contorted due to the extra Bone not specified during the Rig set up.

Here is an example after adjustments were made:

You can specify Bone Translation Retargeting through the Skeleton Tree view. Here we are Right-clicking on the last digit in each finger and setting Bone Translation to Recursively Set Translation Retargeting Skeleton.

Retargeting an Animation Blueprint

Once you have gone through the process of setting up a Rig for two Skeleton assets to share, if there is an Animation Blueprint associated with the Source Skeleton, you can select to retarget it for use with your Target Skeleton.

Right-click on an Animation Blueprint and select the Retarget Anim Blueprints -> Duplicate Anim Blueprints and Retarget option.

RT_AnimBP.jpg

The Select Skeleton window will appear. Select your Target Skeleton and press Select.

Retarget11_2.jpg

All the assets associated with the Animation Blueprint (Animation assets, Blend Spaces, etc.), along with any logic defined in the Animation Blueprint itself will be copied and placed in the same location as your Target Skeleton.

Retargeting a Base Pose

There may be instances where you want to retarget animations to a Skeleton that is not quite using the same base pose as your Source Skeleton.

Take for example the Skeleton in the image below on the right.

Retarget2_2.jpg

Our Source Skeleton on the left is in a A-Pose while our Target Skeleton is using an T-Pose. Even though a Rig has been set up for them to share, if we were to retarget animations as is now, we may encounter issues as seen below.

In the image above, an animation has been retargeted for our Target Skeleton; however his arms clip into his side because the base poses were not the same. Thankfully, you can also retarget the Base Pose of your Target Skeleton prior to retargeting animations to reduce or eliminate issues like this from occurring.

In your Target Skeleton, under Retarget Manager, there is an option called Manage Retarget Base Pose.

If you click the View Pose button, you will see the current Base Pose. You can adjust it by clicking on a Bone and using the Rotation (E) widget.

In the image above, the right arm has been adjusted while the left arm is using the default base pose (which we can adjust by using the rotation widget). Once you have adjusted the pose, you can click the Save Pose option to save the retargeted Base Pose. With similar Base Poses between Skeletons, you can now retarget an animation and when the Skeleton Select window appears, you will notice that your Target Skeleton is now using a retargeted Base Pose.

Retarget2_2.jpg

Retargeting the animation with the retargeted Base Pose, results in a better looking animation.


Easy Material Blueprint