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


1 Answer 1


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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.