Cg Toolkit Cg 3.1 Toolkit Documentation

Name

clamp - returns smallest integer not less than a scalar or each vector component.

Synopsis

float  clamp(float x, float a, float b);
float1 clamp(float1 x, float1 a, float1 b);
float2 clamp(float2 x, float2 a, float2 b);
float3 clamp(float3 x, float3 a, float3 b);
float4 clamp(float4 x, float4 a, float4 b);

half   clamp(half x, half a, half b);
half1  clamp(half1 x, half1 a, half1 b);
half2  clamp(half2 x, half2 a, half2 b);
half3  clamp(half3 x, half3 a, half3 b);
half4  clamp(half4 x, half4 a, half4 b);

fixed  clamp(fixed x, fixed a, fixed b);
fixed1 clamp(fixed1 x, fixed1 a, fixed1 b);
fixed2 clamp(fixed2 x, fixed2 a, fixed2 b);
fixed3 clamp(fixed3 x, fixed3 a, fixed3 b);
fixed4 clamp(fixed4 x, fixed4 a, fixed4 b);

float1 clamp(float1 x, float a, float b);
float2 clamp(float2 x, float a, float b);
float3 clamp(float3 x, float a, float b);
float4 clamp(float4 x, float a, float b);

half1  clamp(half1 x, half a, half b);
half2  clamp(half2 x, half a, half b);
half3  clamp(half3 x, half a, half b);
half4  clamp(half4 x, half a, half b);

fixed1 clamp(fixed1 x, fixed a, fixed b);
fixed2 clamp(fixed2 x, fixed a, fixed b);
fixed3 clamp(fixed3 x, fixed a, fixed b);
fixed4 clamp(fixed4 x, fixed a, fixed b);

Parameters

x
Vector or scalar to clamp.
a
Vector or scalar for bottom of clamp range.
b
Vector or scalar for top of clamp range.

Description

Returns x clamped to the range [a,b] as follows:

1) Returns a if x is less than a; else
2) Returns b if x is greater than b; else
3) Returns x otherwise.

For vectors, the returned vector contains the clamped result of each element of the vector x clamped using the respective element of vectors a and b.

Reference Implementation

clamp for float scalars could be implemented like this.

float clamp(float x, float a, float b)
{
  return max(a, min(b, x));
}

Profile Support

clamp is supported in all profiles except fp20.

See Also

max, min, saturate


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