Here's a shadertoy example of the issue I'm seeing:
https://www.shadertoy.com/view/4dVGzW
I'm sampling a texture by sampling from floor-ed texture coordinates:
#define GRID_SIZE 20.0
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 uv = fragCoord.xy / iResolution.xy;
// Sample texture at integral positions
vec2 texUV = floor(uv * GRID_SIZE) / GRID_SIZE;
fragColor = texture2D(iChannel0, texUV).rgba;
}
The bug I'm seeing is that there are 1-2 pixel lines sometimes drawn between the grid squares.
Note that we've seen this issue not only using GLSL ES on the web, but also HLSL in Unity.
Is there something to do with floor()
and floating point arithmetic that I don't understand?! I'd love to know not just how to fix it, but why exactly it's happening?