I'm trying to pass blend weight and indices to my vertex shader as float4s; the struct that holds data for each vertex is as follows in C++:
struct VertexType_Skin {
XMFLOAT3 position;
XMFLOAT2 texture;
XMFLOAT3 normal;
XMFLOAT4 boneIds;
XMFLOAT4 boneWeights;
};
and in the HLSL vertex shader:
struct VS_IN {
float3 position : POSITION;
float2 tex : TEXCOORD0;
float3 normal : NORMAL;
float4 boneIds : BLENDINDICES;
float4 boneWeights : BLENDWEIGHT;
};
I'm setting up the vertex buffer as follows in C++:
D3D11_BUFFER_DESC vertexBufferDesc = { sizeof(VertexType_Skin) * vertexCount, D3D11_USAGE_DEFAULT, D3D11_BIND_VERTEX_BUFFER, 0, 0, 0 };
vertexData = { skinVertices, 0 , 0 };
device->CreateBuffer(&vertexBufferDesc, &vertexData, &vertexBuffer);
Now I'm not sure why, but doing this doesn't seem to render my mesh at all. Commenting out the float4s in both structs works fine (I'm not using the ids or weights yet, just trying to pass them).
Is there anything obvious I'm missing in this setup?
Thanks!
Nevermind, I figured it out. I don't know if this can ever help anyone because it's an oddly specific problem, but here goes anyway.
I was sending the mesh data like this each frame (because it was in a base class):
unsigned int stride = sizeof(VertexType);//<-- this struct only contains position, uvs and normals
unsigned int offset = 0;
deviceContext->IASetVertexBuffers(0, 1, &vertexBuffer, &stride, &offset);
deviceContext->IASetIndexBuffer(indexBuffer, DXGI_FORMAT_R32_UINT, 0);
deviceContext->IASetPrimitiveTopology(top);
So doing this instead solved the issue:
unsigned int stride = sizeof(VertexType_Skin);//<-- the updated struct with bone indices and weights
unsigned int offset = 0;
deviceContext->IASetVertexBuffers(0, 1, &vertexBuffer, &stride, &offset);
deviceContext->IASetIndexBuffer(indexBuffer, DXGI_FORMAT_R32_UINT, 0);
deviceContext->IASetPrimitiveTopology(top);
Ta-dah, easy as pie! Cheers :)