lerp
Keywords: lerp, NVIDIA, NVIDIA Cg Toolkit, Cg Toolkit, Shader, Shader Programming, GPU Shader Programming, GPU Program

> ## Name

> lerp - returns linear interpolation of two scalars or vectors based on a weight

> ## Synopsis

>     float  lerp(float a, float b, float w);
>     float1 lerp(float1 a, float1 b, float1 w);
>     float2 lerp(float2 a, float2 b, float2 w);
>     float3 lerp(float3 a, float3 b, float3 w);
>     float4 lerp(float4 a, float4 b, float4 w);

>     float1 lerp(float1 a, float1 b, float w);
>     float2 lerp(float2 a, float2 b, float w);
>     float3 lerp(float3 a, float3 b, float w);
>     float4 lerp(float4 a, float4 b, float w);

>     half   lerp(half a, half b, half w);
>     half1  lerp(half1 a, half1 b, half1 w);
>     half2  lerp(half2 a, half2 b, half2 w);
>     half3  lerp(half3 a, half3 b, half3 w);
>     half4  lerp(half4 a, half4 b, half4 w);

>     half1  lerp(half1 a, half1 b, half w);
>     half2  lerp(half2 a, half2 b, half w);
>     half3  lerp(half3 a, half3 b, half w);
>     half4  lerp(half4 a, half4 b, half w);

>     fixed  lerp(fixed a, fixed b, fixed w);
>     fixed1 lerp(fixed1 a, fixed1 b, fixed1 w);
>     fixed2 lerp(fixed2 a, fixed2 b, fixed2 w);
>     fixed3 lerp(fixed3 a, fixed3 b, fixed3 w);
>     fixed4 lerp(fixed4 a, fixed4 b, fixed4 w);

>     fixed1 lerp(fixed1 a, fixed1 b, fixed w);
>     fixed2 lerp(fixed2 a, fixed2 b, fixed w);
>     fixed3 lerp(fixed3 a, fixed3 b, fixed w);
>     fixed4 lerp(fixed4 a, fixed4 b, fixed w);

> ## Parameters

> a
>   Vector or scalar to weight; returned when w is zero.
> b
>   Vector or scalar to weight; returned when w is one.
> w
>   Vector or scalar weight.

> ## Description

> Returns the linear interpolation of a and b based on weight w.

> a and b are either both scalars or both vectors of the same length. The weight w may be a scalar or a vector of the same length as a and b. w can be any value (so is not restricted to be between zero and one); if w has values outside the [0,1] range, it actually extrapolates.

> lerp returns a when w is zero and returns b when w is one.

> ## Reference Implementation

> lerp for float3 vectors for a and b and a float w could be implemented like this:

>     float3 lerp(float3 a, float3 b, float w)
>     {
>       return a + w*(b-a);
>     }

> ## Profile Support

> lerp is supported in all profiles.

> ## See Also

> saturate, smoothstep, step