Hi, I want to change directx version that the game uses from 8 to 9 (if I succeed, maybe I will try to change to 11 in the future). I have a few problems that I can not deal with.
Firstly, I don't know how to change vertex shader declaration.
// template shader for fixed function vertex shader
DWORD _adwDeclTemplateFF[] = {
D3DVSD_STREAM(0),
D3DVSD_REG( D3DVSDE_POSITION, D3DVSDT_FLOAT3),
D3DVSD_STREAM(1),
D3DVSD_REG( D3DVSDE_DIFFUSE, D3DVSDT_D3DCOLOR),
D3DVSD_STREAM(2),
D3DVSD_REG( D3DVSDE_TEXCOORD0, D3DVSDT_FLOAT2),
D3DVSD_STREAM(3),
D3DVSD_REG( D3DVSDE_TEXCOORD1, D3DVSDT_FLOAT2),
D3DVSD_STREAM(4),
D3DVSD_REG( D3DVSDE_TEXCOORD2, D3DVSDT_FLOAT2),
D3DVSD_STREAM(5),
D3DVSD_REG( D3DVSDE_TEXCOORD3, D3DVSDT_FLOAT2),
D3DVSD_STREAM(6),
D3DVSD_REG( D3DVSDE_NORMAL, D3DVSDT_FLOAT3),
D3DVSD_STREAM(7), // not used in fixed-function vs but must be declared for stream reset
D3DVSD_REG( NONE, NONE),
D3DVSD_REG( NONE, NONE),
D3DVSD_END()
};
// template shader for programmable vertex shader
DWORD _adwDeclTemplateVP[] = {
D3DVSD_STREAM(0),
D3DVSD_REG( 0, D3DVSDT_FLOAT3), // position
D3DVSD_STREAM(1),
D3DVSD_REG( 4, D3DVSDT_D3DCOLOR), // diffuse
D3DVSD_STREAM(2),
D3DVSD_REG( 5, D3DVSDT_FLOAT2), // texcoord0
D3DVSD_STREAM(3),
D3DVSD_REG( 6, D3DVSDT_FLOAT2), // texcoord1
D3DVSD_STREAM(4),
D3DVSD_REG( 7, D3DVSDT_FLOAT2), // texcoord2
D3DVSD_STREAM(5),
D3DVSD_REG( 8, D3DVSDT_FLOAT2), // texcoord3
D3DVSD_STREAM(6),
D3DVSD_REG( 1, D3DVSDT_FLOAT3), // normal
D3DVSD_STREAM(7),
D3DVSD_REG( 3, D3DVSDT_D3DCOLOR), // blend indices
D3DVSD_REG( 2, D3DVSDT_D3DCOLOR), // blend weights
D3DVSD_END()
};
Secondly, I have a function that returns shader declaration from given flags. How to change it?
// Get shader stream declaration from stream flags
extern void GetShaderDeclaration_D3D(ULONG *ulRetDecl, ULONG ulStreamFlags)
{
// if using position stream
if(ulStreamFlags&GFX_POSITION_STREAM) {
*( ulRetDecl) = D3DVSD_STREAM(0);
*(++ulRetDecl) = D3DVSD_REG( 0, D3DVSDT_FLOAT3);
ulStreamFlags&=~GFX_POSITION_STREAM;
}
// if using color stream
if(ulStreamFlags&GFX_COLOR_STREAM) {
*(++ulRetDecl) = D3DVSD_STREAM(1);
*(++ulRetDecl) = D3DVSD_REG( 4, D3DVSDT_D3DCOLOR);
ulStreamFlags&=~GFX_COLOR_STREAM;
}
// if using texture unit 1
if(ulStreamFlags&GFX_TEXCOORD0) {
*(++ulRetDecl) = D3DVSD_STREAM(2);
*(++ulRetDecl) = D3DVSD_REG( 5, D3DVSDT_FLOAT2);
ulStreamFlags&=~GFX_TEXCOORD0;
}
// if using texture unit 2
if(ulStreamFlags&GFX_TEXCOORD1) {
*(++ulRetDecl) = D3DVSD_STREAM(3);
*(++ulRetDecl) = D3DVSD_REG( 6, D3DVSDT_FLOAT2);
ulStreamFlags&=~GFX_TEXCOORD1;
}
// if using texture unit 3
if(ulStreamFlags&GFX_TEXCOORD2) {
*(++ulRetDecl) = D3DVSD_STREAM(4);
*(++ulRetDecl) = D3DVSD_REG( 7, D3DVSDT_FLOAT2);
ulStreamFlags&=~GFX_TEXCOORD2;
}
// if using texture unit 4
if(ulStreamFlags&GFX_TEXCOORD3) {
*(++ulRetDecl) = D3DVSD_STREAM(5);
*(++ulRetDecl) = D3DVSD_REG( 8, D3DVSDT_FLOAT2);
ulStreamFlags&=~GFX_TEXCOORD3;
}
if(ulStreamFlags&GFX_NORMAL_STREAM) {
*(++ulRetDecl) = D3DVSD_STREAM(6);
*(++ulRetDecl) = D3DVSD_REG( 1, D3DVSDT_FLOAT3);
ulStreamFlags&=~GFX_NORMAL_STREAM;
}
if(ulStreamFlags&GFX_WEIGHT_STREAM) {
*(++ulRetDecl) = D3DVSD_STREAM(7);
*(++ulRetDecl) = D3DVSD_REG( 3, D3DVSDT_D3DCOLOR);
*(++ulRetDecl) = D3DVSD_REG( 2, D3DVSDT_D3DCOLOR);
ulStreamFlags&=~GFX_WEIGHT_STREAM;
}
// if using tangent
if(ulStreamFlags&GFX_TANGENT_STREAM) {
*(++ulRetDecl) = D3DVSD_STREAM(3);
*(++ulRetDecl) = D3DVSD_REG( 9, D3DVSDT_FLOAT4);
ulStreamFlags&=~GFX_TANGENT_STREAM;
}
ASSERT(ulStreamFlags==0); // make sure stream flags were valid
*(++ulRetDecl) = D3DVSD_END();
}
And I have one question. Is it possible to combine dx8 shaders with dx9?
Thanks for any help.