Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Bug HDRP Terrain Details Flickering

Discussion in 'World Building' started by ThatProgrammerJack, Jun 5, 2022.

  1. ThatProgrammerJack

    ThatProgrammerJack

    Joined:
    Jan 6, 2019
    Posts:
    30
    Hi there. I’m using HDRP in the latest version of Unity 2022, and I’m painting details onto my terrain. These details use grass prefabs from Unity’s HDRP Terrain Demo Scene, and they are GPU-instanced. Also, I’m using DirectX 12 within Unity.

    The issue is that these details badly flicker. I can’t seem to find the source of the problem. Any ideas?
     
  2. PutridEx

    PutridEx

    Joined:
    Feb 3, 2021
    Posts:
    969
    Could be temporal antialiasing. Go to your camera and disable anti-aliasing, and see if it still flickers once in-game.
    Also scene camera has it's own anti-aliasing setting, you can find it by pressing on the small camera icon.

    Temporal Antialiasing does worse on vegetation that is rendered through unity's terrain, (since it uses instancing), and so they lose motion vectors which TAA relies on to produce better results.
     
    ThatProgrammerJack likes this.
  3. ThatProgrammerJack

    ThatProgrammerJack

    Joined:
    Jan 6, 2019
    Posts:
    30
    I’ll look into it, thank you for the help!
     
  4. ThatProgrammerJack

    ThatProgrammerJack

    Joined:
    Jan 6, 2019
    Posts:
    30
    Tried it out, disabled TAA on both scene and main camera. Did not seem to work. I'm trying enabling the detail objects for lightmapping, maybe that'll help. Any other ideas?
     
  5. PutridEx

    PutridEx

    Joined:
    Feb 3, 2021
    Posts:
    969
    Could you take a video of the issue
     
  6. ThatProgrammerJack

    ThatProgrammerJack

    Joined:
    Jan 6, 2019
    Posts:
    30
    Tried it out, disabled TAA on both scene and main camera. Did not seem to work. I'm trying enabling the detail objects for lightmapping, maybe that'll help. I did, however, just notice this error, could be related:

    Code (CSharp):
    1. DivideByZeroException: Attempted to divide by zero.
    2. UnityEditor.TerrainInspector.GetAspectRect (System.Int32 elementCount, System.Int32 approxSize, System.Int32 extraLineHeight, System.Int32& itemsPerRow) (at <5700f1e4d61f4c96b68ca2ee3cdd8eae>:0)
    3. UnityEditor.TerrainInspector.AspectSelectionGridImageAndText (System.Int32 selected, System.Int32 itemCount, UnityEngine.GUI+CustomSelectionGridItemGUI itemGUI, System.Int32 approxSize, UnityEngine.GUIContent emptyString, System.Boolean& doubleClick) (at <5700f1e4d61f4c96b68ca2ee3cdd8eae>:0)
    4. UnityEditor.TerrainTools.PaintDetailsTool.OnInspectorGUI (UnityEngine.Terrain terrain, UnityEditor.TerrainTools.IOnInspectorGUI editContext) (at <5700f1e4d61f4c96b68ca2ee3cdd8eae>:0)
    5. UnityEditor.TerrainInspector.ShowDetails () (at <5700f1e4d61f4c96b68ca2ee3cdd8eae>:0)
    6. UnityEditor.TerrainInspector.OnInspectorGUI () (at <5700f1e4d61f4c96b68ca2ee3cdd8eae>:0)
    7. UnityEditor.UIElements.InspectorElement+<>c__DisplayClass62_0.<CreateIMGUIInspectorFromEditor>b__0 () (at <68628848f6e642b6b06ef341bae611b2>:0)
    8. UnityEditor.InspectorWindow:RedrawFromNative()
    9.  
    Looks like something may be wrong with the terrain itself in some way.
     
  7. ThatProgrammerJack

    ThatProgrammerJack

    Joined:
    Jan 6, 2019
    Posts:
    30
     
  8. PutridEx

    PutridEx

    Joined:
    Feb 3, 2021
    Posts:
    969
    Yeah that's weird, no way that's caused by anti-aliasing method. Not sure what to be honest.
    Most likely as you said it's a problem with the terrain.

    Try disabling/enabling instancing in terrain settings, see if that changes anything.
    Also try disabling all post processing.
    Finally try disabling Light Layers in your active HDRP asset (the one your using). It's there somewhere.

    If the issue still occurs it's most likely an issue with the terrain or grass shader, not sure what unfortunately.
     
  9. mattb-unity

    mattb-unity

    Unity Technologies

    Joined:
    Feb 7, 2020
    Posts:
    17
    Are you using default shaders or something you've creating with ShaderGraph? Also interested to know the results of testing with GPU instancing turned off.

    If you have a project where you can reproduce the issue reliably (seems like this is the case) I'd say go ahead and created a bug report and we'll take a look.
     
    ThatProgrammerJack likes this.
  10. mattb-unity

    mattb-unity

    Unity Technologies

    Joined:
    Feb 7, 2020
    Posts:
    17
    Also -- is it possible for you to switch to DirectX 11 and see if the issue still occurs?
     
    ThatProgrammerJack likes this.
  11. ThatProgrammerJack

    ThatProgrammerJack

    Joined:
    Jan 6, 2019
    Posts:
    30
    It looks like it's from a TerrainGrass shader graph, but I didn't create it myself. I'm using grass details from Unity's HDRP Terrain Demo Scene. Also, disabling GPU instancing appears to be unsupported. Unity version is 2022.1.2f1, HDRP version is 13.1.8.
     
  12. ThatProgrammerJack

    ThatProgrammerJack

    Joined:
    Jan 6, 2019
    Posts:
    30
    Fortunately, it looks like switching to DX11 worked. Unfortunately, looks like I can't reap the performance benefits of DX12. Thank you for suggesting that, though, and I guess I can finally get on with my project.
     
  13. PutridEx

    PutridEx

    Joined:
    Feb 3, 2021
    Posts:
    969
    DX12 in HDRP doesn't really give better performance, it's slower than DX11. Not sure about DX12 with other render pipelines.
     
    ThatProgrammerJack likes this.
  14. mattb-unity

    mattb-unity

    Unity Technologies

    Joined:
    Feb 7, 2020
    Posts:
    17
    Thanks for following up! Of course we don't want DX12 to be broken so this will need to get fixed. If you have a project that reproduces the issue reliably, a bug report with said project would be awesome.
     
  15. KrystofZacek

    KrystofZacek

    Joined:
    Jul 28, 2020
    Posts:
    7
    I have the same problem on URP. A grass mesh from the latest Unity's Terrain Sample Asset Pack flickers in Game mode (both shadow and the grass) as if it was Z-fighting with itself. Nothing helps (DX11/12, shadow bias, near clipping plane etc). The grass comes with shader "Shader graphs\Terrain grass". In Scene mode the flickering does not occur. Interestingly in a new clean project I cannot reproduce it.
     
  16. ashtorak

    ashtorak

    Joined:
    Feb 19, 2014
    Posts:
    37
    Seems, this didn't get fixed yet, if it's a bug? It's still happening for me in 2022.2.b13 with the latest version of the HDRP Terrain demo. Flickers on DX12 but not 11. I can make a bug report, if necessary. But it seems pretty easy to reproduce and shouldn't happen now with DX12 out of experimental. Especially not on an Unity demo. Or is there some secret HDRP setting that you have to tick to have it work in DX12? :D
     
    ThatProgrammerJack likes this.
  17. ThatProgrammerJack

    ThatProgrammerJack

    Joined:
    Jan 6, 2019
    Posts:
    30
    Good to see the thread is still getting attention. I've been done with the project for about eight months now but it's a little frustrating that DX12, for all its wonderful performance benefits, still has issues with a pretty significant component of the terrain system. I'm building a space game rn but I still hope it gets resolved, and soon.
     
    ashtorak likes this.
  18. ashtorak

    ashtorak

    Joined:
    Feb 19, 2014
    Posts:
    37
    Yeah, if just someone would read the forum :D
    Anyway, I have just submitted a bug report and will keep you updated here on how's it going. That's what I wrote on how to reproduce it:

    Start a HDRP core project, import Unity HDRP Terrain Sample Asset and start the TerrainDemoScene while using DX12.
    Move the camera in scene view and you see flickering of the grass already. Same happens in play mode.
    If you turn DX12 off and use DX11, there is no flickering.
     
    wyattt_ likes this.