Jump to content
  • Advertisement
Sign in to follow this  

HLSL Packing Guidance

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

Im having trouble accessing my skinned mesh veriables (boneIndex and boneWeight) in the HLSL (PIX shows different data to my input)

My Vertex definition is:

[color=blue]struct Vertex
Vertex([color=blue]float x, [color=blue]float y, [color=blue]float z,
[color=blue]float tx, [color=blue]float ty, [color=blue]float tz,
[color=blue]float nx, [color=blue]float ny, [color=blue]float nz,
[color=blue]float u, [color=blue]float v)
: pos(x,y,z), tangent(tx, ty, tz), normal(nx,ny,nz), texC(u,v)
memset( boneIndex, 0, [color=blue]sizeof( [color=blue]unsigned [color=blue]char )*4);
memset( boneWeight, 0, [color=blue]sizeof( [color=blue]unsigned [color=blue]char )*4);

D3DXVECTOR3 tangent;
D3DXVECTOR3 normal;

[color=blue]unsigned [color=blue]char boneIndex[4];
D3DXVECTOR4 boneWeight;

[color=green]//Skinning - Supporting a max of 4 bone influences, in practice plenty

My HLSL is:

struct VS_IN
float3 posL : POSITION;
float3 tangentL : TANGENT;
float3 normalL : NORMAL;
float4 boneIndex : BLENDINDICES;
float4 boneWeight : BLENDWEIGHT;
float2 texC : TEXCOORD;

and finally my definition/description is:

D3D10_INPUT_ELEMENT_DESC vertexDesc[] =
{[color=#a31515]"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
{[color=#a31515]"TANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0},
{[color=#a31515]"NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0},
{[color=#a31515]"BLENDINDICES", 0, DXGI_FORMAT_R8G8B8A8_UINT, 0, 36, D3D10_INPUT_PER_VERTEX_DATA, 0},
{[color=#a31515]"BLENDWEIGHT", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 40, D3D10_INPUT_PER_VERTEX_DATA, 0},
{[color=#a31515]"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 56, D3D10_INPUT_PER_VERTEX_DATA, 0}

I have spent a few hours back and forth between PIX and code, and I cant get to the bottom of it.
Any help is greatly appreciated :)

Share this post

Link to post
Share on other sites
You have a bug in your constructor of your vertex.

memset( boneWeight, 0, [color=blue]sizeof( [color=blue]unsigned [color=blue]char )*4);

it should be sizeof(float).

Also you might want to change:

float4 boneIndex : BLENDINDICES;


uint4 boneIndex : BLENDINDICES;

And if you want you can still pack your weights into 4 chars as well, but that is more of an optimization :)
Hope this fixes something for you.

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!