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:


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


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


  • \$\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

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

  • \$\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.