# Strange texture coordinates artefacts (iPads)

**URL:** <https://forums.imgtec.com/t/strange-texture-coordinates-artefacts-ipads/1415>\
**Category:** PowerVR Insider\
**Created:** [May 15, 2012, 3:22pm UTC](https://forums.imgtec.com/t/strange-texture-coordinates-artefacts-ipads/1415 "2012-05-15T15:22:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![boroda](https://avatars.discourse-cdn.com/v4/letter/b/8dc957/32.png) [@boroda](https://forums.imgtec.com/u/boroda)\
**Post date:** [May 15, 2012, 3:22pm UTC](https://forums.imgtec.com/t/strange-texture-coordinates-artefacts-ipads/1415/1 "2012-05-15T15:22:50Z")

</div>

Hello everyone,

  

We developing game, with vast landscapes. Landscape size is about 1km x 1km.&nbsp;

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:&nbsp;

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.&nbsp;

  

[http://dl.dropbox.com/u/3262472/Landscape-Artefacts/Corner\_0\_0\_Normal.PNG](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_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_0_0_Single_Texture_Nearest.PNG)

[http://dl.dropbox.com/u/3262472/Landscape-Artefacts/Corner\_1\_1\_Single\_Texture\_Nearest\_Distorted.PNG](http://dl.dropbox.com/u/3262472/Landscape-Artefacts/Corner_1_1_Single_Texture_Nearest_Distorted.PNG)

  

1)&nbsp;Corner\_0\_0\_Normal.PNG&nbsp;- Image in the corner of the map with texture coords (0, 0) - everything looks good (as it supposed).&nbsp;

2)&nbsp;Corner\_1\_1\_Distorted.PNG&nbsp;- Image of the opposite corner of the map with texture coords (1, 1) - image looks very distorted.&nbsp;

These images: I replaced our shader with simple texture and enabled NEAREST filter.&nbsp;

Results are very strange:&nbsp;

3)&nbsp;Corner\_0\_0\_Single\_Texture\_Nearest&nbsp;- &nbsp;Image in the corner of the map with texture coords (0, 0) - everything looks good (as it supposed).&nbsp;

4)&nbsp;Corner\_1\_1\_Single\_Texture\_Nearest\_Distorted&nbsp;- Image in the corner of the map with texture coords (1, 1) - everything looks very bad.&nbsp;

Seems about 20% artefact during fetch in texture coordinates.&nbsp;

Shaders below.&nbsp;

  

PS.&nbsp;

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

  

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

  

Fragment shader:

[https://github.com/dava/dava.framework/blob/development/Tools/ResourceEditor/Data/Shaders/Landscape/tilemask.fsh](https://github.com/dava/dava.framework/blob/development/Tools/ResourceEditor/Data/Shaders/Landscape/tilemask.fsh)

Vertex shader:&nbsp;

[https://github.com/dava/dava.framework/blob/development/Tools/ResourceEditor/Data/Shaders/Landscape/tilemask.vsh](https://github.com/dava/dava.framework/blob/development/Tools/ResourceEditor/Data/Shaders/Landscape/tilemask.vsh)

---

<div class="post-metadata">

**Author:** ![JoeDavis](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.imgtec.com/joedavis/32/71_2.png) [@JoeDavis](https://forums.imgtec.com/u/JoeDavis)\
**Post date:** [May 18, 2012, 3:18pm UTC](https://forums.imgtec.com/t/strange-texture-coordinates-artefacts-ipads/1415/2 "2012-05-18T15:18:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![boroda](https://avatars.discourse-cdn.com/v4/letter/b/8dc957/32.png) [@boroda](https://forums.imgtec.com/u/boroda)\
**Post date:** [May 21, 2012, 1:26pm UTC](https://forums.imgtec.com/t/strange-texture-coordinates-artefacts-ipads/1415/3 "2012-05-21T13:26:54Z")

</div>

Hello,&nbsp;

  

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:&nbsp;

  

```
#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()

{

&nbsp;&nbsp;&nbsp;&nbsp;lowp vec4 texColor = texture2D(sampler2d, varTexCoord);

#ifdef ALPHA\_TEST\_ENABLED

&nbsp;&nbsp;&nbsp;&nbsp;if (texColor.a \< 0.9)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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&nbsp;

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,&nbsp;

so if renderer is scan line based, it should interpolate U/Z, V/Z.&nbsp;

We assumed that probably it can depend on values we writing to our Frustum matrix(zNear, zFar range).&nbsp;

Instead of zNear:1, zNear:5000 we’ve 

tried zNear:1.0 zNear: 100.0. Again no results.
```

---

<div class="post-metadata">

**Author:** ![boroda](https://avatars.discourse-cdn.com/v4/letter/b/8dc957/32.png) [@boroda](https://forums.imgtec.com/u/boroda)\
**Post date:** [May 23, 2012, 7:05pm UTC](https://forums.imgtec.com/t/strange-texture-coordinates-artefacts-ipads/1415/4 "2012-05-23T19:05:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![JoeDavis](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.imgtec.com/joedavis/32/71_2.png) [@JoeDavis](https://forums.imgtec.com/u/JoeDavis)\
**Post date:** [June 11, 2012, 10:36am UTC](https://forums.imgtec.com/t/strange-texture-coordinates-artefacts-ipads/1415/5 "2012-06-11T10:36:56Z")

</div>

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
