D3DVERTEXELEMENT9

Started by
9 comments, last by glJack 18 years, 9 months ago
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?
Advertisement
Are you sure the problem is in this vertex declaration? Perhaps the supplied texture coordinates are wrong?

Illco
Do you need to include the binormal in the vertex declaration? I always just calculate in the shader.
--m_nPostCount++
As Illco said, your vertex declaration seems fine. Double check to make sure you've supplied the right texture coordinates.

neneboricua
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.
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
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.
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.
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
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 );

This topic is closed to new replies.

Advertisement