Constant Float Register
Microsoft DirectX 9.0 SDK Update (October 2004)

Constant Float Register


Vertex shader input register for a four component floating-point constant. Set a constant register with either def or IDirect3DDevice9::SetVertexShaderConstantF.

The constant register file is read-only from the perspective of the vertex shader. Any single instruction may access only one constant register. However, each source in that instruction may independently swizzle and negate that vector as it is read.

The behavior of shader constants has changed between Microsoft DirectX 8.0 and DirectX 9.0.

A constant register is designated as either absolute or relative:

c[n]           ; absolute
c[a0.x + n]    ; relative - supported only in version 1_1

The constant register can be read, therefore, either by using an absolute index or with a relative index from an address register. Reads from out-of-range registers return (0.0, 0.0, 0.0, 0.0).

Examples

Here is an example declaring two floating-point constants within a shader.

def c40, 0.0f,0.0f,0.0f,0.0f;

These constants are loaded every time IDirect3DDevice9::SetVertexShader is called.

Here is an example using the API.

    // Set up the vertex shader constants.
    {
        D3DXMATRIXA16 mat;
        D3DXMatrixMultiply( &mat, &m_matView, &m_matProj );
        D3DXMatrixTranspose( &mat, &mat );

        D3DXVECTOR4 vA( sinf(m_fTime)*15.0f, 0.0f, 0.5f, 1.0f );
        D3DXVECTOR4 vD( D3DX_PI, 1.0f/(2.0f*D3DX_PI), 2.0f*D3DX_PI, 0.05f );

        // Taylor series coefficients for sin and cos.
        D3DXVECTOR4 vSin( 1.0f, -1.0f/6.0f, 1.0f/120.0f, -1.0f/5040.0f );
        D3DXVECTOR4 vCos( 1.0f, -1.0f/2.0f, 1.0f/ 24.0f, -1.0f/ 720.0f );

        m_pd3dDevice->SetVertexShaderConstantF(  0, (float*)&mat,  4 );
        m_pd3dDevice->SetVertexShaderConstantF(  4, (float*)&vA,   1 );
        m_pd3dDevice->SetVertexShaderConstantF(  7, (float*)&vD,   1 );
        m_pd3dDevice->SetVertexShaderConstantF( 10, (float*)&vSin, 1 );
        m_pd3dDevice->SetVertexShaderConstantF( 11, (float*)&vCos, 1 );
    }

If you are setting constant values with the API, there is no shader declaration required.

Vertex shader versions1_12_02_sw2_x3_03_sw
Constant Registerxxxxxx


© 2004 Microsoft Corporation. All rights reserved.
Feedback? Please provide us with your comments on this topic.
For more help, visit the DirectX Developer Center.