# Could anyone please show me the correct way to load an array of matrices into a shader?

## Recommended Posts

If I had an array like this

	uniform extern float4 lightDirs[4];


How can load the lightDirs from the program?

	m_effect->SetMatrixArray(lightDirs, &lightDirs[0], 4);


or

	m_effect->SetMatrix(lightDirs[i], &lightDirs[i]);


where lightDirs in this case is an array of D3DXHANDLE?

Thanks

Jack

##### Share on other sites
Posted (edited)

Oh no, I see effects framework and that makes me sad. Are you using DX9 or DX11? If DX11, you should really stop using the effects framework, and use the standard API. That way you can use ConstantBuffer, StructuredBuffer and Buffer types in your shaders, all which have different performance characteristics and use cases.

It's been a really long time since I used DX9 or DX11 effect framework, so unfortunately I can't help you here (maybe you can use other buffer types with it, I don't remember?), and I think it seriously limits what you can do with graphics programming.

Edited by turanszkij

##### Share on other sites

I agree with turanskij.

Anyway, I've used the FX library once before and if I understand the question correctly, I suppose something like this is what you want:

XMFLOAT4 lightDirs[4];
m_pEffect->GetVariableByName("lightDirs")->AsScalar()->SetFloatArray(reinterpret_cast<float*>(&lightDirs[0]), 0, 16);

I'm also a bit confused about your question. You're talking about an array of matrices while you have an array of float4's.

## Create an account

Register a new account

1. 1
2. 2
3. 3
4. 4
frob
14
5. 5

• 16
• 12
• 20
• 12
• 19
• ### Forum Statistics

• Total Topics
632168
• Total Posts
3004529

×