D3D Colours
If all of the triangles in a model are to be the same colour, is there any quick way to select that colour in Direct3D without duplicating a diffuse component in all of the vertices? It seems a waste to have a vertex buffer filled with identical colours -- is there a render state or something like that? I tried setting a material, but that seems to have no effect when lighting is disabled.
I *think* you can use a constant DWORD on a texture stage state to do this, though I don't know if most hardware supports this feature or not, or for how long it has.
pDevice->SetTextureStageState(0, D3DTSS_CONSTANT, 0xFFFF0000); //Set the constant to opaque redpDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);pDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_CONSTANT);
It could otherwise be smart to keep the color in the vertices eitherway as that would allow you to batch more efficiently as you don't have to regard to each color (and would allow you to have them differently colored if you would ever like that).
Method #1:
As suggested by Uriel, if you're processing your vertices with a vertex shader, you can just store that constant colour in a shader constant and pass that on for every vertex. This is the most flexible method, but is dependent on using shaders.
Method #2:
As suggested by Agony, if you're using the fixed function pixel pipeline rather than pixel shaders, use the per-texture-stage constant input. Unfortunately this isn't supported on all cards; it seems to mainly be an nVidia thing that a few other vendors have picked up on - most [all?] ATI chips don't support it for example.
Method #3:
If you're using the fixed function pixel pipeline rather than pixel shaders, you can use TEXTUREFACTOR which is really a global constant; similar to method 2, but the same constant is used for all texture stages. TFACTOR is supported on almost all hardware. Only caveat is drivers for really old hardware might not treat TFACTOR correctly.
dev->SetRenderState( D3DRS_TEXTUREFACTOR, 0xFFFF0000 ); // opaque red
dev->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
dev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TFACTOR);
Method #4:
If you're using D3D fixed function lighting, you can set up a material which provides the constant colour regardless of lighting, say with ambient for example.
As suggested by Uriel, if you're processing your vertices with a vertex shader, you can just store that constant colour in a shader constant and pass that on for every vertex. This is the most flexible method, but is dependent on using shaders.
Method #2:
As suggested by Agony, if you're using the fixed function pixel pipeline rather than pixel shaders, use the per-texture-stage constant input. Unfortunately this isn't supported on all cards; it seems to mainly be an nVidia thing that a few other vendors have picked up on - most [all?] ATI chips don't support it for example.
Method #3:
If you're using the fixed function pixel pipeline rather than pixel shaders, you can use TEXTUREFACTOR which is really a global constant; similar to method 2, but the same constant is used for all texture stages. TFACTOR is supported on almost all hardware. Only caveat is drivers for really old hardware might not treat TFACTOR correctly.
dev->SetRenderState( D3DRS_TEXTUREFACTOR, 0xFFFF0000 ); // opaque red
dev->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
dev->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TFACTOR);
Method #4:
If you're using D3D fixed function lighting, you can set up a material which provides the constant colour regardless of lighting, say with ambient for example.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement