Problem with texture edges

Started by Daslee, December 09, 2013, 19:39:37

Previous topic - Next topic

Daslee

Hello. I am working now with VAO and I needed to use multiple textures, so I started using sprite sheet. The problem is, when I moved to sprites texture edges has changed to something weird it seems to be transparent or other sprites overlapping that texture. Here is image how it looks: http://s27.postimg.org/u6b2v6k0j/problem.png

In texture file there isn't problem.

This how I generate my tex coords:
float xsize = (float)32 / Textures.spriteWidth; //Sprite width / Image (texture) width
float ysize = (float)32 / Textures.spriteWidth; //Sprite height / Image (texture) height
		
return new float[]{
		xsize*xindex, ysize*yindex,
		xsize*(xindex+1), ysize*yindex,
		xsize*(xindex+1), ysize*(yindex+1),
		xsize*xindex, ysize*(yindex+1)
};


I also tried to set my texture wrap_s and wrap_t to GL_CLAMP_TO_EDGE and tried GL_CLAMP, but no one fixes my problem. So where could be the problem?

Cornix

If you use linear filtering you should usually leave 1 pixel in between different images in a texture atlas.
Otherwise the filtering could pick colors from adjacent sprites.

Daslee

But I'm not using linear filtering, I'm using GL_NEAREST. What could be another solution?

Fool Running

One thing you could try is subtracting a fudge-factor from the ends of your texture coords:
final float fudge = 0.01f;
float xsize = (float)32 / Textures.spriteWidth; //Sprite width / Image (texture) width
float ysize = (float)32 / Textures.spriteWidth; //Sprite height / Image (texture) height
		
return new float[]{
		xsize*xindex+fudge, ysize*yindex+fudge,
		xsize*(xindex+1)-fudge, ysize*yindex+fudge,
		xsize*(xindex+1)-fudge, ysize*(yindex+1)-fudge,
		xsize*xindex+fudge, ysize*(yindex+1)-fudge
};

If that fixes the problem, then you are definitely getting texture bleed.

Another, I think unlikely, possibility is that your polygons are not actually touching. Make sure that the vertex position of one polygon ends at the exact location as the next one starts.
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

Daslee

fudge fixes the problem except for those quads which are far away from camera. http://s10.postimg.org/ph9wxg189/problem.png As you can see, far quads still getting that problem.

And trust me, there is no spaces between cubes, because if I do not use sprite sheet and those tex coords, then everything is fine, but then I can use only one texture per all cubes. Here is how it looks with one texture: http://s16.postimg.org/qcwh4jhcl/problem1.png

Cornix

Are you using mipmaps? Because when generating mipmaps different tiles might also bleed together and their colors mix up.
This would explain why the tiles which are far away show this problem.

Daslee

Yes, I'm using mipmaps, but it doesn't changes nothing even if I do not use it.  :-\

Fool Running

Could we see a screenshot of the problem without mipmaps?
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

Daslee

Without mipmaps and without fudge: http://s12.postimg.org/gxm2ka2cd/withoutmipmapfudge.png
Without mipmaps and with fudge: http://s12.postimg.org/l80qfv7fh/withoutmipmapwithfudge.png

EDIT: I found the problem. It occurs when I set samples greater than 0 in PixelFormat, but why?

Cornix

Thats anti-aliasing. It also filters the texture and can lead to bleeding.

Daslee

And there isn't any way to fix it without disabling anti-aliasing?

Cornix

Did you try leaving 1 pixel between each sprite in your texture atlas?

Edit: An alternative might be to use texture arrays instead of texture atlases.
Texture arrays require openGL 3.0 however.

Daslee

Yes, I tired, but it didn't helped. Only thing what can help in here so increasing fudge, but then texture is like cropped from center and greater fudge will makes texture smaller. Or disabling anti-aliasing, but I do not want to disable it.

Cornix

If you dont want to use texture arrays you could also try to implement your own multisampling with shaders. Maybe you could tweak it in a way that satisfies your needs.

Daslee

I'm newbie at shaders, so I couldn't do that. ;D I think I'll just use fudge, because that way fixed my problem mostly.