1. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  2. Unity 2017.2 beta is now available for download.
    Dismiss Notice
  3. Unity 2017.1 is now released.
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Reddit AMA with Adam Myhill on Cinemachine, Thurs July 27 - 10AM PT. More info.
    Dismiss Notice
  6. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  7. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice

What does the border-mipmaps setting actually do?

Discussion in 'Shaders' started by kork, Jul 16, 2009.

  1. kork

    kork

    Joined:
    Jul 14, 2009
    Posts:
    211
    Hi,

    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?

    Kind regards,
    Kork
     
  2. Aras

    Aras

    Graphics Plumber Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,522
    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.
     
  3. kork

    kork

    Joined:
    Jul 14, 2009
    Posts:
    211
    Ahh, i see. Thanks for the explanation.
     
  4. Heisenbug

    Heisenbug

    Joined:
    Aug 31, 2012
    Posts:
    40
    I'm experiencing some sampling artifacts while trying to repeat textures using fmod. Here's the related open thread: http://stackoverflow.com/questions/14737910/cg-repeating-a-texture-using-fmod-causes-aliasing.

    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?
     
  5. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    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.
     
  6. Heisenbug

    Heisenbug

    Joined:
    Aug 31, 2012
    Posts:
    40
    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.
     
  7. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    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.
     
  8. Heisenbug

    Heisenbug

    Joined:
    Aug 31, 2012
    Posts:
    40
    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.

    thanks again