<p>I realized that the problem was that I was sending the instance id to the fragment shader via a varying, somehow that was causing issues even though each vertex should have had the same id.</p>

CC BY-SA 3.0
2016-06-24T19:14:01.930Z
2016-06-24T19:14:01.930Z
J.Doe
<p>So I have a batch draw call I am doing with various squares. I have a 4x4 tile map with the numbers 1-16 going in right/down order.</p>

<p>When it gets to the fragment shader their is a varying float "id" that holds the number. In a perfect world if the id was 0, it would sample the top left and display "0", if the id was 4 it would sample the top right and display "4".</p>

<p>Thankfully this is mostly working! However the numbers 5, 9, and 13 (which happen to be on the left of the tile map flicker! The values on these squares just change frequently. </p>

<p>I have traced it down to being the fault of the sample location. And probably this function here: The goal is to take the id and return the proper row and column to texture map.</p>

<pre><code>vec2 getGrid()
{
    return vec2(float(int(mod(id, 4.0))), float(floor(id / 4.0)));
}
</code></pre>

<p>It appears that the flickering ones have a constantly changing x result from "getGrid()" and most of the squares have an occasionally changing y result from the "getGrid()" call. I really have no clue why this is happening!</p>

<p>It probably has something to do with the way glsl does math because id and everything else (I have checked) and they are constant.</p>

<p>Incase it helps here is the tile map. The texture is actually 2000 x 2000 due to the size these need to be. It will be hard to see because the numbers are white and the background is grey.
<a href="https://i.sstatic.net/RHOzG.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/RHOzG.png" alt="enter image description here"></a></p>

<texture><tile-based-rendering>
Flickering tile map
J.Doe
# Flickering tile map

(Asked by: username_0 on 2016-06-24)

So I have a batch draw call I am doing with various squares. I have a 4x4 tile map with the numbers 1-16 going in right/down order.

When it gets to the fragment shader their is a varying float "id" that holds the number. In a perfect world if the id was 0, it would sample the top left and display "0", if the id was 4 it would sample the top right and display "4".

Thankfully this is mostly working! However the numbers 5, 9, and 13 (which happen to be on the left of the tile map flicker! The values on these squares just change frequently.

I have traced it down to being the fault of the sample location. And probably this function here: The goal is to take the id and return the proper row and column to texture map.

```
vec2 getGrid()
{
    return vec2(float(int(mod(id, 4.0))), float(floor(id / 4.0)));
}

```

It appears that the flickering ones have a constantly changing x result from "getGrid()" and most of the squares have an occasionally changing y result from the "getGrid()" call. I really have no clue why this is happening!

It probably has something to do with the way glsl does math because id and everything else (I have checked) and they are constant.

Incase it helps here is the tile map. The texture is actually 2000 x 2000 due to the size these need to be. It will be hard to see because the numbers are white and the background is grey.
[![enter image description here](https://i.sstatic.net/RHOzG.png)](https://i.sstatic.net/RHOzG.png)

**Tags:** texture, tile-based-rendering


---

## 1 answers

### Answer by username_0 on 2016-06-24. Score: 1 | Accepted answer

I realized that the problem was that I was sending the instance id to the fragment shader via a varying, somehow that was causing issues even though each vertex should have had the same id.


---

