Cg Toolkit Cg 3.1 Toolkit Documentation

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


Cg Toolkit | Cg Toolkit | Download | Release Archive | Profiles | Reference | Books | Discussions |


Cg Standard Library

abs
acos
all
any
asin
atan2
atan
bitCount
bitfieldExtract
bitfieldInsert
bitfieldReverse
ceil
clamp
clip
cosh
cos
cross
ddx
ddy
degrees
determinant
distance
dot
exp2
exp
faceforward
findLSB
findMSB
floatToIntBits
floatToRawIntBits
floor
fmod
frac
frexp
fwidth
intBitsToFloat
inverse
isfinite
isinf
isnan
ldexp
length
lerp
lit
log10
log2
log
max
min
modf
mul
normalize
pack
pow
radians
reflect
refract
round
rsqrt
saturate
sign
sincos
sinh
sin
smoothstep
sqrt
step
tanh
tan
tex1DARRAYbias
tex1DARRAYcmpbias
tex1DARRAYcmplod
tex1DARRAYfetch
tex1DARRAYlod
tex1DARRAY
tex1DARRAYproj
tex1DARRAYsize
tex1Dbias
tex1Dcmpbias
tex1Dcmplod
tex1Dfetch
tex1Dlod
tex1D
tex1Dproj
tex1Dsize
tex2DARRAYbias
tex2DARRAYfetch
tex2DARRAYlod
tex2DARRAY
tex2DARRAYproj
tex2DARRAYsize
tex2Dbias
tex2Dcmpbias
tex2Dcmplod
tex2Dfetch
tex2Dlod
tex2DMSARRAYfetch
tex2DMSARRAYsize
tex2DMSfetch
tex2DMSsize
tex2D
tex2Dproj
tex2Dsize
tex3Dbias
tex3Dfetch
tex3Dlod
tex3D
tex3Dproj
tex3Dsize
texBUF
texBUFsize
texCUBEARRAYbias
texCUBEARRAYlod
texCUBEARRAY
texCUBEARRAYsize
texCUBEbias
texCUBElod
texCUBE
texCUBEproj
texCUBEsize
texRBUF
texRBUFsize
texRECTbias
texRECTfetch
texRECTlod
texRECT
texRECTproj
texRECTsize
transpose
trunc
unpack