ARB shading language reference

This paragraph does not aim at replacing the official shader specifications. It's simply a quick reference, listing all useful assembly commands, available program parameters and state variables.

Official ARB shader specifications

ARB vertex program

Vertex program inputs:

Vertex program outputs:

Vertex program parameters (not exhaustive):

Vertex program state matrices (not exhaustive):

Access to inverse and transpose matrices is possible through the addition of a suffix to the targeted matrix: '.inverse' to get the inverse matrix; '.transpose' to get the transposed matrix; '.invtrans' to get the inverse transposed matrix.

Vertex program temporaries:

Note that shader performance is better when fewer temporaries are being used. Low end hardware may have limits in the number of temporaries that can be declared.

Vertex program commands: (V: Vector; S: Scalar; U: Texture image unit identifier; T: Texture target)

InstructionInputsOutputsDescription
ABSVVAbsolute value.
ABS R1, R1; // R1 = |R1|
ADDV, VVAddition.
ADD R0, R1, R2; // R0 = R1 + R2;
DP3V, VS, S, S, S3 components dot product.
DP3 R0, R1, R2; // R0 = R1.x * R2.x + R1.y * R2.y + R1.z * R2.z;
DP4V, VS, S, S, S4 components dot product.
DP4 R0, R1, R2; // R0 = R1.x * R2.x + R1.y * R2.y + R1.z * R2.z + R1.w * R2.w;
DPHV, VS, S, S, SHomogeneous dot product.
DPH R0, R1, R2; // R0 = R1.x * R2.x + R1.y * R2.y + R1.z * R2.z + R2.w;
DSTV, VVDistance vector. Refer to full specification for details.
EX2SS, S, S, SExponential base 2 (approximate). Refer to full specification for details.
EXPSVExponential base 2 (approximate). Refer to full specification for details.
FLRVVFloor. Component wise floor operation. Floor is the largest integer value less than or equal to the value. The floor of 2.3 is 2; the floor of -3.6 is -4.0.
FRCVVFractional part. Generates the fractional portion of each component of the operand to generate a result vector. Subtracts the floor of the operand to its value. The result is always in [0, 1].
FRC R0, R0; // FLR R1, R0; SUB R0, R0, R1;
LG2SS, S, S, SLogarithm base 2 (approximate). Refer to full specification for details.
LITVVCompute lighting coefficients. Refer to full specification for details.
LOGSVLogarithm base 2 (approximate). Refer to full specifications for details.
MADV, V, VVMultiply and add. Multiply the two first operands, add the third one. Component wise operation.
MAD R0, R1, R2, R3; // R0 = R1 * R2 + R3
MAXV, VVMaximum. Component wise maximum of the two operands.
MAX R0, R1, R2; // R0.x = (R1.x > R2.x) ? R1.x : R2.x; Same for y, z, w.
MINV, VVMinimum. Component wise minimum of the two operands.
MIN R0, R1, R2; // R0.x = (R1.x < R2.x) ? R1.x : R2.x; Same for y, z, w.
MOVVVMove. Vector move.
MOV R1, value; // R1 = value;
MULV, VVMultiply. Component wise multiplication of the two operands.
MUL R0, R1, R2; // R0 = R1 * R2
POWS, SS, S, S, SExponentiate (approximate). Raise the first operand at the power of the second operand. Result is duplicated in the result vector.
POW R0, R1.x, R2.z;
RCPSS, S, S, SReciprocal. Approximates the reciprocal of the scalar operand, and replicates the result to the four components of the result vector.
RCP R0, R0.x; // R0.xyzw = 1.0 / R0.x
RSQSS, S, S, SReciprocal square root. Approximates the reciprocal square root of the scalar operand, and replicates the result to the four components of the result vector.
RSQ R0, R0.x; // R0 = 1.0 / sqrt( R0.x )
SGEV, VVSet on greater than or equal to. Performs a component wise comparison of the two operands. Each component of the result vector is 1.0 if the corresponding component of the first operand is greater than or equal to the value in the second operand and 0.0 otherwise.
SGE R0, R1, R2; // R0.x = (R1.x >= R2.x) ? 1.0 : 0.0; Same for y, z, w.
SLTV, VVSet on less than. Performs a component wise comparison of the two operands. Each component of the result vector is 1.0 if the corresponding component of the first operand is less than that of the second and 0.0 otherwise.
SLT R0, R1, R2; // R0.x = (R1.x < R2.x) ? 1.0 : 0.0; Same for y, z, w.
SUBV, VVSubtract. Component wise subtraction of the second operand from the first to yield a result vector.
SUB R0, R1, R2; // Is equivalent to ADD R0, R1, -R2;
SWZVVExtended swizzle. Refer to full specifications for details. This is implicitly used when an operand is written with a full extension suffix, such as the example below:
SWZ R0, R0.zwxy; // Is equivalent to: ADD R0, R1, R0; // ADD R0, R1, R0.zwxy;
XPDV, VVCross product. Refer to full specification for details.
XPD R0, R1, R2; // Is equivalent to: MULR R0.xyz, R1.zxyz, R2.yzxy; MADR R0.xyz, R1.yzxy, R2.zxyz, -R0.xyzx;

