Texture atlas and repeating textures

Does anyone know some tricks (shaders) to put repeating textures (wrap mode GL_REPEAT and tex coords outside the range [0, 1]) into texture atlases (in order to reduce the number of texture switches) that work with MIPMAPPING, too?

Texture atlases can never work properly with mipmapping.

There is indeed a problem with texture atlas, more exactly the ‘texture bleeding’ problem.

It works fine for font page, sprites, where usually border between bitmap is black and alpha is zero, but for texture altas with different textures, it’s more problematic.

One solution is to use anisotropic texture filtering that reduce a lot the texture bleeding problem, but it is not perfect.

There is a white paper about this subject.

The trick is to create your mipmaps from the original textures and then create your atlas (ie you cannot make your mipmaps from the atlas).

This doesn’t solve the problem but it does minimise it, and with some care it can work ok.

As for your original question about wrapping, that is easily acheived in a fragment shader.

Upload the coord boundaries of your texture within the atlas. In your fragment shader just modulate the varying texcoords to the boundary.

Thanks to all.

The repeating problem without mipmapping has already been solved (we used the suggested solution).

 
uniform sampler2D texture;

void main(void) {
  vec2 texCoord = gl_TexCoord[0].xy;
  vec2 paramU   = gl_TexCoord[1].xy;
  vec2 paramV   = gl_TexCoord[2].xy;

  texCoord.x = fract(texCoord.x) * paramU.x + paramU.y;
  texCoord.y = fract(texCoord.y) * paramV.x + paramV.y;

  gl_FragColor = gl_Color * texture2D(texture, texCoord);
} 

But we have models with several 10s or 100s of (small) repeating textures which really sucks without mipmapping (if viewed from the distance).

How would anisotropic filtering help? Wouldn’t this leed to even more texture bleeding artefacts?

It explains everything in the paper execom_rt linked to.

The mipmapping issue can be solved relatively easily. The only real issue is with artifacts caused by the bilinear filtering of the textures (see p13 of the paper). Anisotropic filtering would improve things because it wouldnt take as much colour from neighbouring dirty pixels.

You could solve the problem entirely by disabling texture filtering and doing your own (clamped) bilinear filtering in the pixel shader. But then I imagine it would be faster to just change textures.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.