i noticed some strange artifacts produced by my projector when using a texture with border-mipmaps off. It had streaks going in four directions. Now when I enabled border mipmaps, the artifacts were gone. I’d like to understand why that is the case. What exactly does the border-mipmaps setting do and why does it fix the streaks?
It copies the border pixels from the texture into each mipmap level. So for example if the border of the texture is black, then with “border mipmaps” on, all mip levels will have black border.
Otherwise the smaller mip levels could get gray border (for example), because each level is downsampled previous level.
Digging through Unity forum I found your answer and I was wondering if the border problem could be related to the bug in my shader.
I did some experiments and I found out that disabling mipmap generation make the artifacts shown in the images to disappear.
I tried then to reanable mipmap generation on texture loading and check the Border Mip Maps option in the inspector, but this doesn’t work either.
Have you got any idea on how can I solve this problem?
In addition, is possible to know how exactly the border are generated by enabling that option?
I think this is because across that pixel, the UVs technically get stretched back across the texture to the starting point. The extreme amount of shear probably means the mips kick in.
If I’m right, there’s no easy way around it other than splitting your mesh into grids and properly aligning the UVs to that one bit of texture.
Coud you elaborate a little bit? I’ not sure of having completely understood .
If I understood right,I tried refine my mesh. Now at the discontinuity point there is exactly a vertex with the uvs properly set, but it seems to change nothing.
Well your shader means that for the pixel right on the edge of your segment of texture, the U coord gets looped from 1.0 back to 0.0 (dunno what the real values are). It’s such an abrupt change that it causes the mip map to show up.
So even if you fix your mesh, you’ll need to take that UV looping code out of the shader because that’s what’s causing the issues.
Thanks for your answer, without you I don’t think I’d found the right way to go. I actually I’ve been able to solve this problem using the Cg overload of tex2D that let me specify derivatives (calculated using ddx and ddy). Unfortunately this seems not to work on mobile (iOS), but I’ve read this article http://http.developer.nvidia.com/GPUGems/gpugems_ch25.html and it seem that there are workarounds.
I know its a very old thread, but I can’t find anything on this in the newer Unity versions (> 2017).
How would I set this via script?
What alternatives do I have to prevent “wrong border pixels” as Aras mentioned?