With some margins, the edges of the internal texture are normal. With other margins, the edges are bad.
It seems to be related to mipmaps. When mipmaps are disabled, there are no distorted edges. But the result is very ugly. Please share your thoughts on solving the problem.
Thanks. I’ve been thinking about it too. But this method does not work at all. The best thing I found is to manually set the MipMaps level. It remains to figure out how to calculate the appropriate level of MipMaps.
The issue in the screenshot you posted is 100% that problem. If setting the texture to clamp doesn’t fix it, you’re modifying a different texture, or the problem that remained is not the one in that screenshot.
It is possible with the way you have your shader setup that you’re seeing some other kind of problem. Doing texture samples (tex2D()) inside an if statement can be problematic on some GPUs. The shader compiler is likely to “fix” that for you so that the textures aren’t actually sampled inside a branch, but some won’t. I would suggest using something like this: