lerp

float value = lerp(a, b, v);

Lerp does a linear interpolate between two values.

The cg documentation defines the implementation as equivalent to:

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

Effectively, the range of the function is (b - a) and w is a weight factor applied.

The important thing to understand here is that lerp(0, 1, 0.5) = 0.5, but lerp(0, 10, 5) = 50.

That is, lerp returns an actual value, not a fractional value between 0 and 1.

The lerp supports both simple float values and vector values such as float2, float3 and float4. This makes it particularly useful to generating new procedural color values and lighting.

Rescaling values using lerp

It's tempting to try to use lerp to rescale values, but it's not the correct tool for this purpose.

For example, consider a rim lighting shader:

// Calculate the angle between the poly and view normals
float diff = 1.0 - dot(IN.worldNormal, IN.viewDir);

// Cutoff the rim lighting at RIM
diff = step(RIM, diff) * diff;

// Sample the texutre
float3 rgb = tex2D(_MainTex, IN.uv_MainTex).rgb;

// Apply colored rim to the output
o.Albedo = float3(diff) * _Color + rgb;

It may be tempting to attempt to use lerp to rescale the diff to the range 0 - RIM using lerp:

diff = step(RIM, diff) * diff;
diff = lerp(???); // Convert [1:RIM] -> [1:0]

However, the correct calculation is actually:

diff = step(RIM, diff) * (diff - RIM) / RIM;

Don't use lerp for this purpose.