## UE4 – Procedural 3D noise bump setups

Software:
Unreal Engine 4.25

Yet another case where I develop my own costly solution only to find out afterwards that there’s actually a much more efficient built-in solution.. ðŸ˜€

In this case the subject is deriving a bump normal from a procedural or non-uv projected height map/texture (like noise, or tri-planar mapping for example).

The built-in way:
Using the pre-made material functions, PreparePerturbNormalHQ and PerturbNormalHQ, the first of which uses the low level Direct3D functions DDX and DDY to derive the two extra surface adjacent values needed to derive a bump normal, and the last uses the 3 values to generate a world-space bump normal:

1. Noise coordinates are obtained by multiplying the surface shading point local position by a value to set the pattern density.
2. The Noise output value is multiplied by a factor to set the resulting bump intensity.
3. The PreparePerturbNormalHQ function is used to derive the 2 extra values needed to derive a bump normal.
4. The PerturbNormalHQ function is used to derive the World-Space bump normal.
5. Note:
Using this method, the material’s normal input must be set to world-space by unchecking Tangent Space Normal in the material properties.

The method I’m using:
This method is significantly more expensive in the number of shader instructions, but in my opinion, generates a better quality bump.
Sampling 3 Noise nodes at 3 adjacent locations in tangent-space to derive the 3 input values necessary for the NormalFromFunction material function:

1. Noise coordinates are obtained by multiplying the surface shading point local position by a value to set the pattern density.
2. Crossing the vertex normal with the vertex tangent vectors to derive the bitangent (sometimes called “binormal”).
3. Multiplying the vertex-tangent and bitangent vectors by a bump-offset* factor to create the increment steps to the additional sampled Noise values.
* This factor should be parameter for easy tuning, since it determines the distance between the height samples in tangent space.
4. The increment vectors are added to the local-position to get the final height samples positions.
5. The NormalFromFunction material function is used to derive a tangent-space normal from the 3 supplied height samples.

Note:
From my experience, even though the UV1, UV2 and UV3 inputs of the NormalFromFunction are annotated as V3, the function will only work is the inputs are a scalar value and not a vector/color.

## UE4 – Quick fix for normal map encoding

Software:
Unreal Engine 4.25 | Photoshop 2020

Quick UE normal map tip:
If you load a normal map into a UE material and the result appears inverted, i.e. holes instead of bumps or the other way:

The quick fix:

1. In the texture settings, check the Flip Green Channel option and save it:

The deep fix:
* This can be performed an automated action on multiple files

1. Open the normal map in Photoshop
2. In the Channels panel, select the Green channel
3. Press Ctrl + I,
Or Select Image > Adjustments > Invert
To invert the green channel.
4. Save the texture and reload into Unreal Engine.

Inverted normal map:

Fixed normal map:

## UE4 – Creating two sided material effects using the TwoSidedSign node

Software:
Unreal Engine 4.24

The TeoSidedSign node let’s the shader “know” if a rendered polygon is facing the camera or not by outputting a value of 1 for facing polys and -1 for back-facing polys.
This is useful for creating materials that have different properties when seen front-facing or back-facing.

Example 1:
Blending two different colors based on face direction:

1. Check the Two Sided material attribute.
* Needed so that the engine will render the polygons beck sides.
2. In the material blueprint, create a blend of to colors using a Lerp (LinearInterpolate) node and connect it to the material’s Base Color input.
3. Add a TwoSidedSign node to get polygon facing input (1,-1).
4. Connect the TwoSidedSign node’s output to a Clamp node to clamp the values to (1,0).
5. Connect theÂ  Clamp node’s output to the Lerp node’s Alpha input so that the polygon’s facing direction will control the Lerp blend.

Note:
You can use this method to blend any other material attribute based on polygon facing direction.

Example 2:
Create an “inwards facing” flipped normal material:

1. Set the material’s Blend Mode to Masked.
* Needed for being able to make areas parts of the mesh invisible.
2. Check the Two Sided material attribute.
* Needed so that the engine will render the polygons beck sides.
3. Add a TwoSidedSign node to get polygon facing input (1,-1).
4. Connect the TwoSidedSign node’s output to a Clamp node to clamp the values to (1,0).
5. Connect the Clamp node’s output to a 1-X node to invert the facing input.
6. Connect the 1-X node’s output to the material’s Opacity Mask input so that polygons facing the camera will be invisible.

Related:

## Cycles render – Using the Normal Blue channel for top side effects

Software:
Blender 2.8 | Cycles Render

The shading normal‘s Z component can be easily used as a ready-to-use procedural mask for ‘covering effects’ like dust, snow, and if baked, also as a base for particle effects like debris and vegetation.

This simple shading flow example the shading normal‘sÂ Z component, that represents how much the surface is facing upwards is separated , mixed (multiplied) with a noise textured and than fed into a ColorRamp Converter node for fine tuning the resulting mask:

This is the full shading flow of the snow effect in the image above:

## UE4 – Bump Map

Software:
Unreal Engine 4.21

To use a ‘Bump Texture’ in UE4, or in more geeky terms, derive Normal data from a supplied height map, use the NormalFromHeightMap Node.

Notes:

1. The height map textured is supplied via Texture Object node and not Texture Sample, and is connected to the NormalFromHeightMap‘s Height Map input.
2. A numeric vale is connected to the NormalFromHeightMap‘s Normal Map Intensity input to control the intensity of the resulting Normals/Bump.
3. UV coordinates for the bump map should be connected to the Coordinates input of the NormalFromHeightMap node.