Apply Effect to single instance of SpriteBatch.Draw

I’ve been attempting to apply a sprite effect to a single call to my SpriteBatch.Draw object, without having to call Begin() with the effect passed as a parameter.

So far, I’ve attempted to call shader.CurrentTechnique.Passes[0].Apply() immediately before the draw call, but as far as I can tell this doesn’t modify the sprite at all when it renders on screen.

Is there a proper method to accomplish this?

won’t work with default spritebatch, since it will overwrite the used shader.

Shader…Apply() will just tell the GPU what shader to use, but afterwards spritebatch does it again when End() is called. So yeah nothing gained. It might be confusing with the whole “apply” thing, but the shader is only really applied once the triangles / quads are drawn.

Either way, it’s most likely fine if you handle that one sprite seperately. If you depend on draw order, just do


spriteBatch.end()
begin
draw
end
begin
… continue

otherwise you can do it before or after all the other draws.

Wouldn’t calling spriteBatch.End() draw all of the queued sprites at that time? If I’m depending on draw order, wouldn’t that effectively break draw order?

If you wanted the sprite with the custom effect to be drawn in a particular draw order position, you would have to do the sorting yourself. You would draw the first batch of sprites that come before the custom sprite using the regular SpriteBatch effect (Begin, Draw, Draw, …, End), draw your single sprite with the custom effect (Begin(effect), Draw, End), then draw the remaining batch of sprites (Begin, Draw, Draw, …, End).