ARB pixel / fragment program

Pixel program inputs:

Pixel program outputs:

A pixel program must output at least one of both values.

Pixel program parameters (not exhaustive):

Pixel program temporaries:

Note that shader performance is better when fewer temporaries are being used. Low end hardware may have limits in the number of temporaries that can be declared.

Pixel program state parameters:

Pixel program commands:

Commands that are identical for both vertex and pixel programs are not mentioned again here. This includes: ABS, ADD, DP3, DP4, DPH, DST, EX2, FLR, FRC, LG2, LIT, MAD, MAX, MIN, MOV, MUL, POW, RCP, RSQ, SUB, SWZ, XPD. Pixel program specific commands are here:

InstructionInputsOutputsDescription
CMPV, V, VVCompare. Performs a component wise comparison of the first operand against zero, and copies the value of the second operand or third operand based on the results of the comparison.
CMP R0, R1, R2, R3; // R0.x = (R1.x < 0.0) ? R2.x : R3.x; Same applies for y, z, w.
COSSS, S, S, SCosine with reduction to [-PI, PI]. Approximates the trigonometric cosine of the angle specified by the scalar operand and replicates it to all four components of the result vector.
KILVVKill fragment. This function prevents a fragment from receiving any further processing if any component of its source vector is negative. Subsequent stages of the GL pipeline will be skipped for this fragment.
LRPV, V, VVLinear interpolation. Performs a component wise linear interpolation between the second and third operands using the first operand as blend factor.
LRP R0, R1, R2, R3; // R0.x = R1.x * R2.x + (1.0 - R1.x) * R3.x; Same applies for y, z, w.
SCSSS, S, -, -Sine / Cosine without reduction. Refer to full specifications for details.
SINSS, S, S, SSine with reduction to [-PI, PI]. Approximates the trigonometric sine of the angle specified by the scalar operand and replicates it to all four components of the result vector.
TEXV, U, TVTexture sample. Takes the first three components of the source vector to sample from the specified texture target on the specified texture image unit. The resulting sample is mapped to RGBA and written to the result vector. Example:
TEX R0, fragment.texcoord[2], texture[3], 2D;
TXBV, U, TVTexture sample with bias. Refer to full specification for details.
TXPV, U, TVTexture sample with projection. Divides the first three components of the source vector by the fourth component of the source vector. Performs a regular TEX after that.

Indirect shaders

Indirect shading refers to all GPU lighting calculations that are performed after a ray-casting process. The indirect lighting calculation work as all direct lighting workflows except that it does not use the same shaders. The whole indirect lighting workflow is described in the 'My first indirect shader' tutorial. We'll focus here in describing services offered by the REDsdk to program indirect lighting shaders.

Indirect vertex programs

They render quads instead of triangles. An indirect vertex program operates in WCS and transmits the triangle attributes to the pixel program. It rarely does more than that because it does not know the results of the ray versus triangle intersection yet.

Indirect vertex program inputs:

Indirect vertex programs outputs:

Indirect pixel programs

Indirect pixel programs perform the ray versus triangle intersection for the provided attributes. They interpolate the found intersection to perform all lighting calculations now based on the local information. Indirect programs start by feeding the standard intersection calculation code:

psh.TriangleOwnershipTest();
psh.IntersectRayVsTriangle("ray_uv","ray_start","ray_dir",0);
psh.GetRayVsTriangleHitPoint("ray_hit","ray_uv","ray_start","ray_dir");
psh.GetRayVsTriangleUV("ray_uv");

Indirect pixel program inputs:

Indirect pixel program outputs: