Jump to content
  • Advertisement
Sign in to follow this  
lucky6969b

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!