Pixel Shader
Direct3D 8 - Pixel Shader (Microsoft)
Last edited 2026-01-27
The pixel shader assembler is made up of a set of instructions that operate on pixel data contained in registers.
Operations are expressed as instructions comprised of an operator and one or more operands.
Instructions use registers to transfer data in and out of the pixel shader ALU.
Registers can also be used by some instructions to hold temporary results.
Version Differences
Each version has different limitations, when writing a shader decide which version will be ideal for your effect.
Instructions
There are two main categories of pixel shader instructions: arithmetic instructions and texture addressing instructions. Arithmetic instructions modify color data. Texture addressing operations process texture coordinate data and in most cases, sample a texture. Pixel shader instructions are run on a per-pixel basis; that is, they have no knowledge of other pixels in the pipeline.
Texture addressing instructions each consume one slot, but arithmetic instructions can be paired to enable both color components (RGB) and an alpha component instruction in a single slot.
When multisampling is enabled, pixel shaders only get run once per pixel, not once for every subpixel. Multisampling only increases the resolution of polygon edges, as well as depth and stencil tests. For example, if 3x3 multisampling is enabled, and a triangle being rasterized is found to cover five of the nine subpixels for a particular pixel, the pixel shader gets run once and the same color result is applied to all five subpixels.
Registers
Contains a list of the various registers used by the ALU shader.
Modifiers
Modifiers can be used to change the functionality of an instruction, or the data read from or written to a register.
Example code:
texture T_Image; // <- Main texture
technique tech_main
{
pass p0
{
Texture[0] = <T_Image>;
PixelShader = asm
{
ps.1.3; // <- pixel shader version (ps.1.0, ps.1.1, ps.1.2, ps.1.3 or ps.1.4)
def c0, 1.0, 1.0, 1.0, 0.0; // <- constant value declaration (red: 1.0, green: 1.0, blue: 1.0, alpha: 0.0)
tex t0; // <- load the T_Image texture
mov r0, t0; // <- assigning colors from the texture to the result.
sub r0, c0, t0; // <- subtract colors (c0.rgba - t0.rgba)
mov r0.a, t0.a; // <- assigning alpha color from texture
};
}
}
Created with the Personal Edition of HelpNDoc: Revolutionize Your Documentation Review with HelpNDoc's Project Analyzer