Source Register Selectors

DirectX8

Microsoft DirectX 8.1 (pixel shader versions 1.1, 1.2, 1.3, 1.4)

Source Register Selectors

This modifier replicates a single channel of a source-register argument to all channels.

source register.channel
Source register selectorsSyntaxVersion
1.0 1.1 1.2 1.3 1.4
Red replicate source register.r X
Green replicate source register.g X
Blue replicate source register.b X X X X
Alpha replicate source register.a X X X X X
  • Red replicate. Replicates the red channel to all channels.
  • Green replicate. Replicates the green channel to all channels.
  • Blue replicate. Replicates the blue channel to all channels.
  • Alpha replicate. Replicates the alpha channel to to all channels.

Register

Source register. For more about register types, see Registers.

In version 1.1, 1.2, and 1.3, blue replicate is available only on the source register of arithmetic instruction, which uses an alpha destination register write mask.

Remarks

Source register selectors are applied before any source register modifiers and before the instruction executes.

Copying the contents of a channel into one or more other channels is commonly referred to as "swizzling."

These selectors are valid on source registers for arithmetic instructions. The four selectors operate on different channels.

An alternate syntax for the r,g,b,a channels is x,y,z,w.

Source selectors and source modifiers may be combined freely. In this example, register r0 uses the invert, bias, and signed scaling modifier, as well as the green selector. The contents of the source register are unaffected; the modifier modifies only the data read.

-r0_bx2.g

To understand the order of the execution of these modifiers and selectors, see Order of Operations.

This operator can be used in conjunction with the Invert or Negate operators.

Alpha replicate functionality is analogous to the D3DTA_ALPHAREPLICATE flag in the Microsoft® DirectX® 6.0 and 7.0 multitexture syntax.

Example

The examples below illustrate each of the four selectors.

// Replicate the red color channel to the all channels before
// doing the multiply.
mul r0, r0, r1.r    // the result is r1.rgba = r1.r
					
// Replicate the green color channel to the all channels before
// doing the multiply.
mul r0, r0, r1.g    // the result is r1.rgba = r1.g

// Replicate the blue color channel to the all channels before
// doing the multiply.
mul r0, r0, r1.b    // the result is r1.rgba = r1.b
					
// For ps 1.1, 1.2, 1.3, the blue replicate example 
// would require a destination write mask.					
mul r0.a, r0, r1.b					

// alpha replicate
mul r0, r0, r1.a    ; Replicate the alpha color channel to all channels.