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

Vertex shader function usage does not have corresponding usage in the current vertex declaration

Started by fromthefuture Mar 22, 2011 at 6:53 PM 5 replies 2.6k views
Original Post
fromthefuture
fromthefuture
I need help on this one. I don't understand why I'm getting this error.

Vertex shader function usage (D3DDECLUSAGE_NORMAL,0) does not have corresponding usage in the current vertex declaration

This is my code:

in the vertex shader


struct VS_INPUT
{
float3 position : POSITION;
float2 texture0 : TEXCOORD0;
float3 matRow1 : TEXCOORD1;
float3 matRow2 : TEXCOORD2;
float3 matRow3 : TEXCOORD3;
float3 matRow4 : TEXCOORD4;
float3 matCol4 : NORMAL;

};


declaratrion


D3DVERTEXELEMENT9 dummyElms[8] = {

{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, //position
{ 0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 }, //tex coords
{ 0, 20, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 }, //column 4

{ 0, 32, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1 }, //1st row
{ 0, 44, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 2 }, //2nd row
{ 0, 56, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 3 }, //3rd row
{ 0, 68, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 4 }, //4th row


D3DDECL_END()

};


the actual vertex



struct _vertex
{
D3DXVECTOR3 vertPos;
D3DXVECTOR2 texCoords;

D3DXVECTOR3 transformMatrixCol4; //this is the normal field
D3DXVECTOR3 transformMatrixRow1;
D3DXVECTOR3 transformMatrixRow2;
D3DXVECTOR3 transformMatrixRow3;
D3DXVECTOR3 transformMatrixRow4;

};



I'm actually using the normal field in order to pass a transform matrix through a vertex, but I don't see how that would cause an error. As you can see I have the normal declared everywhere and I'm still getting the error. Anyone know why?
Non est ad astra mollis e terris via
MJP
MJP
Are you sure that's the vertex declaration that's set on the device when you draw with that shader? You can use PIX to verify that pretty quickly.
fromthefuture
fromthefuture

Are you sure that's the vertex declaration that's set on the device when you draw with that shader? You can use PIX to verify that pretty quickly.


*sigh* you are right. I made a test declaration in my init. code a few days ago and forgot about it. Thanks MJP, this was rather silly of me.
Non est ad astra mollis e terris via
karwosts
karwosts
Wouldn't you be better off just storing your matrix as 4 float4's? I believe all those float3's get expanded into float4 (the common GPU datatype), so you're taking up 20 bytes instead of 16 by doing that, plus probably some reconstruction headaches as well. I guess you're doing it because you thought it might save space, but I think it's actually worse than the alternative.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
fromthefuture
fromthefuture

Wouldn't you be better off just storing your matrix as 4 float4's? I believe all those float3's get expanded into float4 (the common GPU datatype), so you're taking up 20 bytes instead of 16 by doing that, plus probably some reconstruction headaches as well. I guess you're doing it because you thought it might save space, but I think it's actually worse than the alternative.



You're saying I can use float4s? The reason I'm doing this is because I saw nothing mentioning float4 in the documentation so I though only 3s were allowed. That would be great because right now its a pain in the neck. So I could just do something like [font=CourierNew, monospace][size=2]D3DDECLTYPE_FLOAT4 as D3DDECLUSAGE_TEXCOORD ? [/font]

Non est ad astra mollis e terris via
karwosts
karwosts
Yes, float4 is certainly a type you can use. Internally I believe GPU's used to represent all variables as float4, even when you requested a smaller value (it would use 16 bytes even if you requested a float or float2 or float3). Not positive if that's still the case today, but float4 is a very common type.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
fromthefuture
fromthefuture

Yes, float4 is certainly a type you can use. Internally I believe GPU's used to represent all variables as float4, even when you requested a smaller value (it would use 16 bytes even if you requested a float or float2 or float3). Not positive if that's still the case today, but float4 is a very common type.


Thanks, thats very helpful since right now I have to use 3 row vectors and then one column vector to make a 4x4 matrix that's missing the last element. Appreciate your input on this karwost
Non est ad astra mollis e terris via

Topic Locked

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

Sign in to reply to this topic.