Jump to content
  • Advertisement
Sign in to follow this  
AndyGeers

D3D Colours

This topic is 4868 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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 red
pDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
pDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_CONSTANT);

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!