Shader Parameter Batching Best Practices

Hi everyone,

I am working on a isometric pixel art graphics pipeline with lighting, and I am running into some issues. I’d like to incorporate custom height maps (to give the scene some “faked” depth for lighting).

This works well so far, but currently it involves me using a custom shader, that samples both the diffuse texture and the custom heightmap texture. Because this parameter could change multiple times within a Begin/End pair, I need to use SpriteSortMode.Immediate.

Visually, everything works. I am getting nice height maps with some good lighting effects. But using SpriteSortMode.Immediate is definitely hurting performance, and its becoming noticeable. A typical draw call draws around 1000 tiles.

Could anyone provide some guidance as to what the best practices are for using per-sprite parameters for shaders, while also taking advantage of batching? How would bigger games get around this issue?

I can’t answer your question but if you put together a sample project that has the issue that could help.

Hello! Well, for example, you can divide a level into tile layers and draw each pass (layer) on a separate rendertarget with the desired SpriteSortMode parameter. Then make a pass through the finished rendertarget by adding a shader. With RenderTarget and SpriteBatch in hand, you can create almost anything you want.