   HLSL and ubyte4
  Hi all,I am trying to implement skinning in vertex shaders using DirectX and HLSL. I am passing four bone indices to the shader as D3DDECLTYPE_UBYTE4. Here's the entire declaration:{{0,  0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},{0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL,   0},{0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD,   0},{0, 32, D3DDECLTYPE_UBYTE4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDINDICES,   0},{0, 36, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT,   0},D3DDECL_END()}In C++, the indices are stored in unsigned chars, like this:struct CustomVertexST{ FLOAT x, y, z; FLOAT nx, ny, nz; FLOAT u, v; unsigned char skin_index[4]; FLOAT skin_weight[4];};I am trying to catch them from inside the shader with an int4. This is the struct:struct VS_INPUT{ float3 position0  : POSITION0; float3 normal0   : NORMAL0; float2 texcoord   : TEXCOORD0; int4 blendindices : BLENDINDICES; float4 blendweights : BLENDWEIGHT;};Then i do:int indices[4] = (int[4])IN.blendindices;but that shouldn't be relevant.The indices seem to be passed incorrectly. Is there something wrong with the way I'm doing this?By the way, this is written for shader model 3.0, my card is a GeForce 6. I am not concerned with compatibility with older cards or anything, I just need to get this thing to run for a university project.Thank you!   
  Only minor detail that I can spot is that your VS decl uses int whereas the SDK documentation states BLENDINDICES as a uint.What sort of incorrect results are you getting? Complete garbage, hard errors? Or something else?Are you checking the debug runtime output? They'll be pretty good at spotting any inconsistencies between the VB, Declaration and signature.hthJack   ;  What card to you have?  Check in the caps viewer if you have UBYTE4 support (older GeForce cards don't), by looking in d3dcap9.decltypes for D3DDTCAPS_UBYTE4.   ;  Many thanks to both of you for suggestions.So I should change the part of my VS_INPUT structure from int4 to uint4, like:uint4 blendindices : BLENDINDICES;?Will try that.My card is a Geforce 6800, so I believe it should support ubyte; I will however check as per your suggestion to make sure.I am unable to use a shader debugger, much to my immense frustration. I am not writing the program from scratch, but rather need to add shader skinning to an existing application. Which apparently has some dodgy coding (for which I am in part responsible), so if I set DX to debug mode and turn the debug info up, it won't even run, even in the state before I added any shader related code. In Release it runs without a hitch. And due to my deadline, I don't have time to try and fix the entire thing; it's massive. Thank you once again, I will go and see what I can make of it.   ;  Make sure you are filling out "unsigned char skin_index[4]" in the correct byte order. This always bites me on platforms where GPU and CPU have different endianness.If the graphics card doesn't support UBYTE4, you can use D3DDECLTYPE_D3DCOLOR and D3DCOLORtoUBYTE4 HLSL intrinsic in the shader to convert.   ;  This is so weird.Apparently all my indices equal zero from inside the shader. The way I found that out was by writing this in the shader:if (indices == 0) draw_garbage; (where i goes from 0 to 3)else draw_model_normally;I get garbage. If i change the if statement to if (indices != 0), model gets drawn properly.So I tried modifying code to pass indices as floats. I changed the part of my C++ struct to FLOAT skin_index[4], changed the vertex declaration to D3DDECLTYPE_FLOAT4, and the vertex shader input struct to float4 blendindices : BLENDINDICES. Testing now reveals that all indices are set to 0.0f.Then I tried passing my floating-point indices as texcoords. Changed vertex declaration to D3DDECLUSAGE_TEXCOORD, changed shader input struct to float4 blendindices : TEXCOORD2. This way, all indices get set to 1.0f.In each case results are always the same regardless of what values I give to indices in C++. By the way, I did check d3dcaps9 for ubyte support, and the card does support it -- but that's obviously not the issue here.Oh, and the same type of testing reveals that weights get passed to the shader correctly.This is so frustrating! Why 0.0f as indices? Why 1.0f as texcoords? I can't even think of what else to try, and if I don't get this to work by the end of the week, I am a dead man!;  I am terribly sorry for wasting your time guys. I have no idea what the original problem was, but at some point, while frantically modifying code trying to do tests, I screwed up the offsets in my vertex declaration. Indices now work, whether as floats or ubytes.   