Looking for a solution to the un-repeatable texture atlas problem?

Hi All!

I’ve been doing some digging around the forums trying to find somebody who’s found a solution to the problem where you cannot repeat textures across a single quad (using UV coordinates) where said texture comes from a texture atlas.

Cue fancy images to explain!

So in this example, I’m building tiles, one quad at a time, and texturing them from a single-image texture atlas by manipulating each quad’s UV texture coordinates.

So far, so good, but the above method of rendering the map geometry is inefficient.

So, cue image 2!

This time around, I’ve optimised the level geometry to combine quads that lie on the same row as one another. This makes the geometry three times more efficient, but I immediately fall into the trap I’ve raised this thread for.

From reading other forum posts, it seems impossible to repeat textures that have been ‘snipped’ from a texture atlas, so the above method of combining geometry wouldn’t work - I’d have to render a single, correctly-sized quad for every texture tile I want to place, making it tremendously inefficient.

What I’d like to know is whether or not anybody has solved this conundrum yet?

I can’t imagine that loading up a single image file for each texture tile is a better way around this - because even with an optimised texture binding order (to ensure each texture is only bound once for all geometry that uses it), I can see frames being chewed up and wasted by doing this.

I’m reaching out for some hands-on experience with this problem (and hopefully, a solution!).

Thanks all :slight_smile:

I came up with this:

As you’re working with a column of tiles, you can use texture repeat on a single axis.

Then you copy your column, and rotate every tile 90deg, so you can use the same texture repeat, but over the other axis. This means you have to be a tad smarter about calculating your texcoords, but it’s guaranteed to support both rows and columns of quads. Not rectangles of quads though, for that you need an OpenGL Texture Array. (support is lacking on mobile devices)

This looks like it could be a solution - I’m just trying to wrap my head around it!

Here’s an in-context example of what I mean from my project:

The walls and floor are all being textured from a single image (texture atlas). The floors (and ceilings) can be lowered and raised - which should affect the repeating value of the texture being used.

Here’s an better look at the problem (the walls are ‘2 texture units’ high, where as the floor is made up of 1x1 texture units):

As you can see, since the image is being snipped from a texture atlas, I’m only able to draw 100% of the texture across the whole quad - not, say, 140%.

I might take your advice on looking into OpenGL texture arrays. My target platform(s) at the moment are Windows and Mac. I would hate to rule out mobile support, but the specifics on my issue might end up forcing my hand to an unsupported method of solving this issue :frowning:

I updated my post a bit with more clarification (not just an image)

Thanks! I’ll probably have a look at the OpenGL texture array, as it might be impractical to do rotations with the way my engine has been set up (although I could still change it without too much effort).

Much appreciated!

You write a shader that handles the sampling of the logical texture…or better yet use one someone else wrote.