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:
- Size: 1, 2, 3 or 4 values.
- Normalized: yes / no (defined in the RED::RenderCode)
- Values: byte; unsigned byte; short; unsigned short; int; unsigned int; float; double. This is defined by the format of the corresponding mesh channels.
- Syntax: vertex.attrib[0 - 15].
Vertex program outputs:
- result.position: position in clip coordinates.
- result.color.primary: primary color.
- result.color.secondary: secondary color.
- result.fogcoord: fog coordinates.
- result.pointsize: point size.
- result.texcoord[0 - 6]: output texture coordinates.
Vertex program parameters (not exhaustive):
- program.env[a]: (x,y,z,w). Program environment parameter number 'a'.
- program.local[a]: (x,y,z,w). Program local parameter 'a'.
Vertex program state matrices (not exhaustive):
- state.matrix.modelview: Modelview matrix.
- state.matrix.projection: Projection matrix.
- state.matrix.mvp: Modelview-projection matrix.
- state.matrix.program[0]: View matrix (specified in the RED::RenderCode).
- state.matrix.program[1]: Model matrix (specified in the RED::RenderCode).
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:
- TEMP R0;
- TEMP myValue;
- PARAM myParam = program.local[10];
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)
Instruction | Inputs | Outputs | Description |
---|---|---|---|
ABS | V | V | Absolute value.
|
ADD | V, V | V | Addition.
|
DP3 | V, V | S, S, S, S | 3 components dot product.
|
DP4 | V, V | S, S, S, S | 4 components dot product.
|
DPH | V, V | S, S, S, S | Homogeneous dot product.
|
DST | V, V | V | Distance vector. Refer to full specification for details. |
EX2 | S | S, S, S, S | Exponential base 2 (approximate). Refer to full specification for details. |
EXP | S | V | Exponential base 2 (approximate). Refer to full specification for details. |
FLR | V | V | Floor. 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. |
FRC | V | V | Fractional 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].
|
LG2 | S | S, S, S, S | Logarithm base 2 (approximate). Refer to full specification for details. |
LIT | V | V | Compute lighting coefficients. Refer to full specification for details. |
LOG | S | V | Logarithm base 2 (approximate). Refer to full specifications for details. |
MAD | V, V, V | V | Multiply and add. Multiply the two first operands, add the third one. Component wise operation.
|
MAX | V, V | V | Maximum. Component wise maximum of the two operands.
|
MIN | V, V | V | Minimum. Component wise minimum of the two operands.
|
MOV | V | V | Move. Vector move.
|
MUL | V, V | V | Multiply. Component wise multiplication of the two operands.
|
POW | S, S | S, S, S, S | Exponentiate (approximate). Raise the first operand at the power of the second operand. Result is duplicated in the result vector.
|
RCP | S | S, S, S, S | Reciprocal. Approximates the reciprocal of the scalar operand, and replicates the result to the four components of the result vector.
|
RSQ | S | S, S, S, S | Reciprocal square root. Approximates the reciprocal square root of the scalar operand, and replicates the result to the four components of the result vector.
|
SGE | V, V | V | Set 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.
|
SLT | V, V | V | Set 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.
|
SUB | V, V | V | Subtract. Component wise subtraction of the second operand from the first to yield a result vector.
|
SWZ | V | V | Extended 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:
|
XPD | V, V | V | Cross product. Refer to full specification for details.
|
ARB pixel / fragment program
Pixel program inputs:
- fragment.texcoord[0-6]: texture coordinates interpolators.
- fragment.color.primary: Primary color. Clamped to [0, 1].
- fragment.color.secondary: Secondary color. Clamped to [0, 1].
- fragment.fogcoord: Fog coordinates. Single interpolated value.
Pixel program outputs:
- result.color: Output RGBA color.
- result.depth: Output fragment depth (in result.depth.z).
A pixel program must output at least one of both values.
Pixel program parameters (not exhaustive):
- program.env[a]: (x,y,z,w). Program environment parameter number 'a'.
- program.local[a]: (x,y,z,w). Program local parameter 'a'.
Pixel program temporaries:
- TEMP R0;
- TEMP myValue;
- PARAM myParam = program.local[10];
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:
- The same state information is available as for vertex shaders.
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:
Instruction | Inputs | Outputs | Description |
---|---|---|---|
CMP | V, V, V | V | Compare. 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.
|
COS | S | S, S, S, S | Cosine 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. |
KIL | V | V | Kill 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. |
LRP | V, V, V | V | Linear interpolation. Performs a component wise linear interpolation between the second and third operands using the first operand as blend factor.
|
SCS | S | S, S, -, - | Sine / Cosine without reduction. Refer to full specifications for details. |
SIN | S | S, S, S, S | Sine 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. |
TEX | V, U, T | V | Texture 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:
|
TXB | V, U, T | V | Texture sample with bias. Refer to full specification for details. |
TXP | V, U, T | V | Texture 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:
- Input position: This is a quad position that must be transformed in DCS as usual.
- Triangle attributes bound by the RED::RenderCode used by the indirect shader. Every attribute is repeated 3 times, for each triangle's vertex. Therefore, if we send vertices and normals, we'll receive vertex.attrib[1] to vertex.attrib[6] filled respectively with P0, P1, P2, N0, N1, N2, where P stands for position and N for normal.
- Last received attribute is the triangle ID. In our previous example, it's received as vertex.attrib[7].
- Indirect vertex programs use the 'Object to World' space matrices. These matrices are set on the RED::RenderCode.
Indirect vertex programs outputs:
- Triangle ID. Usually transferred using RED::ShaderString::TriangleIDTransfer.
- Triangle attributes at P0, P1 - P0 and P2 - P0. Every received attribute should be transferred.
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:
- Triangle ID transferred from the indirect vertex program.
- Ray starting position textures (RED_SHADER_INDIRECT_RAY_POS_TEX reference).
- Ray direction textures (RED_SHADER_INDIRECT_RAY_DIR_TEX reference).
- Triangle attributes: Vertex positions P0, P1 - P0, P2 - P0.
- Triangle attributes (optional): UV at P0, P1 - P0, P2 - P0.
- Other triangle attributes for interpolation (optional): Normals, tangents, etc
Indirect pixel program outputs:
- result.color: Fragment color.
- No depth may be output by an indirect pixel program. Depth testing is disabled and depth writing is although disabled for an indirect pixel program.
![]() | GLSL shading language reference![]() |