I am creating a game where I have platforms of different sizes - but always in multiplications of 8 pixels and always 8 pixels high.
All platforms use the same texture like the one here:
The texture is divided up into three 8x8 sections. I want to be able to "tile" this texture via the fragment shader so that the first 8 pixels are applied only at the left end - the middle 8 pixels tiles for as many pixels as the width of the geometry minus the last 8 pixels where the "end" tile is rendered. Something like this geometry which is 32 pixels wide and 8 pixels high:
The framework I use does not allow setting the vertices and UVs (just a simple textured quad) so I cannot fix this in the geometry.
I get the following uniforms in the fragment shader:
sampler2D u_texture - The texture above
vec2 u_sprite_size - The size of the geometry I want to tile the texture in (in pixels)
.. and this varying:
- vec2 v_tex_coord - The coordinates used to access the texture. These are normalized so that the point (0.0,0.0) is in the bottom-left corner of the texture.
It is possible to add other uniforms via code.
Can someone point me in the direction of how to create the fragment shader?