Jump to content
  • Advertisement
Sign in to follow this  
glJack

D3DVERTEXELEMENT9

This topic is 4708 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

What can be wrong with this vertex declaration? D3DVERTEXELEMENT9 decl[]{ {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0}, {0, 3 * sizeof(float), D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0}, {0, 6 * sizeof(float), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0}, {0, 8 * sizeof(float), D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0}, {0, 11 * sizeof(float), D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BINORMAL, 0}, D3DDECL_END() } When I read vertex position in Vertex Shader it is fine, but when I try to read texture coordinate, i get random garbage instead of texcoord values. What's wrong with it?

Share this post


Link to post
Share on other sites
Advertisement
Are you sure the problem is in this vertex declaration? Perhaps the supplied texture coordinates are wrong?

Illco

Share this post


Link to post
Share on other sites
Thanx guys.

I checked the vertex declaration many times, and asked this question just to make sure that the problem isn't in the declaration.

The texture coords I pass to the shader are fine, since, when I use D3DFVF instead of IDirect3DVertexDeclaration9, object is textured properly.

Maybe the problem is in something else. Maybe in rendering, maybe in vertex buffer creation.

What can cause such problem? I think that if problem was in vertex buffer the vertex position wouldn't reach vertex shader, as the texture coords do.


>>Do you need to include the binormal in the vertex declaration? I always just
>>calculate in the shader.
You are right :) I just didn't think about it.

Share this post


Link to post
Share on other sites
Quote:

The texture coords I pass to the shader are fine, since, when I use D3DFVF instead of IDirect3DVertexDeclaration9, object is textured properly.

For using FVF the order of the vertex elements is fixed; for VDs the order is as specified in the declaration. So, check your VB layout and see if it matches the declaration in order. Because, the order as you have it now is not like the FVF order (if I remember well) and yet it works with FVF. Makes me wonder about what the order in the actual VB is...

Quote:

>>Do you need to include the binormal in the vertex declaration? I always just
>>calculate in the shader.
You are right :) I just didn't think about it.

I'd go for supplying them instead of computing them. The penalty is some more storage, the gain is some speed every frame every object every vertex. May be beneficial.

Greetz,

Illco

Share this post


Link to post
Share on other sites
Illco
The order is fine. I checked it.
For FVF it is pos, normal, texcoord.
For my vertex declaration I used the same order, so, there is no need to rearrange vertex data components when switching between FVF and VD

Quote:

I'd go for supplying them instead of computing them. The penalty is some more storage, the gain is some speed every frame every object every vertex. May be beneficial.


binormal evaluation consists of a single cross product and a single normalization. Evaluating it shouldn't cause big loss of performance. But, from the other point removing binormal data from vertex buffer won't cause mentionable economy of memory space.

Share this post


Link to post
Share on other sites
I still experience the same trouble. I found that not only TEXCOORD data, but also NORMAL data is supplied wrong to vertex shader.
Only POSITION is right.

I checked the code many times, but still can't find the error.

Share this post


Link to post
Share on other sites
Strange. Is it a lot of code? Maybe you can post some or make all available for (temporarily) download. I'm happy to look at it as a second eye.

Greetz,

Illco

Share this post


Link to post
Share on other sites
Finally I found the error!

It was as stupid as always.
Look, on what I've been doing:

pDevice->SetVertexDeclaration ( (IDirect3DVertexDeclaration9*) &pVertexDeclaration );

I don't know, for which reason I used this type casting but it compiled without any warnings and didn't capture my attention :)

This way it looks now:
pDevice->SetVertexDeclaration ( pVertexDeclaration );

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!