Search code examples
javaopenglglsltexturesfragment-shader

Why is my texture mapping with my fragment shader generating lines at texture coordinate jumps?


I'm having a lot of trouble with mapping an equirectangular panorama image on to a simple plane. So far i've got the mapping correct so everything shows up exactly where it should. But my problem is that at the point where my texture coordinates jump from 1 to 0 there is a line. But that line is not simply some line. It has pixels with double size than normal. I'm rendering it directly to my screen without a framebuffer inbetween. I tried to enable multisampling but it didn't affect that line at all. I also tried to get rid of that line by just hiding it behind my camera but then I realized when I look up there is always the line no matter where I turn it. In my code this line is always showing up when I do texture coordinate jump with for example "if" or "atan". Does somebody know that problem or at least can somebody reproduce it?

Image of the Problem


Solution

  • This is usually caused by mipmapping. When you wrap the coordinates yourself, such as during conversion to polar coords, the pixels next to the seam end up with large coordinate derivatives, which means the wrong mip level gets sampled.

    Probably the best solution here is to check whether you actually need mipmaps in this case. On a skybox it usually does not make much of a difference. Otherwise, you'll have to calculate the level of detail yourself, in order to properly take the jump in coordinates into account.

    Yet another way to avoid the issue is to prevent the fragments on both sides of the seam to be rasterized together. You can do that by building your skybox mesh in such a way that a triangle edge always lines up with the seam, so that each side of the seam is in a different triangle.