Borders appearing wrong

Started by
4 comments, last by Plerion 11 years, 7 months ago
Hello everybody

My problem is actually described completely with the following picture:
[img]http://imagr.eu/up/5...1200d9b8163.jpg[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"]
private static void LoadTexCoords()
{
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:

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
...


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;
AddressU = WRAP;
AddressV = WRAP;
};
[/source]
Does anyone have a clue where the error could come from or if my calculations are wrong for the texture coordinates?

Greetings and thanks in advance
Plerion
Advertisement
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.
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.
Some ideas:
1. Subdivide your chunks .
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:

vec2 new_tex_coord = fract(tex_coord);
vec4 texture_color = tex2D(textureSample, new_tex_coord);
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.
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:
5051c5f80686e2_good.jpg

Still no problems:
5051c6af50ed24_stillgood.png

Bad one:
5051c727ee3af3_bad.jpg (its the same chunk of map is in the two others just without models and from top)

All the samplers are using trilinear filtering.

I have no idea where this is coming from, but i think that its an issue with filtering, right?

This topic is closed to new replies.

Advertisement