Sign in to follow this  
inimical14

Sending data to Vertex Shader (dx9)

Recommended Posts

inimical14    100
I'm trying to pass a 3-dimensional vector (along with some other things) to my vertex shader, but for some reason my code is not working right.

My vertex structure and declaration are as follows:


struct VERTEXTEXTURED
{
float x, y, z;
D3DVECTOR normal;
D3DXVECTOR2 TexCoords;
D3DVECTOR texWeights;
};

D3DVERTEXELEMENT9 vertexDecl[] =
{
{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_TEXCOORD, 1},
D3DDECL_END()
};



My mesh is created with the following code:


D3DXCreateMesh((WIDTH - 1) * (HEIGHT - 1) * 2, WIDTH * HEIGHT, D3DXMESH_MANAGED, vertexDecl, p_Device, &mesh);



After the mesh is created I copy my vertex and index information into the appropriate buffers.

My vertex shader input structure is:


struct VertexShaderInput
{
float3 Position : POSITION;
float3 Normal : NORMAL;
float2 UV : TEXCOORD0;
float3 TexWeights : TEXCOORD1;
};



And here is what I do with it:


VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
VertexShaderOutput output = (VertexShaderOutput)0;

float4 Pos = float4(input.Position.xyz,1);
output.Position = mul(Pos, WorldViewProjection);
output.Normal = mul(input.Normal, WorldInverseTranspose).xyz;
output.UV = input.UV;
output.TexWeights = input.TexWeights;
return output;
}



The problem is TexWeights contains all 0's, and not the information I set when I created the vertices in my application. Every other variable contains correct values.

I know the problem is not with my pixel shader because when I hard code TexWeights to a certain value in my vertex shader, rather then setting it to the input it works fine. (output.TexWeights = float3(1.0f, 0.0f, 0.0f); for example)

I'm not sure where the problem is, and I've searched around for hours trying to find the solution. Any ideas would be greatly appreciated.

[Edited by - inimical14 on December 1, 2010 8:04:19 PM]

Share this post


Link to post
Share on other sites
Noggs    141
Your code looks fine to me. I can't suggest anything other than try switching to DirectX debug runtime bumping the DirectX debug level up (Start->DirectX Control Panel->Direct3D 9->"Use Debug Version of Direct3D 9" and "Debug Output Level")

This may give you some warnings and errors in the output window.

Share this post


Link to post
Share on other sites
unbird    8335
Can't spot anything suspicious either, and you have done a fair amount of narrowing down the problem. My next approach - apart from the DX debug runtimes - would be to run it through PIX and e.g. make sure the texcoords get to your vertex shader at all: Find the draw call of interest and check the mesh tab. There you can see the vertices values before the vertex shader processing. And I'd also check against the reference device to exclude a driver issue or some weird card incapabilities, though I doubt it's the latter.

Share this post


Link to post
Share on other sites
inimical14    100
Looks like my vertex shader is only receiving the first float of TexWeights. According to PIX the shader is receiving: ( 0.000, -431602080.000, -431602080.000 ). The y and z components are always the same, -431602080.00, no matter what I try to pass in.

Share this post


Link to post
Share on other sites
unbird    8335
In hex this value is CDCDCDCD. This smells like a magic number, it could actually be the one I found here.
Quote:
CDCDCDCD : Used by Microsoft's C++ debugging runtime library to mark uninitialised heap memory
If this is not just a coincidence: Does that ring any bells, e.g. is there something off with your memory allocation ?

If it is a coincidence, look out for that value anywhere in your code (or includes).
Can you show us your vertex buffer update code ?

Share this post


Link to post
Share on other sites
inimical14    100
I found the source of my issue. Thanks for pointing out that -431602080.000 is actually the default for uninitialized memory. I went through all my code that initializes my VERTEXTEXTURED objects and found a y where an x should be.

Everything works correctly now.

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