Sign in to follow this  
glJack

D3DVERTEXELEMENT9

Recommended Posts

glJack    122
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
Illco    928
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
glJack    122
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
Illco    928
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
glJack    122
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
glJack    122
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
Illco    928
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
glJack    122
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
glJack    122
Quote:

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.


Thanx Ilco. As you can see I've found the error. Once I finish the demo I'll publish the source.
The demo is called Shader Pool. You may take a look at it:
www.glplanet3d.newmail.ru

At the moment only it's OpenGL version is available. My idea is to organize 2 rendering modes(OpenGL and Direct3D) for a single demo. When I finish Direct3D version, I'll publish it as well.

Thank you all for help!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this