# Take diffuse vertex color?

## Recommended Posts

dali    195
Hello! I am a bit ashamed to ask this but how can i take the vertex diffuse color instead of the diffuse material color. I think i have set all the renderstates correct:
device->SetRenderState( D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_COLOR1  );
device->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_SELECTARG2);
device->SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_DIFFUSE);
device->SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE);   //Ignore
device->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
device->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
device->SetTextureStageState(2, D3DTSS_COLOROP, D3DTOP_DISABLE);
device->SetTextureStageState(2, D3DTSS_ALPHAOP, D3DTOP_DISABLE);

The vertex format looks like that:
struct VERTEX
{
FLOAT x, y, z;
FLOAT nx, ny, nz;
DWORD color;
FLOAT u, v;
};
#define D3DFVF_VERTEX (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_DIFFUSE|D3DFVF_TEX1)

I cant see what is going wrong here. Another question is how i can unset the material for it is not possible to do something like device->SetMaterial(NULL); Thanks a lot!!

##### Share on other sites
If you're not using lighting, it will just use the vertex color.

If you're using light, you set the DIFFUSEMATERIALSOURCE that you've set, but you have to enable all the *MaterialSource states with D3DRS_COLORVERTEX. The diffuse color your stages will see will be a mix of light colors, vertex color, emissive, and ambient colors.

##### Share on other sites
dali    195
I wonder why this is not in the dx docu.