Interpolation within a Texture Atlas

I have a mesh. It can have many different textures on it. To prevent lag n’ such, I switched from individual textures to a single big texture atlas and slightly modified the shader I was using, so the mesh’s parts can have the same material. However, I want the textures to blend between instead of having a hard border, but texture atlases and texture blending can be difficult together.

A way I thought of was to assign an index that points to which texture within the big atlas for each vertex. I use the Type.TexCoord attribute to assign each vertex, but it automatically interpolates in the fragment shader. For example, if I assign “1” to a vertex for grass and assign “2” to an adjacent vertex for dirt, I would get decimal numbers between those, so it wouldn’t know which texture to use. Right now, I would like to know how to prevent this. I googled around found the “flat” keyword, but the shader returned with an error: “Interpolation of texCoord does not match”.

another way is to try it without a shader. custom meshes

try this and anjust the texCoords between 0 and 1. for example the atlas texture is 256 and you want 128x128 tile textures from it. so you can

use the following code for the first texture (top-left):


Vector2f[] texCoord = new Vector2f[4];

texCoord[0] = new Vector2f(0,0);

texCoord[1] = new Vector2f(.5,0);

texCoord[2] = new Vector2f(0,.5);

texCoord[3] = new Vector2f(.5,.5);