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

Started by
2 comments, last by simco50 5 years, 8 months ago

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

Advertisement

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.

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.

This topic is closed to new replies.

Advertisement