# Borders appearing wrong

This topic is 1953 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello everybody

My problem is actually described completely with the following picture:
[img][url="http://imagr.eu/up/504ece42b36296_de568740285919deb973f1200d9b8163.jpg"]http://imagr.eu/up/5...1200d9b8163.jpg[/url][img]

As you can see the border of all the chunks (each of them is one draw-call) is visible. As i have observed its repeating a tiny part from below on top and from right on the left which means the texture begins to repeat somehow.

Of course for me it seems to be a problem with the texture coordinates as the sampler sets AddressU and AddressV to Wrap which means the texture gets repeated beyond 1 and below 0 and thats exactly whats happening. So i checked my function that generates the texture coordinates which looks like that:
[source lang="csharp"]
{
uint counter = 0;
float tx, ty;
// 17 rows of vertices
for (int j = 0; j < 17; ++j)
{
// All even rows have 9 vertices, the odd ones only 8 and are shifted half the unitsize into the middle
for (int i = 0; i < (((j % 2) != 0) ? 8 : 9); ++i)
{
tx = (float)i;
ty = (float)j * 0.5f;
if ((j % 2) != 0)
tx += 0.5f;
TexCoords[counter, 0] = tx;
TexCoords[counter++, 1] = ty;
}
}
}
[/source]

Just a quick explanation:
Im repeating the texture 8 times on the chunk. The vertices are aligned the following way:
[code]
x x x x x x x x x
x x x x x x x x
x x x x x x x x x
x x x x x x x x
x x x x x x x x x
x x x x x x x x
...
[/code]

After all i couldnt find an error with the coordinates or why they would repeat once more at the end. All the last vertices have either u or v set to 8.

In my shader i have the following:
[source lang="cpp"]
sampler BlendSampler1 = sampler_state
{
texture = <blendTexture1>;
magfilter = LINEAR;
minfilter = LINEAR;
mipfilter = LINEAR;
};
[/source]
Does anyone have a clue where the error could come from or if my calculations are wrong for the texture coordinates?

Plerion Edited by Plerion

##### Share on other sites
Are all the texture tiles placed on a single texture (texture atlas) or are they unique textures ?
In the first case you need to define a border for each sub-texture (8-16 pixels, depends on texture resolution) or you will get mipmapping artifacts at the borders. In the second case you should not use WRAP as texturing mode, but CLAMP. Edited by Ashaman73

##### Share on other sites
The textures are unique and then blended using alpha values for each of the chunks (the chunk is the one with the border). The problem with CLAMP is that i repeat the texture several times on the chunk so the texture coordinates are from 0 to 8 and wrapped. So when i use CLAMP it looks completely odd. Interestingly its still the same that the border can be seen.

##### Share on other sites
Some ideas:
2. As texture mode use clamp, but use only the fractional part of the texture coord to access the texture, here's some shader pseudo code:
[CODE]
vec2 new_tex_coord = fract(tex_coord);
vec4 texture_color = tex2D(textureSample, new_tex_coord);
[/CODE]

##### Share on other sites
Thank you for your tips. I was using the second version but sadly the results are more or less the same. I start to think that theres another problem, not the texture coordinates but i have no idea what it could be.

##### Share on other sites
After some more research i came to the following result till now:
The problem appears now only when i go far away from the terrain, in normal prospective view it all looks like a charm when its near but when i go far away and/or into orthogonal view all borders appear.

Good one:
[img]http://imagr.eu/up/5051c5f80686e2_good.jpg[/img]

Still no problems:
[img]http://imagr.eu/up/5051c6af50ed24_stillgood.png[/img]