Repeating texture problems

Well my problem is that i finally got the atlas to work, and also the texture is repeating. However i have some lines on the tile borders, that i cant get rid of. If I use the same model without atalsing and use glrepeat it works fine. Also the lines are far larger than one pixel is. Anyone any Idea what might cause this?

(Click link after image to see lines more clearly)

http://i.imgur.com/pkHDF.jpg


uniform sampler2D m_l1_diffuse;
varying vec2 texCoord1;
varying vec2 texCoord2;
varying vec2 texCoord3;
void main(){
vec4 color = vec4(1,1,1,1);
float u = texCoord1.x;
float v = texCoord1.y;
u = mod(u,1);
v = mod(v,1);
float scaleu = texCoord3.x-texCoord2.x;
float scalev = texCoord3.y-texCoord2.y;
u = u*scaleu;
v = v*scalev;
u = u + texCoord2.x;
v = v + texCoord2.y;
color *= texture2D(m_l1_diffuse, vec2(u,v));
color.w = 1;
gl_FragColor = color;
}

Yes I think a similar issue appeared in another thread where the OP was doing a texture atlas system.

I will say the same thing I said to him: The issue is due to mipmapping. Your texture atlas generator can’t just generate level 0 for the mipmap since when it gets scaled down, your 1 pixel borders will get reduced and adjacent textures will be blended with each over.



See the whitepaper from the NVIDIA:

http://http.download.nvidia.com/developer/NVTextureSuite/Atlas_Tools/Texture_Atlas_Whitepaper.pdf

Specifically, the section “Using Mip-Maps with Atlases”.



However, before you do that, I recommend you disable mipmapping on the texture to confirm the issue is indeed with the mipmapping.

1 Like

Yeah thats not my problem actually, I have a 100 pixel border on each tile end for just that problem, it also makes no difference if i set the size to 0 or 1000

Okay, I see. Does the texture atlas work correctly for non-repeating textures?

Yes seems so, also if I do:


if(u > 1){
u = 1;
}
if(u < 0){
u = 0;
}

if(v > 1){
v = 1;
}
if(v < 0){
v = 0;
}


The lines dissapear, so I think it must have to do something with the repeating idea

Yes, the mod() function is to blame here I think. The main point is if the range of the UVs is 0 - 1 exclusive or inclusive.

1 Like

Actually it’s not even that, I haven’t figured it out in a whole day ;(



I prepared a little testproject containing one small textureatlas and the shader + crappy sample model.

If someone with a bit shader expirience here in the forum might take a look at at I would be very thankfull.

http://nh-game.net/ShaderTest.7z

Seems that after all for the repeating there is no real solution as the error happens on the converting from last te xel to the first texel, while normally all texels are hardware based interpolated, there it is only possible with huge amount of shader power, wich defies the useage of an atlas.



I think I will take a deep look into ArrayTextures and try to use them instead as they don’t have that problem.

I looked into your test case, and wasn’t able to get rid of the issue.

I had the same issue with the water normal map, for the water filter.

First i was computing my own texcoord, with a mod like computation.

I resolved it by setting the texture to repeat in JME and just leave the texcoord as they were.

I’m afraid that’s not applicable in your case, but still…this issue is strange.

Hm at least I’m now sure tahts not just my pc. Well I will try to add a support for array textures, as they can be repeated without that issue and are a good solution for my useage as well :wink:

I think you guys are missing something …

See this thread:

2 Likes

Yeah great tahts it :wink:





uniform sampler2D m_l1_diffuse;



varying vec2 texCoord1;

varying vec2 texCoord2;

varying vec2 texCoord3;



float MipmapLevel(vec2 uv, vec2 textureSize)

{

vec2 dx = dFdx(uv * textureSize.x);

vec2 dy = dFdy(uv * textureSize.y);

float d = max( dot(dx, dx), dot(dy, dy) );

return log2( sqrt(d) );

}



vec4 filter1(){



float u = texCoord1.x;

float v = texCoord1.y;

float level = MipmapLevel(vec2(u,v),vec2(256,256));



float scaleu = texCoord3.x-texCoord2.x;

float scalev = texCoord3.y-texCoord2.y;



u = fract(u);

v = fract(v);



u = uscaleu;

v = v
scalev;



u = u + texCoord2.x;

v = v + texCoord2.y;





vec4 color = texture2DLod(m_l1_diffuse, vec2(u,v),level);



return color;

}







void main(){

vec4 color1 = filter1();



gl_FragColor = color1;

}

hey cool you figured it out!

I wonder how slow that code is compared to not using a texture atlas at all :stuck_out_tongue: Probably not much …

1 Like

Depends on models of course, but with batching combined it can still give a 5X boost when there are much objects.