![]() |
![]() |
![]() |
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).
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 versions | 1_1 | 2_0 | 2_sw | 2_x | 3_0 | 3_sw |
---|---|---|---|---|---|---|
Constant Register | x | x | x | x | x | x |