2
votes

I think I'm experiencing precision issues in the pixel shader when reading the texcoords that's been interpolated from the vertex shader.

My scene constists of some very large triangles (edges being up to 5000 units long, and texcoords ranging from 0 to 5000 units, so that the texture is tiled about 5000 times), and I have a camera that is looking very close up at one of those triangles (the camera might be so close that its viewport only covers a couple of meters of the large triangles). When I pan the camera along the plane of the triangle, the texture is lagging and jumpy. My thought is that I am experiencing lack of precision on the interpolated texcoords.

Is there a way to increase the precision of the texcoords interpolation?

My first though was to let texcoord u be stored in double precision in the xy-components, and texcoord v in zw-components. But I guess that will not work since the shader interpolation assumes there are 4 separate components of single-precision, and not 2 components of double-precision?

If there is no solution on the shader side, I guess I'll just have to tesselate the triangles into finer pieces? I'd hate to do that just for this issue though.. Any ideas?

EDIT: The problem is also visible when printing texcoords as colors on the screen, without any actual texture sampling at all.

1
Have you verified that the floating point precision of the texcoords is actually the issue? I'm not sure that it is, but allow me a guess: When sampling a texture, the texture coordinates are converted to fixed point, typically with 8 bit of fractional precision. That means that there are only 256 discrete, equidistant locations between two texels where you can sample for. Or, to put it another way: YOu will get banding artifacts if you magnify a texture by more than a factor of 256. - derhass
I have had a similar problem a few days ago. I stopped the banding by making the texture bigger (but yeah that's a very stupid solution). Any advice on how to avoid the problem @derhass? - Jerem
The problem is not texture sampling. I tried just outputting the uv coordinates to the returned pixel shader COLOR, without any texture sampling, and still got the same problem. - shadow_map
I don't magnify the texture. Since the texture coordinates ranges from 0-5000 as the vertex positions, the texture is tiling 5000 times, meaning that from my close-up camera the texture is pretty well aligned with the viewport size. - shadow_map
The visual problem I am experiencing is not really banding. It's more like the texture coordinates are lagging with respect to camera motion. For example, if I pan the camera 5 cm over 100 frames, the texture coordinate (or sampled texture color) of each pixel does not appear to change each frame, but instead like each 20th frame, i.e. each 1 cm of camera movement. (these numbers are just examples to get the idea, not actual measurements). - shadow_map

1 Answers

2
votes

You're right, it looks like a precision problem. If your card supports it, you can indeed use double precision floats for interpolation. Just declare the variables as dvec2 and it should work.

The shader interpolation does not assumes there are 4 separate 8bit components. In recent cards, each scalar (ie. component in a vec) is interpolated separately as a float (or a double). Older cards, that could only interpolate vec4s, were also working with full floats (but these ones probably don't support doubles).