Microsoft DirectX 8.0 (C++)

Instruction Modifiers

The Direct3DX pixel shader assembler support shift/scale modifier flags and a saturation modifier flag that affects the generated output result. Instruction modifiers integrate with the instruction processing in the following order.

  1. Perform inversion.
  2. Apply biasing.
  3. Apply scaling to the result.
  4. Perform clamping.

The shift/scale modifiers can vary the magnitude of the result within a certain range.

Name Modifier
_x2 Multiply result by 2
_x4 Multiply result by 4
_d2 Divide result by 2

In addition, a saturation modifier (_sat) is provided for both color and alpha blending instructions and texture addressing instructions.

For color and alpha blending instruction, the saturation modifier clamps the result of this instruction into the range 0.0 to 1.0 for each component. The following example shows how to use this instruction modifier.

dp3_sat r0, t0_bx2, v0_bx2    ; t0 is bump, v0 is light direction

This operation occurs after the scaling instruction modifier. This is most often used to clamp dot product results. However, it also enables consistent emulation of multipass methods where the frame buffer is always in the range 0 to 1, and of Microsoft® DirectX 6.0 and 7.0 multitexture syntax, in which saturation is defined to occur at every stage.

For texture addressing instructions, the saturation modifier can be appended to the operation to indicate that the result of the operation should be clamped into the color range 0 .0 to 1.0 upon completion of the operation. This is commonly required for use in lighting operations. The following example shows how to use this instruction modifier.

ps.1.0                       ; DirectX8 Version
tex t0                       ; Read a texture color.
dp3_sat t1, t0_bx2, v0_bx2   ; Calculate a dotproduct with the texture coordinates and clamp.

The following add instruction loads the destination register (d) with the sum of the two colors in the source operands (s0 and s1), and multiplies the result by 2.

add_x2   d, s0, s1

The following add instruction loads the destination register (d) with the sum of the two colors in the source operands (s0 and s1), and clamps the result into the range 0.0 to 1.0 for each component.

add_sat   d, s0, s1

The following add instruction loads the destination register (d) with the sum of the two colors in the source operands (s0 and s1), multiplies the result by 2, and clamps the result into the range 0.0 to 1.0 for each component.

add_2x_sat   d, s0, s1