tags:

views:

44

answers:

2

Hi,

I want to use the contents of a vector of D3DXMatrices to my shader.

m_pLightMatrices->SetMatrixArray(&currentLightMatrices[0].m[0][0],0,numLights);

As we know the internals of a vector this poses no problems (as it is just a dynamic array).

Now when I access this matrix in hlsl to fill up a struct I get this strange behavior:

struct LightTest
{
 float3 LightPos; 
 float LightRange; 
 float4 LightDiffuse; 
 float3 LightAtt;
};

float4x4 currentLight = gLights[0];

LightTest lt;
lt.LightPos = currentLight._m00_m01_m02; //{0,0,0}
lt.LightDiffuse = currentLight[1].rgba; //{0,0,0,0}
lt.LightRange = currentLight._m03; //this gives me a value
lt.LightAtt = currentLight[2].xyz; //{0,0,0}

While debugging I see that my matrix is nicely filled with the variables I want. When I try to hardcode check what is in the struct I get all zero's, except the LightRange.

As you can see I tried different methods of accessing the float4x4 but without any other results.

Why oh why is hlsl not copying all my variables ?

A: 

I managed to fix the issue. I do need some clarification on why it works now.

I just put the SetMatrixArray() function before the Input layout is set and suddenly it works perfectly.

Previously it was inside an update function together with all other variables (like world matrices, etc ..) and those work fine.

Tili
A: 

You need to call CommitChanges in order to update to HLSL under some circumstances.

Also, doing this is really kind of evil. Have you tried sending the vectors and such separately?

DeadMG
Evil? You, sir made my day!I was just hacking along because my custom structs were also not working. I though of just send vectors separately, but it's too much work. With some luck I can use a normal struct to transfer my data to hlsl instead of this matrix hack.
Tili