The **Math_Hall** map inside the Content Examples project aims to give you more of an understanding of how math is used within Unreal Engine 4 inside of **Blueprints** and **Materials**.

The first section entitled **Functions**, covers Math and Material Functions (left side of the wall) and example usage cases (right side of the wall). This section is excellent for learning more about blending Materials as well as how logic can be applied to Materials to create events like rippling water or bouncing balls entirely inside the **Material Editor**.

The second section covers **Vector Math** and describes the various types of Vectors and how they are used in Materials as well as their importance as it relates to Blueprints (e.g. making objects face the player, checking if players are looking towards something or finding out how far the player is from an object).

Listed below are the examples provided in the **Functions** section, example use cases can be found along the right side of the wall.

Example | What is Demonstrated |
---|---|

| Describes how to read each chart in this section where each chart plots the value of X for various math functions. |

| Obtaining the Absolute (ABS value of X where negative values are read as positive values (e.g. By taking the Sine of Time and getting the ABS value, a bouncing motion is created for a ball). |

| Using the Frac function to remove the integer part of any number which is useful for pseudo random number generation (e.g. the value of Raw Time is shown counting upwards extending past 1, Frac is used to express the 0 to 1 time that increments the Raw Time value). |

| Floor removes the fraction from any number keeping only the integer (e.g. where 0.9 becomes 0 or 1.9 becomes 1, etc.). |

| Ceil works just like floor but rounds up instead of down. The result of ceil is always 1 greater than floor (e.g. 0.1 becomes 1, 1.1 becomes 2, etc. An example of creating a Mosaic is also provided). |

| FMod stands for Floating Modulus and has both A and B inputs. It divides A by B and returns the remainder (e.g. an example is provided for generating a stripe pattern on a material). |

| Power takes a base input and applies an exponent. Negative values become positive just like ABS and a power of 1 will give the same result as ABS (e.g. an example is given to adjust the contrast of a texture). |

| Linear Interpolation (Lerp) returns a blend between the A and B inputs based on the alpha input. In the given example, when the alpha is 0, 100% of A will be returned. When the alpha is 1, 100% of B is returned (e.g. an example of using Lerp to blend between two textures is given). |

| HeightLerp is a Lerp that modulates the blend using a heightmap (e.g. an example is given where the heightmap of a texture is used to blend between two textures where a grass texture blends into a cobblestone texture). |

| Clamp is used to clamp the input value to the specified Min and Max Range (e.g. using clamp to specify a min/max view angle on a security camera). |

| Sine is a function of an angle and represents a ratio between the sides of a right triangle (e.g. Sine has a variety of applications and can create swaying motions inside Blueprints or Materials; it can also be used to make "waves" in water). |

| Cosine is another trigonometric function like Sine. It represents the ratio between the lengths of the sides in a right triangle. Cosine is the ratio between the side adjacent an angle and the hypotenuse (e.g. Sine and Cosine are very similar when used to make waves as seen in the example provided). |

| OneMinus can be used to get the inverse value of something like a texture or image (e.g. an example is shown where a black-and-white logo is inverted to a white-and-black logo). |

| Exponential Density creates a gradient with a smooth curve at both ends (e.g. it is most commonly used for creating the density in fog but can have other uses). |

| Sphere Mask has A and B inputs, as well as Radius and Hardness inputs and gets the distance between A and B (e.g. an example is shown where the hardness of a blend between textures is performed). |

| Sphere Gradient - 2D is a Material function that returns the sphere shaped falloff and takes V2 input coordinates, CenterPosition and scalar radius values (e.g. an example is shown how a material with a bevel shape is constructed). |

Listed below are the examples provided in the **Basic Vector Math** section.

Example | What is Demonstrated |
---|---|

| Describes the importance of Vector Math in Materials and Blueprints. |

| Explains what a Vector is and the types of vectors. |

| Basic 1D Vector using a roadmap analogy. |

| Explanation of a 2D Vector using a 2D graph. |

| How Distance is calculated using the Pythagorean Theorem (Note: Distance is automatically calculated in Materials and Blueprints). |

| Distance being calculated in a Blueprint and Material. |

| Visual demonstration of a 3D Vector using a 3D grid. |

| Using Normalized Vectors with Normalize nodes that can be found in Blueprints or Materials. |

| Converting a Vector into a Rotation value (e.g. a character that rotates towards the player's position is shown). |

| World Position and how to use the data (e.g. an object's world position is updated as it is dragged around in the editor). |

| Using World Aligned Texture to blend a texture around a sphere (e.g. this is useful for creating more natural looking rock materials). |

| A CameraVector is shown with a diagram illustrating vector paths. |

| CameraForwardVector is shown with a diagram illustrating forward vector paths. |

| An explanation of Dot Product is given which can be used to check if the player is looking at a specific point. |

| How to derive the dot product (Note: In Unreal Engine 4, a dot product is almost always solved using a node). |

| A CameraVector and Dot Product where a Material blends between colors based on player distance to an object as well as tracks player movement (Note: This is done entirely in the Material without a Blueprint). |

| A CameraForwardVector and Dot Product is used to determine if the player is looking at an object (Note: This is done entirely in the Material without a Blueprint). |

| Usage of Cross Product with a diagram illustrating how a cross product can be derived by reading vector values. |

| CreateThirdOrthogonalVector Material function and how it is useful for creating a full set of orthogonal (perpendicular) vectors is shown. |

| CameraPosition - ObjectPosition is shown to create the effect of objects rotating to face the player (e.g. in this example when standing in front of several objects, the objects directly in front of the player do not rotate, while objects to the left or right of the player rotate inward). |

| Camera Left Vector and Camera Up Vector are used to create the effect of objects rotating to face the player (e.g. in this example, unlike 2.20, the objects on the outside do not rotate inward as they all rotate in unison). |

| Sine, Cosine and Tangent as it relates to solving a right triangle where knowing any two sides can tell you the Angle of X (e.g. Our House is A House Of Animals mnemonic is explained as each capital letter stands for one of the triangle sides). |