GLSL Fragment Shader to intelligently tile texture
<p>I am creating a game where I have platforms of different sizes - but always in multiplications of 8 pixels and always 8 pixels high.</p>

<p>All platforms use the same texture like the one here:</p>

<p><a href="https://i.stack.imgur.com/0uzEH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0uzEH.png" alt="Tiling texture image with description"></a>
<br></p>

<p>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:</p>

<p><a href="https://i.stack.imgur.com/1XLNV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1XLNV.png" alt="Tiled platform"></a>
<br></p>

<p>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.</p>

<p>I get the following uniforms in the fragment shader:</p>

<ul>
<li><p><em>sampler2D</em> 
<strong>u_texture</strong> - The texture above</p></li>
<li><p><em>vec2</em>
<strong>u_sprite_size</strong> - The size of the geometry I want to tile the texture in (in pixels)</p></li>
</ul>

<p>.. and this varying:</p>

<ul>
<li><em>vec2</em> <strong>v_tex_coord</strong> - 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.</li>
</ul>

<p>It is possible to add other uniforms via code.</p>

<p>Can someone point me in the direction of how to create the fragment shader?</p>