Custom Texture Atlas problem

hi,



i am trying to use a texture atlas for my meshes. but the problem is that the textures are “sliced”. that looks very strange and the mipmaps are also looks not good. the whole texture is 256x256px and it consists of 16x16 tiles.

i am use this code to get the specific tile:

[java]

public static List<Vector2f> uvMapTexture(final int coordX, final int coordY)

{

// each image is 16x16, the whole image-atlas is 256x256

// coordX: 0…15

// coordY: 0…15

final float s = (float) 16 / (float) 256;

final float c = 0; // correction

final float x = coordX * s;

final float y = (15 - coordY) * s;



final Vector2f bottomLeft = new Vector2f(x, y);

final Vector2f bottomRight = new Vector2f(x + s, y);

final Vector2f topLeft = new Vector2f(x, y + s);

final Vector2f topRight = new Vector2f(x + s, y + s);



return Arrays.asList(bottomLeft, bottomRight, topLeft, topRight);

}



texCoord.addAll(Materials.uvMapTexture(texCoords[2], texCoords[3]));



mesh.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord.toArray(new Vector2f[texCoord.size()])));



[/java]

screenshot:

http://www.alrik-online.de/bug.jpg



are there any solutions to prevent the slices? is it a float division bug?



oh i have to say: the texture i used is from minecraft (terrain.png)

Texture.MagnificationFilter and MinFilter are what you’re looking for. You’re going to want these to be on nearest. Mipmapping doesn’t work too well with texture atlases.

1 Like

ok thanks. but in minecraft it is possible to enable linear/nearest mipmaps (mod optifine) and it works well. how did they do that?



here are two screenshots to compare. in the first screenshot you can see the color change in the distance. on the second it seems to be equal in the distance.

http://www.alrik-online.de/bug1.jpg

http://www.alrik-online.de/bug2.jpg

You need a border in the atlas parts that “extends” the actual border by a few pixels on the atlas image.

ok thanks i understand, but in minecraft has the texture no borders. is there a trick? i want to use the same texture as in minecraft and i need another way than to add borders.

I don’t think you’re allowed to use minecraft assets? Anyway you could just generate them in code if you have to.

@alrik said:
i want to use the same texture as in minecraft and i need another way than to add borders.


It is illegal to use Minecraft's assets (or any other game's assets) in another game unless you have the written permission of the author/company. The only exception is if you're making a mod. jME can't be a Minecraft mod, so, you're not allowed to do that.

its not my purpose to use minecraft’s assets. i only want the same technique to use a textures atlas with mipmaps and without color changes in the distance. for now i use the minecraft asset terrain.png to test my code if it does the same as in minecraft :confused:

You sure the “problem” isn’t lighting? MC’s lighting system is fugly as hell.

@alrik said:
ok thanks i understand, but in minecraft has the texture no borders. is there a trick? i want to use the same texture as in minecraft and i need another way than to add borders.


Well the reason why minecraft only uses 64x64, they DISABLE mipmapping, and with low res textures it is not visible that much.
@madjack said:
You sure the "problem" isn't lighting? MC's lighting system is fugly as hell.

@alrik said:
in minecraft it is possible to enable linear/nearest mipmaps (mod optifine) and it works well.


there is a very visible difference between vanilla minecraft (no mipmaps) and optifine mod (mipmaps enabled) so there must be a way to get mipmapping.

I think mipmapping should not cause bleed as long as the subtextures are on the proper power of two boundaries.



Because your image has single pixel issues even close up, I do not think this is a filter-bleed problem and is more likely a texture coordinate problem. You may have to clamp the values in your shader or something.

1 Like

ok thanks, i will try it

Do you use realtive or absolute positioniongin the shader? There are ways to use pixels instead of 0-1