Difference between revisions of "Cg functions"

From Wikiid
Jump to: navigation, search
(Texture Mapping)
(Functions)
 
(2 intermediate revisions by the same user not shown)
Line 2: Line 2:
  
 
== Functions ==
 
== Functions ==
{|
+
{| border="1" cellspacing="0" cellpadding="5" align="center"
! Function
+
! Function !! Description
! Description
+
 
|-
 
|-
| ''' <tt>abs(</tt> '' <tt>x</tt> '' <tt>)</tt> '''
+
| abs( x ) || Absolute value of x .
| Absolute value of ''' '' <tt>x</tt> '' '''.
+
 
|-
 
|-
| ''' <tt>acos(</tt> '' <tt>x</tt> '' <tt>)</tt> '''
+
| acos( x ) || Arccos of x in range [0, pi], x in [-1, 1].
| Arccosine of ''' '' <tt>x</tt> '' ''' in range [0, <font face="symbol">p</font>], ''' '' <tt>x</tt> '' ''' in [–1, 1].
+
 
|-
 
|-
| ''' <tt>all(</tt> '' <tt>x</tt> '' <tt>)</tt> '''
+
| all( x ) || true if '''all''' components of x != 0 - false otherwise.
| Returns ''' <tt>true</tt> ''' if every component of ''' '' <tt>x</tt> '' ''' is not equal to 0. Returns ''' <tt>false</tt> ''' otherwise.
+
 
|-
 
|-
| ''' <tt>any(</tt> '' <tt>x</tt> '' <tt>)</tt> '''
+
| any( x ) || true if '''any''' component of x != 0 - false otherwise.
| Returns ''' <tt>true</tt> ''' if any component of ''' '' <tt>x</tt> '' ''' is not equal to 0. Returns ''' <tt>false</tt> ''' otherwise.
+
 
|-
 
|-
| ''' <tt>asin(</tt> '' <tt>x</tt> '' <tt>)</tt> '''
+
| asin( x ) || Arcsin of x in range [-pi/2,pi/2]; x in [-1, 1].
| Arcsine of ''' '' <tt>x</tt> '' ''' in range [–<font face="symbol">p</font>/2, <font face="symbol">p</font>/2]; ''' '' <tt>x</tt> '' ''' should be in [–1, 1].
+
 
|-
 
|-
| ''' <tt>atan(</tt> '' <tt>x</tt> '' <tt>)</tt> '''
+
| atan( x ) ||| Arctan of x in range [-pi/2, pi/2].
| Arctangent of ''' '' <tt>x</tt> '' ''' in range [–<font face="symbol">p</font>/2, <font face="symbol">p</font>/2].
+
 
|-
 
|-
| ''' <tt>atan2(</tt> '' <tt>y</tt> '' <tt>,</tt> '' <tt>x</tt> '' <tt>)</tt> '''
+
| atan2( y , x ) || Arctan y/x in range [-pi,pi].
| Arctangent of ''' '' <tt>y</tt> ''/'' <tt>x</tt> '' ''' in range [–<font face="symbol">p</font>, <font face="symbol">p</font>].
+
 
|-
 
|-
| ''' <tt>ceil(</tt> '' <tt>x</tt> '' <tt>)</tt> '''
+
| ceil( x ) || Smallest integer not less than x .
| Smallest integer not less than ''' '' <tt>x</tt> '' '''.
+
 
|-
 
|-
| ''' <tt>clamp(</tt> '' <tt>x</tt> '' <tt>,</tt> '' <tt>a</tt> '' <tt>,</tt> '' <tt>b</tt> '' <tt>)</tt> '''
+
| clamp( x , a , b ) || x clamped to the range [a,b]: a if x<ab if x>b else returns x.
| ''' '' <tt>x</tt> '' ''' clamped to the range [''' '' <tt>a</tt> '' <tt>,</tt> '' <tt>b</tt> '' '''] as follows: Returns ''' '' <tt>a</tt> '' ''' if ''' '' <tt>x</tt> '' ''' is less than ''' '' <tt>a</tt> '' '''. Returns ''' '' <tt>b</tt> '' ''' if ''' '' <tt>x</tt> '' ''' is greater than ''' '' <tt>b</tt> '' '''. Returns ''' '' <tt>x</tt> '' ''' otherwise.
+
 
|-
 
|-
| ''' <tt>cos(</tt> '' <tt>x</tt> '' <tt>)</tt> '''
+
| cos( x ) || Cos of x.
| Cosine of ''' '' <tt>x</tt> '' '''.
+
 
|-
 
|-
| ''' <tt>cosh(</tt> '' <tt>x</tt> '' <tt>)</tt> '''
+
| cosh( x ) || Hyperbolic cos of x .
| Hyperbolic cosine of ''' '' <tt>x</tt> '' '''.
+
 
|-
 
|-
| ''' <tt>cross(</tt> '' <tt>A</tt> '' <tt>,</tt> '' <tt>B</tt> '' <tt>)</tt> '''
+
| cross( A , B ) || Cross product of vectors A and B (A and B must be three-component).
| Cross product of vectors ''' '' <tt>A</tt> '' ''' and ''' '' <tt>B</tt> '' '''<nowiki>;</nowiki> ''' '' <tt>A</tt> '' ''' and ''' '' <tt>B</tt> '' ''' must be three-component vectors.
+
 
|-
 
|-
| ''' <tt>ddx(</tt> '' <tt>a</tt> '' <tt>)</tt> '''
+
| ddx( a ) || Partial derivative of a with respect to screen-space x coordinate
| Approximate partial derivative of ''' '' <tt>a</tt> '' ''' with respect to screen-space ''' '' <tt>x</tt> '' ''' coordinate
+
 
|-
 
|-
| ''' <tt>ddy(</tt> '' <tt>a</tt> '' <tt>)</tt> '''
+
| ddy( a ) || Partial derivative of a with respect to screen-space y coordinate
| Approximate partial derivative of ''' '' <tt>a</tt> '' ''' with respect to screen-space ''' '' <tt>y</tt> '' ''' coordinate
+
 
|-
 
|-
|''' <tt>void debug(float4</tt> '' <tt>x</tt> '' <tt>)</tt> '''
+
| debug(float4 x) || If compiler DEBUG option is enabled, causes shader to halt with x copied to the COLOR output - otherwise it does nothing.
| If the compiler's ''' <tt>DEBUG</tt> ''' option is enabled, calling this function causes the value ''' '' <tt>x</tt> '' ''' to be copied to the ''' <tt>COLOR</tt> ''' output of the program, and execution of the program is terminated. If the compiler's ''' <tt>DEBUG</tt> ''' option is not enabled, this function does nothing.
+
 
|-
 
|-
| ''' <tt>degrees(</tt> '' <tt>x</tt> '' <tt>)</tt> '''
+
| degrees( x ) || convert radians to degrees.
| Radian-to-degree conversion.
+
 
|-
 
|-
| ''' <tt>determinant(</tt> '' <tt>M</tt> '' <tt>)</tt> '''
+
| determinant( x ) || Determinant of matrix x.
| Determinant of matrix ''' '' <tt>M</tt> '' '''.
+
 
|-
 
|-
| ''' <tt>distance(</tt> '' <tt>pt1</tt> '' <tt>,</tt> '' <tt>pt2</tt> '' <tt>)</tt> '''
+
| distance( p1 , p2 ) || Pythagorean distance between p1 and p2.
| Euclidean distance between points ''' '' <tt>pt1</tt> '' ''' and ''' '' <tt>pt2</tt> '' '''.
+
 
|-
 
|-
| ''' <tt>dot(</tt> '' <tt>A</tt> '' <tt>,</tt> '' <tt>B</tt> '' <tt>)</tt> '''
+
| dot( A, B ) || Dot product of A and B.
| Dot product of vectors ''' '' <tt>A</tt> '' ''' and ''' '' <tt>B</tt> '' '''.
+
 
|-
 
|-
| ''' <tt>exp(</tt> '' <tt>x</tt> '' <tt>)</tt> '''
+
| exp( x ) || Exponential func: e<sup>x</sup>.
| Exponential function e''' '' <tt> <sup>x</sup> </tt> '' '''.
+
 
|-
 
|-
| ''' <tt>exp2(</tt> '' <tt>x</tt> '' <tt>)</tt> '''
+
| exp2( x ) || Exponential function 2<sup>x</sup>.
| Exponential function 2''' '' <tt> <sup>x</sup> </tt> '' '''.
+
 
|-
 
|-
| ''' <tt>faceforward(</tt> '' <tt>N</tt> '' <tt>,</tt> '' <tt>I</tt> '' <tt>,</tt> '' <tt>Ng</tt> '' <tt>)</tt> '''
+
| faceforward( N, I, Ng ) || N if dot( Ng , I ) < 0 otherwise (-N).
| ''' '' <tt>N</tt> '' ''' if ''' <tt>dot(</tt> '' <tt>Ng</tt> '' <tt>,</tt> '' <tt>I</tt> '' <tt>)</tt> ''' < 0; ''' <tt>-</tt> '' <tt>N</tt> '' ''' otherwise.
+
 
|-
 
|-
| ''' <tt>floor(</tt> '' <tt>x</tt> '' <tt>)</tt> '''
+
| floor( x ) || Largest integer not greater than x.
| Largest integer not greater than ''' '' <tt>x</tt> '' '''.
+
 
|-
 
|-
| ''' <tt>fmod(</tt> '' <tt>x</tt> '' <tt>,</tt> '' <tt>y</tt> '' <tt>)</tt> '''
+
| fmod( x , y ) || Remainder of x/y (with the same sign as x). If y==0, result is undefined.
| Remainder of ''' '' <tt>x</tt> ''/'' <tt>y</tt> '' ''', with the same sign as ''' '' <tt>x</tt> '' '''. If ''' '' <tt>y</tt> '' ''' is 0, the result is implementation-defined.
+
 
|-
 
|-
| ''' <tt>frac(</tt> '' <tt>x</tt> '' <tt>)</tt> '''
+
| frac( x ) || Fractional part of x.
| Fractional part of ''' '' <tt>x</tt> '' '''.
+
 
|-
 
|-
| ''' <tt>frexp(</tt> '' <tt>x</tt> '' <tt>, out</tt> '' <tt>exp</tt> '' <tt>)</tt> '''
+
| frexp( x , out exp ) || Splits x into normalized fraction in the interval [, 1), which is returned, and a power of 2, which is stored in exp . If x==0, both parts of the result are 0.
| Splits ''' '' <tt>x</tt> '' ''' into a normalized fraction in the interval [½, 1), which is returned, and a power of 2, which is stored in ''' '' <tt>exp</tt> '' '''. If ''' '' <tt>x</tt> '' ''' is 0, both parts of the result are 0.
+
 
|-
 
|-
| ''' <tt>isfinite(</tt> '' <tt>x</tt> '' <tt>)</tt> '''
+
| isfinite( x ) || Returns true if x is finite.
| Returns ''' <tt>true</tt> ''' if ''' '' <tt>x</tt> '' ''' is finite.
+
 
|-
 
|-
| ''' <tt>isinf(</tt> '' <tt>x</tt> '' <tt>)</tt> '''
+
| isinf( x ) || Returns true if x is infinite.
| Returns ''' <tt>true</tt> ''' if ''' '' <tt>x</tt> '' ''' is infinite.
+
 
|-
 
|-
| ''' <tt>isnan(</tt> '' <tt>x</tt> '' <tt>)</tt> '''
+
| isnan( x ) || Returns true if x is NaN.
| Returns ''' <tt>true</tt> ''' if ''' '' <tt>x</tt> '' ''' is NaN (Not a Number).
+
 
|-
 
|-
| ''' <tt>ldexp(</tt> '' <tt>x</tt> '' <tt>,</tt> '' <tt>n</tt> '' <tt>)</tt> '''
+
| ldexp( x , n ) || x * 2<sup>n</sup>.
| ''' '' <tt>x</tt> '' ''' x 2''' '' <tt> <sup>n</sup> </tt> '' '''.
+
 
|-
 
|-
| ''' <tt>length(</tt> '' <tt>v</tt> '' <tt>)</tt> '''
+
| length( v ) || Pythagorean length of vector.
| Euclidean length of a vector.
+
 
|-
 
|-
| ''' <tt>lerp(</tt> '' <tt>a</tt> '' <tt>,</tt> '' <tt>b</tt> '' <tt>,</tt> '' <tt>f</tt> '' <tt>)</tt> '''
+
| lerp( a , b , f ) || Linear interpolation: (1 - f)* a + b * f. f can be a vector of same length as a & b.
| Linear interpolation: ''' <tt>(1 –</tt> '' <tt>f</tt> '' <tt>)*</tt> '' <tt>a</tt> '' <tt>+</tt> '' <tt>b</tt> '' <tt><nowiki>*</nowiki></tt> '' <tt>f</tt> '' ''' where ''' '' <tt>a</tt> '' ''' and ''' '' <tt>b</tt> '' ''' are matching vector or scalar types. ''' '' <tt>f</tt> '' ''' can be either a scalar or a vector of the same type as ''' '' <tt>a</tt> '' ''' and ''' '' <tt>b</tt> '' '''.
+
 
|-
 
|-
| ''' <tt>lit(</tt> '' <tt>NdotL</tt> '' <tt>,</tt> '' <tt>NdotH</tt> '' <tt>,</tt> '' <tt>m</tt> '' <tt>)</tt> '''
+
| lit( NdotL , NdotH , m ) || Computes lighting coefficients (m is the shininess). Returns: float4: .x=ambient (always 1), .y=diffuse (0 if N.L < 0), .z=specular (0 if N.L<0 or N.H<0); .w==1.0.
| Computes lighting coefficients for ambient, diffuse, and specular light contributions. Expects the ''' '' <tt>NdotL</tt> '' ''' parameter to contain ''' '' <tt>N</tt> '' ''' • ''' '' <tt>L</tt> '' ''' and the ''' '' <tt>NdotH</tt> '' ''' parameter to contain ''' '' <tt>N</tt> '' ''' • ''' '' <tt>H</tt> '' '''. Returns a four-component vector as follows: The ''' '' <tt>x</tt> '' ''' component of the result vector contains the ambient coefficient, which is always 1.0. The ''' '' <tt>y</tt> '' ''' component contains the diffuse coefficient, which is 0 if (''' '' <tt>N</tt> '' ''' • ''' '' <tt>L</tt> '' ''') < 0; otherwise (''' '' <tt>N</tt> '' ''' • ''' '' <tt>L</tt> '' '''). The ''' '' <tt>z</tt> '' ''' component contains the specular coefficient, which is 0 if either (''' '' <tt>N</tt> '' ''' • ''' '' <tt>L</tt> '' ''') < 0 or (''' '' <tt>N</tt> '' ''' • ''' '' <tt>H</tt> '' ''') < 0; (''' '' <tt>N</tt> '' ''' • ''' '' <tt>H</tt> '' ''')''' '' <tt> <sup>m</sup> </tt> '' ''' otherwise. The ''' <tt>w</tt> ''' component is 1.0. There is no vectorized version of this function.
+
 
|-
 
|-
| ''' <tt>log(</tt> '' <tt>x</tt> '' <tt>)</tt> '''
+
| log( x ) || Natural logarithm (x>0).
| Natural logarithm''' <tt>ln(</tt> '' <tt>x</tt> '' <tt>)</tt> '''<nowiki>; </nowiki>''' '' <tt>x</tt> '' ''' must be greater than 0.
+
 
|-
 
|-
| ''' <tt>log2(</tt> '' <tt>x</tt> '' <tt>)</tt> '''
+
| log2( x ) || Log Base 2 (x>0).
| Base 2 logarithm of ''' '' <tt>x</tt> '' '''<nowiki>; </nowiki>''' '' <tt>x</tt> '' ''' must be greater than 0.
+
 
|-
 
|-
| ''' <tt>log10(</tt> '' <tt>x</tt> '' <tt>)</tt> '''
+
| log10( x ) || Log Base 10 (x>0).
| Base 10 logarithm of ''' '' <tt>x</tt> '' '''<nowiki>; </nowiki>''' '' <tt>x</tt> '' ''' must be greater than 0.
+
 
|-
 
|-
| ''' <tt>max(</tt> '' <tt>a</tt> '' <tt>,</tt> '' <tt>b</tt> '' <tt>)</tt> '''
+
| max( a , b ) || Maximum of a and b .
| Maximum of ''' '' <tt>a</tt> '' ''' and ''' '' <tt>b</tt> '' '''.
+
 
|-
 
|-
| ''' <tt>min(</tt> '' <tt>a</tt> '' <tt>,</tt> '' <tt>b</tt> '' <tt>)</tt> '''
+
| min( a , b ) || Minimum of a and b .
| Minimum of ''' '' <tt>a</tt> '' ''' and ''' '' <tt>b</tt> '' '''.
+
 
|-
 
|-
| ''' <tt>modf(</tt> '' <tt>x</tt> '' <tt>, out</tt> '' <tt>ip</tt> '' <tt>)</tt> '''
+
| modf( x , out ip ) || Splits x into int and frac parts (each with the same sign as x). Stores the int part in ip and returns the fractional part.
| Splits ''' '' <tt>x</tt> '' ''' into integral and fractional parts, each with the same sign as ''' '' <tt>x</tt> '' '''. Stores the integral part in ''' '' <tt>ip</tt> '' ''' and returns the fractional part.
+
 
|-
 
|-
| ''' <tt>mul(</tt> '' <tt>M</tt> '' <tt>,</tt> '' <tt>N</tt> '' <tt>)</tt> '''
+
| mul( M , N ) || Matrix product of matrix M and matrix N: If M has size AxB, and N has size BxC, returns an AxC.
| Matrix product of matrix ''' '' <tt>M</tt> '' ''' and matrix ''' '' <tt>N</tt> '' ''', as shown below: If ''' '' <tt>M</tt> '' ''' has size ''' <tt>A</tt> ''' <tt>x</tt> ''' <tt>B</tt> ''', and ''' '' <tt>N</tt> '' ''' has size ''' <tt>B</tt> ''' <tt>x</tt> ''' <tt>C</tt> ''', returns a matrix of size ''' <tt>A</tt> ''' <tt>x</tt> ''' <tt>C</tt> '''.
+
 
|-
 
|-
| ''' <tt>mul(</tt> '' <tt>M</tt> '' <tt>,</tt> '' <tt>v</tt> '' <tt>)</tt> '''
+
| mul( M , v ) || Product of matrix M and column vector v: If M has size AxB, and v is Bx1, returns an Ax1.
| Product of matrix ''' '' <tt>M</tt> '' ''' and column vector ''' '' <tt>v</tt> '' ''', as shown below: If ''' '' <tt>M</tt> '' ''' is an ''' <tt>A</tt> ''' <tt>x</tt> ''' <tt>B</tt> ''' matrix and ''' '' <tt>v</tt> '' ''' is a ''' <tt>B</tt> ''' <tt>x</tt> ''' <tt>1</tt> ''' vector, returns an ''' <tt>A</tt> ''' <tt>x</tt> ''' <tt>1</tt> ''' vector.
+
 
|-
 
|-
| ''' <tt>mul(</tt> '' <tt>v</tt> '' <tt>,</tt> '' <tt>M</tt> '' <tt>)</tt> '''
+
| mul( v , M ) || Product of row vector v and matrix M: If v is a 1xA and M is AxB, returns a 1xB.
| Product of row vector ''' '' <tt>v</tt> '' ''' and matrix ''' '' <tt>M</tt> '' ''', as shown below: If ''' '' <tt>v</tt> '' ''' is a ''' <tt>1</tt> ''' <tt>x</tt> ''' <tt>A</tt> ''' vector and ''' '' <tt>M</tt> '' ''' is an ''' <tt>A</tt> ''' <tt>x</tt> ''' <tt>B</tt> ''' matrix, returns a ''' <tt>1</tt> ''' <tt>x</tt> ''' <tt>B</tt> ''' vector.
+
 
|-
 
|-
| ''' <tt>noise(</tt> '' <tt>x</tt> '' <tt>)</tt> '''
+
| noise( x ) || Noise function. The returned value is between 0 and 1, and is always the same for a given input value.
| Either a one-, two-, or three-dimensional noise function, depending on the type of its argument. The returned value is between 0 and 1, and is always the same for a given input value.
+
 
|-
 
|-
| ''' <tt>normalize(</tt> '' <tt>v</tt> '' <tt>)</tt> '''
+
| normalize( v ) || Normalize v.
| Returns a vector of length 1 that points in the same direction as vector ''' '' <tt>v</tt> '' '''.
+
 
|-
 
|-
| ''' <tt>pow(</tt> '' <tt>x</tt> '' <tt>,</tt> '' <tt>y</tt> '' <tt>)</tt> '''
+
| pow( x , y ) || x<sup>y</sup>
| ''' '' <tt>x<sup>y</sup> </tt> '' '''.
+
 
|-
 
|-
| ''' <tt>radians(</tt> '' <tt>x</tt> '' <tt>)</tt> '''
+
| radians( x ) || Converts degrees to radians.
| Degree-to-radian conversion.
+
 
|-
 
|-
| ''' <tt>reflect(</tt> '' <tt>I</tt> '' <tt>,</tt> '' <tt>N</tt> '' <tt>)</tt> '''
+
| reflect( I , N ) || Computes reflection of I in a plane with surface normal N. (three-component vectors only).
| Computes reflection vector from entering ray direction ''' '' <tt>I</tt> '' ''' and surface normal ''' '' <tt>N</tt> '' '''. Valid only for three-component vectors.
+
 
|-
 
|-
| ''' <tt>refract(</tt> '' <tt>I</tt> '' <tt>,</tt> '' <tt>N</tt> '' <tt>,</tt> '' <tt>eta</tt> '' <tt>)</tt> '''
+
| refract( I , N , eta ) || Computes refraction of I in a plane with surface normal N and refractive index eta. Returns (0,0,0) for total internal reflection. (three-component vectors only).
| Given entering ray direction ''' '' <tt>I</tt> '' ''', surface normal ''' '' <tt>N</tt> '' ''', and relative index of refraction ''' '' <tt>eta</tt> '' ''', computes refraction vector. If the angle between ''' '' <tt>I</tt> '' ''' and ''' '' <tt>N</tt> '' ''' is too large for a given ''' '' <tt>eta</tt> '' ''', returns (0, 0, 0). Valid only for three-component vectors.
+
 
|-
 
|-
| ''' <tt>round(</tt> '' <tt>x</tt> '' <tt>)</tt> '''
+
| round( x ) || Closest integer to x.
| Closest integer to ''' '' <tt>x</tt> '' '''.
+
 
|-
 
|-
| ''' <tt>rsqrt(</tt> '' <tt>x</tt> '' <tt>)</tt> '''
+
| rsqrt( x ) || Reciprocal square root of x (x>0).
| Reciprocal square root of ''' '' <tt>x</tt> '' '''<nowiki>; </nowiki>''' '' <tt>x</tt> '' ''' must be greater than 0.
+
 
|-
 
|-
| ''' <tt>saturate(</tt> '' <tt>x</tt> '' <tt>)</tt> '''
+
| saturate( x ) || Clamps x to [0, 1].
| Clamps ''' '' <tt>x</tt> '' ''' to the [0, 1] range.
+
 
|-
 
|-
| ''' <tt>sign(</tt> '' <tt>x</tt> '' <tt>)</tt> '''
+
| sign( x ) || Sign of x (returns -1, 0 or +1)
| 1 if ''' '' <tt>x</tt> '' ''' > 0; –1 if ''' '' <tt>x</tt> '' ''' < 0; 0 otherwise.
+
 
|-
 
|-
| ''' <tt>sin(</tt> '' <tt>x</tt> '' <tt>)</tt> '''
+
| sin( x ) || Sin of x.
| Sine of ''' '' <tt>x</tt> '' '''.
+
 
|-
 
|-
| ''' <tt>sincos(float</tt> '' <tt>x</tt> '' <tt>, out</tt> '' <tt>s</tt> '' <tt>, out</tt> '' <tt>c</tt> '' <tt>)</tt> '''
+
| sincos(float x , out s , out c ) || s is set to sin(x), and c to cos(x).
| ''' '' <tt>s</tt> '' ''' is set to the sine of ''' '' <tt>x</tt> '' ''', and ''' '' <tt>c</tt> '' ''' is set to the cosine of ''' '' <tt>x</tt> '' '''. If both ''' <tt>sin(</tt> '' <tt>x</tt> '' <tt>)</tt> ''' and ''' <tt>cos(</tt> '' <tt>x</tt> '' <tt>)</tt> ''' are needed, this function is more efficient than calculating each individually.
+
 
|-
 
|-
| ''' <tt>sinh(</tt> '' <tt>x</tt> '' <tt>)</tt> '''
+
| sinh( x ) || Hyperbolic sine of x.
| Hyperbolic sine of ''' '' <tt>x</tt> '' '''.
+
 
|-
 
|-
| ''' <tt>smoothstep(</tt> '' <tt>min</tt> '' <tt>,</tt> '' <tt>max</tt> '' <tt>,</tt> '' <tt>x</tt> '' <tt>)</tt> '''
+
| smoothstep( min , max , x ) || For values of x between min and max , returns a smoothly varying value that ranges from 0 at x==min to 1 at x==max. x is clamped to the range [min,max] and then returns 2*((x-min)/(max-min))<sup>3</sup>+3*((x-min)/(max-min))<sup>2</sup>
| For values of ''' '' <tt>x</tt> '' ''' between ''' '' <tt>min</tt> '' ''' and ''' '' <tt>max</tt> '' ''', returns a smoothly varying value that ranges from 0 at ''' '' <tt>x</tt> '' <tt><nowiki>=</nowiki></tt> '' <tt>min</tt> '' ''' to 1 at ''' '' <tt>x</tt> '' <tt><nowiki>=</nowiki></tt> '' <tt>max</tt> '' '''. ''' '' <tt>x</tt> '' ''' is clamped to the range [''' '' <tt>min</tt> '' <tt>,</tt> '' <tt>max</tt> '' '''] and then the interpolation formula is evaluated: ''' <tt>–2*((</tt> '' <tt>x</tt> '' <tt>–</tt> '' <tt>min</tt> '' <tt>)/(</tt> '' <tt>max</tt> '' <tt>–</tt> '' <tt>min</tt> '' <tt>))<sup>3</sup> +</tt> ''' ''' <tt>3*((</tt> '' <tt>x</tt> '' <tt>–</tt> '' <tt>min</tt> '' <tt>)/(</tt> '' <tt>max</tt> '' <tt>–</tt> '' <tt>min</tt> '' <tt>))<sup>2</sup> </tt> '''
+
 
|-
 
|-
| ''' <tt>step(</tt> '' <tt>a</tt> '' <tt>,</tt> '' <tt>x</tt> '' <tt>)</tt> '''
+
| step( a , x ) || 0 if x<a, 1 if x>=a
| 0 if ''' '' <tt>x</tt> '' ''' < ''' '' <tt>a</tt> '' '''<nowiki>;</nowiki> 1 if ''' '' <tt>x</tt> '' ''' >=''' '' <tt>a</tt> '' '''.
+
 
|-
 
|-
| ''' <tt>sqrt(</tt> '' <tt>x</tt> '' <tt>)</tt> '''
+
| sqrt( x ) || Square root of x (x>0)
| Square root of ''' '' <tt>x</tt> '' '''<nowiki>;</nowiki> ''' '' <tt>x</tt> '' ''' must be greater than 0.
+
 
|-
 
|-
| ''' <tt>tan(</tt> '' <tt>x</tt> '' <tt>)</tt> '''
+
| tan( x ) || Tan of x.
| Tangent of ''' '' <tt>x</tt> '' '''.
+
 
|-
 
|-
| ''' <tt>tanh(</tt> '' <tt>x</tt> '' <tt>)</tt> '''
+
| tanh( x ) || Hyperbolic tan of x.
| Hyperbolic tangent of ''' '' <tt>x</tt> '' '''.
+
 
|-
 
|-
| ''' <tt>transpose(</tt> '' <tt>M</tt> '' <tt>)</tt> '''
+
| tex1D(sampler1D tex , float s ) || 1D nonprojective texture lookup
| Matrix transpose of matrix ''' '' <tt>M</tt> '' '''.  If ''' '' <tt>M</tt> '' ''' is an ''' <tt>A</tt> ''' <tt>x</tt> ''' <tt>B</tt> ''' matrix, the transpose of ''' '' <tt>M</tt> '' ''' is a ''' <tt>B</tt> ''' <tt>x</tt> ''' <tt>A</tt> ''' matrix whose first column is the first row of ''' '' <tt>M</tt> '' ''', whose second column is the second row of ''' '' <tt>M</tt> '' ''', whose third column is the third row of ''' '' <tt>M</tt> '' ''', and so on.
+
|-
|}
+
| tex1D(sampler1D tex , float s , float dsdx , float dsdy ) || 1D nonprojective texture lookup with derivatives
 
+
|-
== Geometry Functions ==
+
| tex1D(sampler1D tex , float2 sz ) || 1D nonprojective depth compare texture lookup
 
+
|-
{|
+
| tex1D(sampler1D tex , float2 sz , float dsdx , float dsdy ) || 1D nonprojective depth compare texture lookup with derivatives
! Function
+
|-
! Description
+
| tex1Dproj(sampler1D tex , float2 sq ) || 1D projective texture lookup
|}
+
|-
 
+
| tex1Dproj(sampler1D tex , float3 szq ) || 1D projective depth compare texture lookup
== Texture Mapping ==
+
|-
 
+
| tex2D(sampler2D tex , float2 s ) || 2D nonprojective texture lookup
Only OpenGL profiles support the ''' <tt>samplerRECT</tt> ''' functions. All of the functions return a ''' <tt>float4</tt> ''' value.
+
|-
 
+
| tex2D(sampler2D tex , float2 s , float2 dsdx , float2 dsdy ) || 2D nonprojective texture lookup with derivatives
{|
+
|-
! Function
+
| tex2D(sampler2D tex , float3 sz ) || 2D nonprojective depth compare texture lookup
! Description
+
|-
 
+
| tex2D(sampler2D tex , float3 sz , float2 dsdx , float2 dsdy ) || 2D nonprojective depth compare texture lookup with derivatives
|}
+
|-
 
+
| tex2Dproj(sampler2D tex , float3 sq ) || 2D projective texture lookup
* ''' '' <tt>s</tt> '' ''' indicates a one-, two-, or three-component texture coordinate.
+
|-
* ''' '' <tt>z</tt> '' ''' indicates a depth comparison value for shadow map lookups.
+
| tex2Dproj(sampler2D tex , float4 szq ) || 2D projective depth compare texture lookup
* ''' '' <tt>q</tt> '' ''' indicates a perspective value, and is used to divide the texture coordinate (''' '' <tt>s</tt> '' ''') before the texture lookup is performed.
+
|-
 
+
| texRECT(samplerRECT tex , float2 s ) || 2D nonprojective texture rectangle texture lookup (OpenGL)
When you use the texture functions that allow specifying a depth comparison value, the associated texture unit must be configured for depth-compare texturing. Otherwise, no depth comparison will actually be performed.
+
|-
 
+
| texRECT(samplerRECT tex , float2 s , float2 dsdx , float2 dsdy ) || 2D nonprojective texture rectangle texture lookup with derivatives (OpenGL)
==E.4 Derivative Functions==
+
|-
 
+
| texRECT(samplerRECT tex , float3 sz ) || 2D nonprojective texture rectangle depth compare texture lookup (OpenGL)
Table E-4 presents the derivative functions that are supported by the Cg Standard Library. Vertex profiles do not support these functions.
+
|-
 
+
| texRECT(samplerRECT tex , float3 sz , float2 dsdx , float2 dsdy ) || 2D nonprojective depth compare texture lookup with derivatives (OpenGL)
====Table E-4. Derivative Functions====
+
|-
 
+
| texRECTproj(samplerRECT tex , float3 sq ) || 2D texture rectangle projective texture lookup (OpenGL)
{|
+
|-
!
+
| texRECTproj(samplerRECT tex , float3 szq ) || 2D texture rectangle projective depth compare texture lookup (OpenGL)
Function
+
|-
!
+
| tex3D(sampler3D tex , float3 s ) || 3D nonprojective texture lookup
Description
+
|-
 +
| tex3D(sampler3D tex , float3 s , float3 dsdx , float3 dsdy ) || 3D nonprojective texture lookup with derivatives
 +
|-
 +
| tex3Dproj(sampler3D tex , float4 sq ) || 3D projective texture lookup
 +
|-
 +
| texCUBE(samplerCUBE tex , float3 s ) || Cubemap nonprojective texture lookup
 +
|-
 +
| texCUBE(samplerCUBE tex , float3 s , float3 dsdx , float3 dsdy ) || Cubemap nonprojective texture lookup with derivatives
 +
|-
 +
| texCUBEproj(samplerCUBE tex , float4 sq ) || Cube map projective texture lookup (ignores q)
 
|-
 
|-
 +
| transpose( M ) || transpose of matrix M
 
|}
 
|}
  
==E.5 Debugging Function==
+
NOTES:
 
+
* s indicates a one-, two-, or three-component texture coordinate.
Table E-5 presents the debugging function that is supported by the Cg Standard Library. Vertex profiles are not required to support this function.
+
* z indicates a depth comparison value for shadow map lookups.
 
+
* q indicates a perspective value, and is used to divide the texture coordinate ( s ) before the texture lookup is performed.
====Table E-5. Debugging Function====
+
When you use the texture functions that allow specifying a depth comparison value, the associated texture unit must be configured for depth-compare texturing. Otherwise, no depth comparison will actually be performed.
 
+
{|
+
!
+
Function
+
!
+
Description
+
|}
+
 
+
The intent of the ''' <tt>debug</tt> ''' function is to allow a program to be compiled twice—once with the ''' <tt>DEBUG</tt> ''' option and once without. By executing both programs, it is possible to obtain one frame buffer containing the final output of the program and another frame buffer containing an intermediate value to be examined for debugging purposes.
+

Latest revision as of 10:23, 6 October 2009

The Cg function table:

Functions

Function Description
abs( x ) Absolute value of x .
acos( x ) Arccos of x in range [0, pi], x in [-1, 1].
all( x ) true if all components of x != 0 - false otherwise.
any( x ) true if any component of x != 0 - false otherwise.
asin( x ) Arcsin of x in range [-pi/2,pi/2]; x in [-1, 1].
atan( x ) Arctan of x in range [-pi/2, pi/2].
atan2( y , x ) Arctan y/x in range [-pi,pi].
ceil( x ) Smallest integer not less than x .
clamp( x , a , b ) x clamped to the range [a,b]: a if x<a, b if x>b else returns x.
cos( x ) Cos of x.
cosh( x ) Hyperbolic cos of x .
cross( A , B ) Cross product of vectors A and B (A and B must be three-component).
ddx( a ) Partial derivative of a with respect to screen-space x coordinate
ddy( a ) Partial derivative of a with respect to screen-space y coordinate
debug(float4 x) If compiler DEBUG option is enabled, causes shader to halt with x copied to the COLOR output - otherwise it does nothing.
degrees( x ) convert radians to degrees.
determinant( x ) Determinant of matrix x.
distance( p1 , p2 ) Pythagorean distance between p1 and p2.
dot( A, B ) Dot product of A and B.
exp( x ) Exponential func: ex.
exp2( x ) Exponential function 2x.
faceforward( N, I, Ng ) N if dot( Ng , I ) < 0 otherwise (-N).
floor( x ) Largest integer not greater than x.
fmod( x , y ) Remainder of x/y (with the same sign as x). If y==0, result is undefined.
frac( x ) Fractional part of x.
frexp( x , out exp ) Splits x into normalized fraction in the interval [, 1), which is returned, and a power of 2, which is stored in exp . If x==0, both parts of the result are 0.
isfinite( x ) Returns true if x is finite.
isinf( x ) Returns true if x is infinite.
isnan( x ) Returns true if x is NaN.
ldexp( x , n ) x * 2n.
length( v ) Pythagorean length of vector.
lerp( a , b , f ) Linear interpolation: (1 - f)* a + b * f. f can be a vector of same length as a & b.
lit( NdotL , NdotH , m ) Computes lighting coefficients (m is the shininess). Returns: float4: .x=ambient (always 1), .y=diffuse (0 if N.L < 0), .z=specular (0 if N.L<0 or N.H<0); .w==1.0.
log( x ) Natural logarithm (x>0).
log2( x ) Log Base 2 (x>0).
log10( x ) Log Base 10 (x>0).
max( a , b ) Maximum of a and b .
min( a , b ) Minimum of a and b .
modf( x , out ip ) Splits x into int and frac parts (each with the same sign as x). Stores the int part in ip and returns the fractional part.
mul( M , N ) Matrix product of matrix M and matrix N: If M has size AxB, and N has size BxC, returns an AxC.
mul( M , v ) Product of matrix M and column vector v: If M has size AxB, and v is Bx1, returns an Ax1.
mul( v , M ) Product of row vector v and matrix M: If v is a 1xA and M is AxB, returns a 1xB.
noise( x ) Noise function. The returned value is between 0 and 1, and is always the same for a given input value.
normalize( v ) Normalize v.
pow( x , y ) xy
radians( x ) Converts degrees to radians.
reflect( I , N ) Computes reflection of I in a plane with surface normal N. (three-component vectors only).
refract( I , N , eta ) Computes refraction of I in a plane with surface normal N and refractive index eta. Returns (0,0,0) for total internal reflection. (three-component vectors only).
round( x ) Closest integer to x.
rsqrt( x ) Reciprocal square root of x (x>0).
saturate( x ) Clamps x to [0, 1].
sign( x ) Sign of x (returns -1, 0 or +1)
sin( x ) Sin of x.
sincos(float x , out s , out c ) s is set to sin(x), and c to cos(x).
sinh( x ) Hyperbolic sine of x.
smoothstep( min , max , x ) For values of x between min and max , returns a smoothly varying value that ranges from 0 at x==min to 1 at x==max. x is clamped to the range [min,max] and then returns 2*((x-min)/(max-min))3+3*((x-min)/(max-min))2
step( a , x ) 0 if x<a, 1 if x>=a
sqrt( x ) Square root of x (x>0)
tan( x ) Tan of x.
tanh( x ) Hyperbolic tan of x.
tex1D(sampler1D tex , float s ) 1D nonprojective texture lookup
tex1D(sampler1D tex , float s , float dsdx , float dsdy ) 1D nonprojective texture lookup with derivatives
tex1D(sampler1D tex , float2 sz ) 1D nonprojective depth compare texture lookup
tex1D(sampler1D tex , float2 sz , float dsdx , float dsdy ) 1D nonprojective depth compare texture lookup with derivatives
tex1Dproj(sampler1D tex , float2 sq ) 1D projective texture lookup
tex1Dproj(sampler1D tex , float3 szq ) 1D projective depth compare texture lookup
tex2D(sampler2D tex , float2 s ) 2D nonprojective texture lookup
tex2D(sampler2D tex , float2 s , float2 dsdx , float2 dsdy ) 2D nonprojective texture lookup with derivatives
tex2D(sampler2D tex , float3 sz ) 2D nonprojective depth compare texture lookup
tex2D(sampler2D tex , float3 sz , float2 dsdx , float2 dsdy ) 2D nonprojective depth compare texture lookup with derivatives
tex2Dproj(sampler2D tex , float3 sq ) 2D projective texture lookup
tex2Dproj(sampler2D tex , float4 szq ) 2D projective depth compare texture lookup
texRECT(samplerRECT tex , float2 s ) 2D nonprojective texture rectangle texture lookup (OpenGL)
texRECT(samplerRECT tex , float2 s , float2 dsdx , float2 dsdy ) 2D nonprojective texture rectangle texture lookup with derivatives (OpenGL)
texRECT(samplerRECT tex , float3 sz ) 2D nonprojective texture rectangle depth compare texture lookup (OpenGL)
texRECT(samplerRECT tex , float3 sz , float2 dsdx , float2 dsdy ) 2D nonprojective depth compare texture lookup with derivatives (OpenGL)
texRECTproj(samplerRECT tex , float3 sq ) 2D texture rectangle projective texture lookup (OpenGL)
texRECTproj(samplerRECT tex , float3 szq ) 2D texture rectangle projective depth compare texture lookup (OpenGL)
tex3D(sampler3D tex , float3 s ) 3D nonprojective texture lookup
tex3D(sampler3D tex , float3 s , float3 dsdx , float3 dsdy ) 3D nonprojective texture lookup with derivatives
tex3Dproj(sampler3D tex , float4 sq ) 3D projective texture lookup
texCUBE(samplerCUBE tex , float3 s ) Cubemap nonprojective texture lookup
texCUBE(samplerCUBE tex , float3 s , float3 dsdx , float3 dsdy ) Cubemap nonprojective texture lookup with derivatives
texCUBEproj(samplerCUBE tex , float4 sq ) Cube map projective texture lookup (ignores q)
transpose( M ) transpose of matrix M

NOTES:

  • s indicates a one-, two-, or three-component texture coordinate.
  • z indicates a depth comparison value for shadow map lookups.
  • q indicates a perspective value, and is used to divide the texture coordinate ( s ) before the texture lookup is performed.

When you use the texture functions that allow specifying a depth comparison value, the associated texture unit must be configured for depth-compare texturing. Otherwise, no depth comparison will actually be performed.