Sprites on Quads?

Essentially, what I’m trying to do is have a varying number of quads, that can be different sizes, have animated sprites on them. Creating the quads isn’t the issue here - my issue is that I don’t possess sufficient knowledge of how shaders work to properly implement this.

I don’t want point sprites - odds are that I’ll have sprites that go far over the size limit on a point sprite.

The basis of the sprites that I have is that each individual sprite, a TextureSprite, have X, Y, Width, and Height variables. Essentially this points to a texture you’ve drawn. I know that I need to pass these variables to the shader (something like that) and convert them to UV coordinates - I’m simply very confused as to how I would actually go about doing this.

I’ve made a material definition that also has what I think are the proper variables:

MaterialDef Sprite {
MaterialParameters {
Texture2D ColorMap
Int x
Int y
Int width
Int height

Technique {
	VertexShader GLSL100: ./Shaders/sprite.vert
	FragmentShader GLSL100: ./Shaders/sprite.frag
	WorldParameters {


I have the vertex and fragment shaders as well:

uniform mat4 g_WorldViewProjectionMatrix;

attribute int x;
attribute int y;
attribute int width;
attribute int height;
attribute vec3 inPosition;

varying vec2 texCoord0;

void main() {
gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);
texCoord0 = vec2(float(x) / float(width), float(y) / float(height));

varying vec2 texCoord0;
uniform sampler2D m_ColorMap;

void main() {
vec4 tex = texture2D(m_ColorMap, texCoord0);

gl_FragColor = tex;


So, with all this in mind, does anyone have any pointers?

You can use the basic Unshaded material for this for now, no need to make your own. (You can always consider making your own in future but for now using Unshaded will be much simpler).

UV co-ordinates are simply the point in the texture to draw for that point in the sprite.

For example f you split your texture into 4 equally sized sprites then your UVs will be:

0, 0, 0.5, 0.5
0.5, 0, 1, 0.5
0, 0.5, 0.5, 1
0.5, 0.5, 1, 1