Internal texture repeat


I am wondering if there is some way to repeat parts of a texture. For example, let’s say I have a scene with floor and walls, where both use their own repeated texture patterns. Is it possible to combine these two textures into one (meaning just one texture bind) and still repeat individually?

Thanks in advance

yes (using fragment shaders) but may not bring good performance …

It would be extremely difficult to make it work correctly in a fragment shader, because of the corner cases, when the fragment is between the two edge texels on the opposite side. The problem is that you have no control over subpixel texel sampling at the borders. I mean on the edge, the sampler will sample the next pixel, not the one at the other side of the tile. You would have to switch to nearest filtering, sample the two sides separately, and then interpolate yourself. And then I didn’t even mention handling mipmaps!!

Bottom line is: don’t do it.

Okey, thanks

It can be done, but you’ll need the GL_ATI_shader_texture_lod extension if you need it to work with mipmaps. To solve the edge problem you can pad each subtexture with its edge pixels. You’ll still get problems with mipmap selection at edges. For this reason you need to compute the gradients before the frac() function, then use the texture2D_ATI() function to sample the texture with these gradients in the end. That will solve the mipmap selection problem that would otherwise occur when the texture coordinates wrap around.

or u could simply use 2 different sets of texture coordinates :slight_smile:
wait i didnt see the word parts, by parts do u mean a subregion of the texture, if so ignore what i said.

What the heck is GL_ATI_shader_texture_lod and I couldn’t see it in the extregistry. Is info on it in the ATI SDK?

It adds texture lookup functions that take gradients, like this:

vec2 dx = dFdx(texCoord);
vec2 dy = dFdy(texCoord);

if (branch_condition){
    // Sample with gradients. Works inside dynamic branching
    vec4 tex = texture2D_ATI(Sampler, texCoord, dx, dy);

There’s a short paper on it in the SDK, and the RayTracing and ParallaxMapping samples use it.