Quantcast
Channel: Question and Answer » hlsl
Viewing all articles
Browse latest Browse all 69

In XNA 4, how can I access SpriteBatch's transformMatrix in my shader?

$
0
0

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?


Viewing all articles
Browse latest Browse all 69

Trending Articles