Textures on procedurally generated mesh have lines in between

I just started on procedurally generated meshes and was going along great until I noticed this nagging problem that I really hope someone can shed some light on. I have a giant quad mesh made up of many little quads, and when I UV map some textures to these quads from a big tilesheet texture lines appear in between each of the little quads. The amount and intensity of the lines change when I change the Wrap Mode and Filter Mode of the tilesheet, though none of the options gets rid of them all, which is what I really want.

The tilesheet is here (only using the bottom left tile) and the UV mapping code is below:

for(i = 0;i < p.quadCount;i++) {
	uv[0 + (i*4)] = new Vector2(0, 0);
	uv[1 + (i*4)] = new Vector2(1.0/p.tileSheetX, 0);
	uv[2 + (i*4)] = new Vector2(1.0/p.tileSheetX, 1.0/p.tileSheetY);
	uv[3 + (i*4)] = new Vector2(0, 1.0/p.tileSheetY);
}

This for loop loops through every quad on the mesh and UV maps a section of the tilesheet to the four corners of every quad, with p.tileSheetX and p.tileSheetY being how many tiles are on the tilesheet (in this case p.tileSheetX = 8 and p.tileSheetY = 7). If I change this to the below:

for(i = 0;i < p.quadCount;i++) {
	uv[0 + (i*4)] = new Vector2(0.01, 0.01);
	uv[1 + (i*4)] = new Vector2(1.0/p.tileSheetX - 0.01, 0.01);
	uv[2 + (i*4)] = new Vector2(1.0/p.tileSheetX - 0.01, 1.0/p.tileSheetY - 0.01);
	uv[3 + (i*4)] = new Vector2(0.01, 1.0/p.tileSheetY - 0.01);
}

then there are no more lines unless you zoom very far out from the mesh, though if you go to 0.001 instead of 0.01 the lines reappear. This seems messy and doesn’t appear very scalable for large tilesheets so I’d like a better fix.

Wrap - Clamp, Filter - Point

alt text

Wrap - Repeat, Filter - Point

alt text

Wrap - Clamp, Filter - Bilinear

alt text

Wrap - Repeat, Filter - Bilinear

alt text

this has to do with mipmapping and antialiasing and stuff, basically there are times the graphics engine will sample the textures border (the white part) to determine an “average” value for texture scaling and antialaising and stuff and you end up with white getting thrown in which screws up the texture color value. The solution is well known.

all textures need whats called padding. Around the edge of the texture you take the texture edge color and yuo just drop it in.

you’d put a nice black border around that blue thing with a black edge and a generally brown texture around that water thing. You dont mark this part as part of the texture.

what you do is you make this padding border on a seperate layer and alpha it out. That way its not seen and is only sampled from.

The other alternative is to “extrude” the edge of the texture.

http://wiki.polycount.com/EdgePadding

this link will help you better understand if needed.