Summary: Demonstration of using Lerp function in Unity’s and Unreal’s shader editors.
Linear Interpolation commonly used in Game development code can also be used in Shaders. LERP uses a value as the control, to go from one point to another.
These points could be anything we want to go back and forth from. Any 2 two of a kind values like Colors, Textures. Let’s use these examples in Unity and Unreal. Since Lerp is a common function used in Shaders you could just use the pre-made Lerp function. Or if you want to know how it works, you could make the formula for Lerp.
In both the demos I first create a Lerp function. Then I delete it and use the in-built Lerp function already provided with each game engine.
Unity
We will use Unity’s Shader graph to make a shader that Lerps between to colors.
Follow the video for a quick tutorial on how to make or use the pre-built function for Lerp.
Here is the graph for the Lerp function in Unity.
You can also use the in-built Lerp function.
Unreal
We will use Unreal’s Shader editor to make a shader that Lerps between to textures.
Follow the video for a quick tutorial on how to make or use the pre-built function for Lerp.
Here is the graph for the Lerp function in Unreal.
You can also use the in-built Lerp function.
Limitations and important information to know about LERP
In math calculations, the Lerp doesn’t really reach it’s final destinations ever. Only goes very close to it. If A to B is 0 to 1. Then the maximum value of B using Lerp will be around 0.999. Never reaching 1. So the correct visual representation of Lerp is a gradient slider that never really reaches either of the extreme values.
Fortunately in practical use, these limitations hardly cause any hindrances. But it’s always good to know, when that one random nonsense thing happens and you don’t know what’s causing it! Check your Lerp values!