I have a 1024x1024 texture of tiles that I draw from.
When the camera is at very specific positions I can see a 1 pixel gap appearing between tiles like this:
Upon further inspection, I found out that in the shader (yes, the default one too) the texture coordinates always have the same integer values (for example y value of 360.444 and 360.026 because 360 = 360), but the decimal value after is determined by the final screen position of the drawn object. Meaning the value could fluctuate between 360-360.999. (Actually, the texture coordinates are both between 0-1 where 1 represents the width/height of the texture, I’m referring to the value multiplied by texture width/height)
Why? I have no idea. In theory this doesn’t matter because I’m using PointClamp sampling, but when you have a big texture and the y texture coordinate is at exactly 360 for example, a floating point error can sneak in during the tex2D call and sample the pixel above, so if that pixel is transparent above the tile in the texture you will see a “gap” like this. If you try to draw a black line in the texture just above the tile, you will see that instead.
I “fixed” this by adding 1000th of a pixel to the texture coordinates, but although I have never encountered it if it were to pick, say 360.999, then my problem would appear again the other way around. So how can I fix this properly? It would be best if I could somehow make it aim for the middle of each pixel instead of fluctuating to the absolute bounds of each pixel.
I’m using PointClamp sampling, please do not confuse this with the common problem of using LinearWrap:
GraphicsDevice.SamplerStates = SamplerState.PointClamp;