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

add

Performs a component-wise add of two registers.

add dest, src0, src1

Registers

Argument Description RegistersVersion
vn cn tn rn
dest Destination register x 1.0
x x 1.1, 1.2, 1.3
x 1.4
src0, src1 Source register x x x x 1.0, 1.1, 1.2, 1.3
x x 1.4 phase 1
x x x 1.4 phase 2

To learn more about registers, see Registers.

Remarks

This instruction performs a component-wise addition of two registers as shown below.

dest.r = src0.r + src1.r
dest.g = src0.g + src1.g
dest.b = src0.b + src1.b
dest.a = src0.a + src1.a

Example

This example is for illustration only. The C code accompanying the shader has not been optimized for performance. It can use helper functions from the Sample Framework. The sample framework is the foundation on which many of the samples are built.

// This example adds the vertex color to the texture color.

// The shader is shown below.
ps.1.0          // Version instruction.
tex t0          // Declare texture. This example requires the DX Logo texture 
                // to be set on stage 0.
add r0, t0, t0  // r0 = t0 + t0. This doubles each color component.
                // The effect is to increase image brightness.

// The input texture is shown on the left. The rendered output from the 
// pixel shader is shown on the right. In this example, it is brighter 
// because the texture color values have been doubled. 

// Additional code loads the texture in texture stage 0.
LPDIRECT3DDEVICE8   m_pd3dDevice;   // Init this device pointer in the application.
LPDIRECT3DTEXTURE8  m_pTexture0;    // Use this variable to hold a pointer to the texture.
TCHAR               strPath[512] = "textureFile.jpg";

// Use a helper function from the SDK to load the texture.
D3DUtil_CreateTexture( m_pd3dDevice, strPath, &m_pTexture0, D3DFMT_R5G6B5 );
m_pd3dDevice->SetTexture( 0, m_pTexture0 );