Skip to main content
GameDev.net gamedev.net
🔒 Locked

[DX9] Turning on/off vertex information

Started by Tar Dec 19, 2010 at 9:23 PM 3 replies 1.2k views
Original Post
Tar
Tar
I have the following vertex declaration (Direct3D 9.0):

D3DVERTEXELEMENT9 VertexPosNormalTexture[] =
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
{0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
{0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
D3DDECL_END()
};

... and I populate my vertex buffer with VertexPosNormalTexture vertices.

Question:
Is it possible to disable/enable one of the components of this declaration in run-time? For example, I would like to turn off D3DDECLUSAGE_TEXCOORD sometimes in order to show the material of the object instead of its texture.
MJP
MJP
If you want to change the behavior of your shader, then you should change your shader. Your vertex declaration should always accurately reflect the contents of your vertex buffer...using an inaccurate declaration is not a reliable way to control the behavior of your shaders.
Buckeye
Buckeye
Quote:
to show the material of the object instead of its texture

In that particular case, set the texture to white or neutral gray instead of the normal texture.
Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly. You don't forget how to play when you grow old; you grow old when you forget how to play.
unbird
unbird
You can safely ignore a input semantic ("vertex information") in your shaders. So switching to another shader could be considered "disabling a semantic".

If you are concerned about "I don't want to send more to the GPU than I need to", DX 9 provides the concept of streams. Basically you split (de-interleave) your vertices by semantics and provide separate vertex buffers. Note: Using streams does not necessarily improve performance, if that's what you are looking for. But they could provide a flexibility you are currently missing: You can disable a semantic by disabling a stream, if the stream/vertex buffer covers that specific semantic only. Just keep in mind that not sending a semantic that a shader expects will fail. So you will have to switch shaders anyway.

This flexibility comes with the price of considerable greater complexity on the administration/setup side, so if you want to keep your life simple, just switch shaders or use dummy textures, as suggested.
Tar
Tar
Thanks for your valuable suggestions!

For now I've used the "dummy texture" method. It's working fine.

If I understand it correctly an alternative would be to create two techniques with different pixel shaders: one employing textures and another one that ignores texture data. This way I could switch from one technique to another in my code hence enabling and disabling textures.

Using multiple streams is the most efficient method as it would allow me to send texture data only when it is needed. As this technique seems to be quite complicated I'll try it later.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.