   HLSL structure padding
  Hello everyone,I'm having some troubles defining some structures in the shader from within my program, the problem seems to be with padding, but i don't get why it's not working, currently i have the following code://C++ light structurestruct _hxLight{_hxLight(){ZeroMemory ( this, sizeof ( _hxLight ) );}D3DXVECTOR3 pos;float pad1;D3DXVECTOR3 dir;float pad2;D3DXCOLOR ambient;D3DXCOLOR diffuse;D3DXCOLOR specular;D3DXVECTOR3 att;float spotPow;float range;int type;};//HLSL light structurestruct Light{float3 pos;float3 dir;float4 ambient;float4 diffuse;float4 spec;float3 att;float  spotPower;float  range;int type;};cbuffer cbPerFrame{Light gLight[99];int gLightCount;};//assigning them like this:ID3D10EffectVariable* mfxLightVar;ID3D10EffectScalarVariable* mfxLightCount;mfxLightVar  = _EffectV[0]->_Effect->GetVariableByName("gLight");mfxLightCount = _EffectV[0]->_Effect->GetVariableByName("gLightCount")->AsScalar();int pos = 0;_hxLight lightArray[99];for ( int i2 = 0; i2 < _LightV.size(); i2++ ){if ( _LightV[i2]->_enabled )lightArray[pos++] = _LightV[i2]->_GetRawLight ( );}mfxLightVar->SetRawValue ( &lightArray, 0, sizeof ( _hxLight ) * 99 );mfxLightCount->SetInt ( pos );_GetRawLight methods returns the _hxLight structure required for each element, note that im dealing with arrays of light, not just one ( one works fine ),when debugging, i set a breakpoint before assigning the variables to my effects, the C++ structure array looks just fine, but it is different than the HLSL structure, for example, in the C++ code, lightArray[1].type = 1, so i wanted to test the value from HLSL, added the following in my pixel shader:if ( gLight[1].type == 1 )clip ( -1.0f );it's simply not clipping the pixel, which means there is an error with the structure, so i'm asking, what's wrong with padding over there? is it what's causing the issue?Quote:structure padding occurs so that elements are packed into 4D vectorsso mine should be like thisvec1(pos.x,  pos.y,  pos.z,  pad1  )vec2(dir.x,  dir.y,  dir.z,  pad2  )vec3(amb.r,  amb.g,  amb.b,  amb.a )vec4(diff.r, diff.g, diff.b, diff.a)vec5(spec.r, spec.g, spec.b, spec.a)vec6(att0,   att1,   att2,   spotPow)vec7(range,  type,   empty,  empty)am i missing something there?   
  Oh i found the problem, padding the end of the structure is not empty, it continues from the last structure ( that's why one light worked ), adding 2 pads at the end of the C++ structure fixed it.   