sub

DirectX8

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

sub

Performs subtraction. Subtracts the second source register from the first source register.

sub 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 the subtraction based on the following formula.

dest = src0 - src1

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 subtracts texture color from the diffuse color.

// The shader is shown below.
ps.1.0              // Version instruction
tex t0              // Declare texture.
sub r0, v0, t0      // Subtract texture color from diffuse color.

// The following images show the contents of the source registers and 
// the resulting destination register. The colors in the second image (src1) 
// are subtracted from the color in the first image (src0) to make the 
// resulting image (dest).

// 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";

D3DUtil_CreateTexture( m_pd3dDevice, strPath, &m;_pTexture0, D3DFMT_R5G6B5 );
m_pd3dDevice->SetTexture( 0, m_pTexture0 );