# lerp in shader doesn't work as imagined?

Hey, so I’m using lerp in a displacement/tessellation/paralax shader and I’m trying to pulsate between a minimum and maximum float value using _SinTime like this:

``````_DisplacementAmount = lerp(_MinDisplacement,_MaxDisplacement, _SinTime.w*_PulseSpeed);
``````

However influencing _SinTime in anyway (for example multiplying by _PulseSpeed), doesn’t make the process go faster/slower, but instead increases/decreases the maximum and minimum values. I know Mathf.Lerp in Unity C# uses a 0-1 value to interpolate between two values, but this seems to work in a different manner?

Does anyone know why it does this or what the proper way to use it is?

Lerp works everywhere the same way. If it doesn’t it’s not linear interpolation.

The behaviour you see is absolute correct. Lerp requires a value between 0 and 1. When you multiply _SinTime.w by a value you change that range. Of course this doesn’t change the speed of the sine wave.

_SinTime contains 4 values which are

``````_SinTime.x = Mathf.Sin(Time.time / 8);
_SinTime.y = Mathf.Sin(Time.time / 4);
_SinTime.z = Mathf.Sin(Time.time / 2);
_SinTime.w = Mathf.Sin(Time.time);
``````

If you want to change the frequency of the sine wave you have to change the “time” value inside the sin method. _SinTime just provides 4 predefined values with 4 different constant frequencies (8Hz, 4Hz, 2Hz, 1Hz)

If you want to control the frequency with a parameter you have to do this in your shader:

``````DisplacementAmount = lerp(_MinDisplacement,_MaxDisplacement, sin(_Time.y *_PulseSpeed));
``````