Custom vertex declaration for use in 2D?

Dear all,

I am at a bit of a loss concerning how to pass data to a custom pixel shader when drawing sprites from a sprite batch.

I am drawing a 2D tile-based landscape and would like to additionally pass information on the height of the tile for later use. In 3D, I would use a custom vertex declaration and store the needed information in, e.g., an additional texture coordinate. However, I do not know how to access the vertex declaration when using the SpriteBatch.Draw() method.

Here is the (default) VertexShaderOutput I am using right now:

struct VertexShaderOutput
	float4 Position		: SV_POSITION;
	float4 Color		: COLOR0;
	float2 TexCoord	: TEXCOORD0;

Now, is there a way to use a custom vertex declaration instead?

Alternatively, I could use an additional Texture2D object to pass height information. then I would also need to pass the tile position so that I can relate the height information to the correct tile.

So I am pretty much stuck at the moment, even though I am sure I am overlooking something fundamental. Any help (or alternative approach) would be highly appreciated.


It seems using SpriteSortMode.Immediate() seems to allow me to pass changing values of global variables for each draw call. However, I have the feeling this is a hack …

If you want to use something other than a VertexPositionColorTexture decleration then you can’t use SpriteBatch since it uses only that declaration to create and batch coloured textured quadrilaterals.

You can check out for a tutorial on how to draw geometry without using SpriteBatch.

Thanks, this explained a lot!

If you want to draw simple quads you can use the quadrenderer from this sample:

At least it’s a good headstart I think

Cool project, I will check it out!