App A
App A
Appendix A
Low-Level Shading
Languages Reference
Paul Baker
Instructions
Table A.1 lists all of the instructions that are common to both ARB_vertex_program and
ARB_fragment_program. Table A.2 lists the instructions that are only available in
ARB_vertex_program, and Table A.3 lists the instructions that are only available in
ARB_fragment_program.
DPH Homogeneous (x1, y1, z1, w1), (d, d, d, d) where Calculates a 4-component
dot product (x2, y2, z2, w2) d = x1 * x2 + y1 scalar (dot) product of the
* y2 + z1 * z2 + w2 source vectors, with the
exception that w1 is forced to
1.0. Writes the result to all
components of the
destination vector.
DST Distance vector (x1, y1, z1, w1), (1.0, y1 * y2, z1, w2) When used with input vectors
(x2, y2, z2, w2) of the form:| (x1, y1, z1, w1)
= (N/A, d^2, d^2, N/A)
(x2, y2, z2, w2) = (N/A, 1/d,
N/A, 1/d) Calculates:
(1.0, d, d^2, 1/d)
EX2 Exponential s (2^s, 2^s, 2^s, 2^s) Calculates 2 raised to the
base 2 power of the scalar operand
and writes the result to all
four components of the
destination vector.
FLR Floor (x, y, z, w) (floor(x), floor(y), Calculates the floor of each
floor(z), floor(w)) component of the source
vector. The floor of a value is
the largest integer less than
or equal to the value.
FRC Fraction (x, y, z, w) (fraction(x), fraction (y), Calculates the fractional part
fraction (z), fraction (w)) of each component of the
source vector.
LG2 Logarithm s (log2(s), log2(s), Calculates the base 2
base 2 log2(s), log2(s)) logarithm of the scalar
operand and writes the result
to all four components of the
destination vector.
LIT Calculate (d, s, N/A, x) (1.0, D, S, 1.0) d is a diffuse dot product, s is
lighting a specular dot product, x is
coefficients the specular exponent, D is
the value to be multiplied by
the diffuse color, and S is the
value to be multiplied by the
specular color.
MAD Multiply and (x1, y1, z1, w1), (x1 * x2 + x3, y1 Multiplies the first two
accumulate (x2, y2, z2, w2), * y2 + y3, z1 * z2 + z3, source vectors and adds the
(x3, y3, z3, w3) w1 * w2 + w3) third source vector,
component-wise.
MAX Maximum (x1, y1, z1, w1), (max(x1, x2), max(y1, y2), Calculates the
(x2, y2, z2, w2) max(z1, z2), max(w1, w2)) component-wise maximum
of the two source vectors.
continued
13-More Open GL-AppA 9/26/05 9:03 AM Page 3
Instructions A3
MIN Minimum (x1, y1, z1, w1), (min(x1, x2), min(y1, y2), Calculates the component-
(x2, y2, z2, w2) min(z1, z2), min(w1, w2)) wise minimum of the two
source vectors.
MOV Move (x1, y1, z1, w1) (x1, y1, z1, w1) Copies the source vector into
the destination vector.
MUL Multiplication (x1, y1, z1, w1), (x1 * x2, y1 * y2, z1 Multiplies the two source
(x2, y2, z2, w2) * z2, w1 * w2) vectors component-wise.
POW Power s, p (s^p, s^p, s^p, s^p) Raises the first scalar
operand to the power of the
second scalar operand and
writes the result to all four
components of the
destination vector.
RCP Reciprocal s (1/s, 1/s, 1/s, 1/s) Calculates the reciprocal of
the scalar operand and
writes the result to all four
components of the
destination vector.
RSQ Reciprocal s (1/sqrt(s), 1/sqrt(s), Calculates the reciprocal
square root 1/sqrt(s), 1/sqrt(s)) of the scalar operand and
writes the result to all four
components of the
destination vector.
SGE Set On Greater (x1, y1, z1, w1), (x1 >= x2 ? 1.0 : 0.0, Compares the two source
Than Or Equal (x2, y2, z2, w2) y1 >= y2 ? 1.0 : 0.0, z1 vectors component-wise,
>= z2 ? 1.0 : 0.0, w1 setting the corresponding
component of the
destination vector if the first
source is greater than or
equal to the second.
SLT Set On (x1, y1, z1, w1), (x1 < x2 ? 1.0 : 0.0, y1 Compares the two source
Less Than (x2, y2, z2, w2) < y2 ? 1.0 : 0.0, z1 vectors component-wise,
< z2 ? 1.0 : 0.0, w1 setting the corresponding
< w2 ? 1.0 : 0.0) component of the destination
vector if the first source is
less than the second.
SUB Subtraction (x1, y1, z1, w1), (x1 – x2, y1 – y2, Subtracts the two source
(x2, y2, z2, w2) z1 – z2, w1 – w2) vectors component-wise.
continued
13-More Open GL-AppA 9/26/05 9:03 AM Page 4
SWZ Extended (x1, y1, z1, w1), (c1, c2, c3, c4) Reorders the components
Swizzle c1, c2, c3, c4 of a source vector, optionally
negating selected
components or replacing
them with a constant. The
parameters c1–c4 can be x,
x, y, y, z, z, w, w, 0, 1
or 1. The corresponding
component of the source
vector, or the given constant,
is used as the component of
the destination vector.
XPD Cross Product (x1, y1, z1, N/A), (y1 * z2 z1 * y2, Calculates a vector (cross)
(x2, y2, z2, N/A) z1 * x2 x1 * z2, product using the first three
x1 * y2 y1 * x2, components of the source
UNDEF) vectors and writes the result
to the first three components
of the destination vector.
Instructions A5
Parameter Vectors
The OpenGL state variables listed in Table A.4 are available to vertex programs and frag-
ment programs as parameter vectors. Unless otherwise indicated, the variables are avail-
able to both types of program.
Parameter Vectors A7