Jump to content
  • Advertisement
Sign in to follow this  
Jutsimitsu

Vertex weights not properly passed to shader

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

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.

Edited by Jutsimitsu

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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? 

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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!

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!