•      Sign In
• Create Account

## Borders appearing wrong

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

5 replies to this topic

### #1Plerion  Members

381
Like
0Likes
Like

Posted 10 September 2012 - 11:52 PM

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

Edited by Plerion, 10 September 2012 - 11:55 PM.

### #2Ashaman73  Members

13649
Like
1Likes
Like

Posted 11 September 2012 - 01:22 AM

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, 11 September 2012 - 01:23 AM.

Ashaman

### #3Plerion  Members

381
Like
0Likes
Like

Posted 11 September 2012 - 01:57 AM

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.

### #4Ashaman73  Members

13649
Like
0Likes
Like

Posted 11 September 2012 - 02:05 AM

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);


Ashaman

### #5Plerion  Members

381
Like
0Likes
Like

Posted 11 September 2012 - 02:45 AM

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.

### #6Plerion  Members

381
Like
0Likes
Like

Posted 13 September 2012 - 05:45 AM

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:

Still no problems:

Bad one:
(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?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.