0
\$\begingroup\$

This question explains how to use borders to avoid texture bleeding. The following image is taken from the excellent answer to that question.

enter image description here

But the problem I don't understand is, imagine you have an 800x800 texture, and to alleviate the colour bleeding you use a one pixel border to the right. Now when the sampler samples from the last pixel it can blend between the second last pixel and the last pixel (the padding border you put).

However now imagine at a lower mip level. Now picture the image (or atlas, or whatever you want to imagine), instead of being 800 pixels across, is only 4 pixels across. Now the last pixel is located at U value is located at the centre of the fourth pixel, 0.5 + 0.125 + (0.125 /2). Anyway, U value after that (the centre of the fourth pixel) is going to want to be blended with an equally large pixel to the right. That one or two pixel border you put or however big really to the right isn't going to do anything because it was only 2 pixels in an 800 pixel image, and meanwhile in the 4x4 mipmap each pixel covers the equivalent of 200 pixels in the original image.

enter image description here

Please explain.

\$\endgroup\$
2
  • \$\begingroup\$ i dunno i usually just use the blend tool and blend out the edge, like extruding the color outside and it fixes any problem with any edge bleed even when exporting, even to outdated softwares. \$\endgroup\$
    – Cei
    Commented Jul 9, 2023 at 21:02
  • \$\begingroup\$ Imo, you should think in terms of the lowest mipmap level you care about and place all your textures on a corresponding grid. That way, the higher levels have generous padding and the lower levels work as intended. \$\endgroup\$
    – mm201
    Commented Jul 11, 2023 at 18:23

1 Answer 1

6
\$\begingroup\$

You've accurately identified the reason why it's better to store textures like this in a texture array / array texture, where supported, rather than a texture atlas.

In a texture array, each image wraps and mips independently, so samples near the border of one never end up pulling in data from a different image, and you don't need any borders or padding at all.

When you don't have texture arrays available, or you need to pack images of different dimensions, then about the best you can do is add more padding. Take the deepest mip level you want to be able to address, subtract one, raise two to the resulting power, and that's how much padding you need to ensure that even at the deepest mip, your samples never blend between two distinct images.

That can get excessive, so you can also accept some bleeding at deep mips, on the assumption that these objects must be very far or viewed very obliquely for that mip to even be sampled, and so the bleeding will likely be less noticeable.

\$\endgroup\$
2
  • \$\begingroup\$ And why even arrays? Why not just different images? I noticed playing around with my Vulkan implementation that sometimes it asks for an image alignment of about 150kb, that's an enormous loss of memory. The thing about arrays is that it forces you to use the same size. \$\endgroup\$
    – Zebrafish
    Commented Jul 12, 2023 at 6:13
  • \$\begingroup\$ Arrays and atlases allow you to draw multiple objects needing different textures in a single batch. Otherwise you tend to need a separate draw call each time you want to change the textures being sampled. This is a common bottleneck which is why atlassing is such a popular technique for improving performance. \$\endgroup\$
    – DMGregory
    Commented Jul 12, 2023 at 11:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .