Strange texture coordinates artefacts (iPads)

Hello everyone,


We developing game, with vast landscapes. Landscape size is about 1km x 1km. 
The problem we’ve mentioned recently that we have HUGE artefacts on landscape. It’s looking very strange, and I’ve never seen such artefacts before. Engine is cross-platform, and on PC and Mac everything looks good.

Geometry is landscape.
Coordinates from -330 to 330.
Texture coordinates: from 0 to 1

Issue is the following: 
The closer we move to (1, 1) texture coordinates, the more distortion we have during texture_fetch. You can see the effect on the images. 

http://dl.dropbox.com/u/3262472/Landscape-Artefacts/Corner_0_0_Normal.PNG
http://dl.dropbox.com/u/3262472/Landscape-Artefacts/Corner_1_1_Distorted.PNG
http://dl.dropbox.com/u/3262472/Landscape-Artefacts/Corner_0_0_Single_Texture_Nearest.PNG
http://dl.dropbox.com/u/3262472/Landscape-Artefacts/Corner_1_1_Single_Texture_Nearest_Distorted.PNG

1) Corner_0_0_Normal.PNG - Image in the corner of the map with texture coords (0, 0) - everything looks good (as it supposed). 
2) Corner_1_1_Distorted.PNG - Image of the opposite corner of the map with texture coords (1, 1) - image looks very distorted. 
These images: I replaced our shader with simple texture and enabled NEAREST filter. 
Results are very strange: 
3) Corner_0_0_Single_Texture_Nearest -  Image in the corner of the map with texture coords (0, 0) - everything looks good (as it supposed). 
4) Corner_1_1_Single_Texture_Nearest_Distorted - Image in the corner of the map with texture coords (1, 1) - everything looks very bad. 
Seems about 20% artefact during fetch in texture coordinates. 
Shaders below. 

PS. 
Precision modifiers in shader do not help at all.  We’ve tried to use highp for everything and it doesn’t help. 

Can anyone help me how to resolve this issue. If you saw such artefacts please write us. 

Fragment shader:
https://github.com/dava/dava.framework/blob/development/Tools/ResourceEditor/Data/Shaders/Landscape/tilemask.fsh
Vertex shader: 
https://github.com/dava/dava.framework/blob/development/Tools/ResourceEditor/Data/Shaders/Landscape/tilemask.vsh





Hi,

Do you see the problem if you set color as:
lowp vec3 color = (color0) * lightMask.rgb;[/CODE]?

Can you explain what the purpose of the mask is? Would it be possible to bake everything into a single texture instead?

Thanks,
Joe

lowp vec3 color = (color0) * lightMask.rgb;?

Can you explain what the purpose of the mask is? Would it be possible to bake everything into a single texture instead?

Thanks,
Joe





Hello, 


I am sorry in the thread i’ve posted full shader we’ve used on landscape. To produce these 2 images we’ve used very simple shader, with only 1 texture: 

#ifdef GL_ES
// define default precision for float, vec, mat.
precision highp float;
#else
#define lowp
#define highp
#define mediump
#endif

uniform sampler2D sampler2d;
varying lowp vec4 varColor;
varying mediump vec2 varTexCoord;

void main()
{
    lowp vec4 texColor = texture2D(sampler2d, varTexCoord);
#ifdef ALPHA_TEST_ENABLED
    if (texColor.a < 0.9)
        discard;
#endif
// gl_FragColor = texColor * varColor;
gl_FragColor = texColor;
}

Today we’ve made one more test, without texture at all. So we’ve used checker shader 
without texture fetches, picture is the same(noisy borders). So problem is in texture coordinates.
Because we generate checkers according to texture coordinates.

Also we’ve tried to reverse texture coordinates. Problem always appear on the part of the
landscape where texture coords are closer to 1.0.

We had one more idea, we’ve investigated today. U,V can’t be interpolated linearly in screen space, 
so if renderer is scan line based, it should interpolate U/Z, V/Z. 
We assumed that probably it can depend on values we writing to our Frustum matrix(zNear, zFar range). 
Instead of zNear:1, zNear:5000 we’ve
tried zNear:1.0 zNear: 100.0. Again no results.




Any ideas from developers of the hardware? How to deal with these issues? 

Hi,

Apologies for the slow reply.

The artefacts you’ve seen are likely an accumulative error caused by wrapping texture coordinates into high values. For example, if there was an error of 0.001 between a 0.0 to 1.0 range, then using a value of 100.0 for a texture coordinate would mean this accumulated error would be 0.1. This is an unavoidedable situation where the varyings will eventually be impacted by the hardware’s maximum varying precision and is common to all GPUs.

One way of solving this problem is to handle the wrapping yourself to ensure all texture coordinates used are within the 0.0-1.0 range. The most efficient way of doing this would be to use a mod() operation on all of your texture coordinate data before it’s uploaded to GL, but for testing purposes you could also do the mod() in your vertex shader before you assign a value to the varying.

Let us know if this doesn’t resolve the issue for you.

Regards,
Joe