Search Unity

Terrain Instancing + Anisotropic Textures = glitches

Discussion in 'General Graphics' started by protopop, Dec 17, 2019.

  1. protopop

    protopop

    Joined:
    May 19, 2009
    Posts:
    1,561
    Im using Unity 2019.2.8 for iOS

    Terrain instancing per pixel normals look great. But if I turn on instancing and anisotropy at the same time I get crazy glitches bug in the terrain

    Are there any workarounds, beside disabling Anisotropy?

    IMB_oUdZer.GIF
     
    pokruchin likes this.
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
  3. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    Hi protopop, did you end up submitting that bug report? Was there a case number? Or a workaround?

    I think we are seeing the same problem, the flicker is very similar. (Updates: We have opened a case 1230409 to address this, and can confirm we face the same issue...)

    https://forum.unity.com/threads/terrain-rendering-issue-on-ios-please-help.853132/
     
    Last edited: Mar 25, 2020
    protopop likes this.
  4. protopop

    protopop

    Joined:
    May 19, 2009
    Posts:
    1,561
    No I just changed my options so if you turn on anisotropy it disables terrain instancing and vice versa - I make sure the players never has both on at the same time, although it would make unity games look better if we could use both :)
     
  5. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    We end up using terrain instancing but set the anisotropic filter to per-texture. That workarounds the problem, it breaks if we are using "Force On" mode, even though our ground texture is set to aniso level 0 now.

    Shrug and hope Unity team can reply to my case someday
     
    protopop likes this.
  6. protopop

    protopop

    Joined:
    May 19, 2009
    Posts:
    1,561
    I read forced on actually sets ainso levels to the max so maybe that’s part of the bug.

    I guess if you use per texture than you have to go through each texture to make sure aniso is enabled?
     
  7. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    If aniso level = 0 doesn't overwrite the Force On option, then it's a bug; though I suspect to trigger the terrain bug we need a few more stars to align, because with Per Texture and Aniso level > 0, we don't experience this issue.

    https://support.unity3d.com/hc/en-u...ty-Setting-affect-each-texture-s-Aniso-Level-
     
  8. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Forced On sets the anisotropic level to 9. This indeed was at one time the max "anisotropic level", and the max listed in Unity’s documentation. But it’s not, the documentation is wrong. It's been wrong for a long time since they changed how
    anisoLevel
    worked many, many years ago. You can easily test this by looking at what the current slider range is, which is 0-16. However the "0 = no aniso ever, 1 = no aniso unless forced on" is still true.

    But it's also irrelevant. The bug isn't with any texture users can control. Your ground textures aren't the issue. The issue is the height map texture that Unity generates and passes to instanced terrain patches is likely left at the default
    anisoLevel
    , which is 1.

    But that should also not matter. Textures sampled in the vertex shader using
    tex2Dlod
    , which is where and how the height map is sampled, shouldn't be affected by their anisotropic level. The
    tex2Dlod
    (and it's equivalents on other platforms / API) should explicitly disable anisotropic filtering for that sample as it's telling the GPU to ignore the derivatives used to determine the anisotropic filtering axis. Plus those derivatives only exist when rendering the fragment shader, GPUs don't allow derivatives in the vertex shader because they don't make sense there. So anisotropic filtering should be doubly disabled for any texture sample in the vertex shader.


    The fact it's doing something at all speaks to this being a bug in Metal itself. One that luckily Unity can probably work around by forcing those textures to use a
    anisoLevel
    of 0. But again, apart from not selecting the Forced On option, there's not much you can do about this from our side.
     
    protopop and TerraUnity like this.
  9. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    @bgolus so yeah, we have tested this theory without using Unity Terrain, and observe the following:

    - If we sample a height map texture in vertex using a sampler that has anisotropy set to non-zero (corresponding to Per Texture filtering + Aniso Level 1), then some of the vertices will glitch into wrong positions.

    - If we sample this height map without anisotropy, then things are fine.

    - Instancing doesn't affect the outcome.

    But it seems like such an oversight on Metal's part, I don't know how they manages to miss it.

    (Also checked the compiled shader in Xcode, doesn't see anything strange on the sampling itself, didn't look too deep into the rest of vertex shader, but I assume they are not the problem.)
     
    bgolus likes this.
  10. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Can one of you actually submit a big report for this? Otherwise it'll never get fixed.
     
  11. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961
    We did, with case 1230409, but because we are on 2019.2.17f1, no one got back to us yet.

    If you mean Apple, we will follow up on that.
     
    bgolus likes this.
  12. Shaunyowns

    Shaunyowns

    Joined:
    Nov 4, 2019
    Posts:
    328
    Hey @bitinn, thanks for submitting a bug, I'll chase that up for you!
     
    bitinn likes this.
  13. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    961