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:
sprite.j3md
[java]
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 {
WorldViewProjectionMatrix
}
}
}
[/java]
I have the vertex and fragment shaders as well:
sprite.vert
[java]
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));
}
[/java]
sprite.frag
[java]
varying vec2 texCoord0;
uniform sampler2D m_ColorMap;
void main() {
vec4 tex = texture2D(m_ColorMap, texCoord0);
gl_FragColor = tex;
}
[/java]
So, with all this in mind, does anyone have any pointers?