Vertex weights not properly passed to shader

Started by
5 comments, last by kauna 10 years, 5 months ago

Where to start with. I am implementing a project based on fbx sdk and directx 11, right now (for quite a while sadly) I have irritating problem with passing weights to shader. I try creating D3DXVECTOR4 with 4 floats and then pass it to vertex structure as with this description:


	polygonLayout[5].SemanticName = "WEIGHTS";
	polygonLayout[5].SemanticIndex = 0;
	polygonLayout[5].Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
	polygonLayout[5].InputSlot = 0;
	polygonLayout[5].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
	polygonLayout[5].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
	polygonLayout[5].InstanceDataStepRate = 0;

It clearly is the most basic way (at least for me), where optimization is not important for now. Vertex structure in hlsl looks like that:


struct VertexInputType
{
	float4 position : POSITION;
	float3 normal : NORMAL;
	float2 tex : TEXCOORD0;
	float hairLen : HAIRLENGTH;
	int4 bonesID : BONES;
	float4 weight : WEIGHTS;
};

Don't bother with other variables - they work. And here comes what bothers me: weights that are equal 1.0f are passed fine, but those <1.0f are messed up. I mean they get larger than 1.0f... like sometimes over 10000.0f... The question is not why, but how I can pass weights without having this problem. I know that I probably should use BLENDWEIGHT, however this gives me some error no matter what. I tried BLENDWEIGHT with rgba16 unorm format to be clear (but I guess my 16 bit data type was anyways wrong, so if I should use this, then how do I have to store weights other than in D3DXVECTOR4... or how to parse it to D3DXVECTOR4 correct?).

All in all, please give me a most straight forward answer, since it's my first directx project. I will surely provide additional information if this was not clear.

Advertisement

I see you have float hairLen : HAIRLENGTH; and I heard there are some alignment troubles. Might have to move this to the end or fix it in some other way (ex. using float4). Other than that I fail to see any problems.

1. When you bind the vertex buffer, what stride are you using?

2. Have you tried changing the location of the weights - (a) in the shader (b) in the VB (c) both - and check what happens?

After long negotiations with my project. You guys are right about the positioning variables in vertex structure. It would seem like all the data I try to parse in bone indices and weights messes up. I will try to find out the problem right now (and probably tomorrow I will share more information, right now I think I caught the problem and I proceed with patching ;) ).

Didn't really go to sleep trying to find out what is wrong (yet another night). Right now I am confused.

I changed position of hairlength to last spot, bones indices and weights still does not work right. Weights are all 0.0f, and bone indices are values way above max index (~1000000000). However it does not bother me the most, but what happened next. I thought - maybe something is wrong with texture coords and moved those to last spot. It didn't change anything... except other shader. I use one shader for hair rendering (one I am trying to get to first) and another one for solid objects. Changing texcoords in hair shader, actually changed texcoords in solid shader. My thoughts are:

1. Is it possible that my graphic card is somehow broken?

2. Is it possible that graphic card driver is broken?
3. If solid object is first in render cycle and then hair shader, then how can it influence previous shader?

It shouldn't affect other shader. Are you sure you're setting right input layout/shader when you render?

Did you change both, shader and IA?

Maybe an alignment issue?

Try #pragma pack(push, 1) before the c++ side vertex structure and then #pragma pack(pop) after it.

Otherwise I'd suggest to save a bit of memory and store the weights in a dword. Since your weights are always between 0-1.0 and don't need extreme precision you can well store them in 8-bit values.

Can you show your skinning shader too?

Cheers!

This topic is closed to new replies.

Advertisement