3
\$\begingroup\$

I would like to use a custom effect with a regular XNA SpriteBatch. I have a 2D camera which computes a transform matrix, so I need my shader to take this into account.

I have put a world matrix property into my shader:

float4x4 World;

However, it does not get set by SpriteBatch:

spriteBatch.Begin(spriteSortMode, blendState, samplerState,
    depthStencilState, rasterizerState, effect, camera.WorldToScreen);

Everything is rendered properly if I set it manually in the draw loop:

effect.Parameters["World"].SetValue(camera.WorldToScreen);

How can I set up my shader parameters to make SpriteBatch set them up correctly?

\$\endgroup\$
1
\$\begingroup\$

That is explained here by Shawn Hargreaves, the Xna lead coder

http://blogs.msdn.com/b/shawnhar/archive/2010/04/05/spritebatch-and-custom-shaders-in-xna-game-studio-4-0.aspx

\$\endgroup\$
  • \$\begingroup\$ I have looked at that post and I don't think that it is. Could you extract the relevant bit? \$\endgroup\$ – dfgdhdgh Oct 28 '14 at 0:07
0
\$\begingroup\$

In the SpriteEffect source, the world matrix is actually float4x4 MatrixTransform

\$\endgroup\$
  • \$\begingroup\$ I tried changing the shader to float4x4 MatrixTransform; but no luck! \$\endgroup\$ – dfgdhdgh Oct 25 '14 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.