Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Bug LightLayers with Instanced rendering

Discussion in 'High Definition Render Pipeline' started by nehvaleem, May 8, 2020.

  1. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    440
    Hi,

    I am writing this post to make some awareness of the issue that emerges when using LightLayers with instanced rendering. I think that there is need for some documentation or extending the graphics api to allow creators use of the Light Layers system in HDRP.

    I am using some 3rd party packages such as Vegetation Studio Pro or MicroSplat and I've noticed something really weird. When LightLayers option is enabled in pipeline settings it causes issues with rendering materials for terrain (MicroSplat) or objects instantiated by VSPro.

    For example when using VSPro - How it looks with normal rendering:



    And this is how it looks with instanced rendering:



    As I've mentioned before the issue with instanced rendering with light layers enabled affects not only VSPro, but also assets that deals with terrain shaders (CTS, MicroSplat - every has similiar issue).

    This is how it looks when terrain has "Draw instanced" option enabled.



    When it is turned off, there is no visible artifacts.

    Disabling any of LightLayers or instanced rendering immediately solves the problem. It leads to tradeoff between graphics and performance right now.

    I've talked directly to creators of mentioned assets and there is no way currently for them to tackle this issue. There is no documentation or api whatsoever.

    So I am asking unity team to shed some light onto that matter :)

    Note: I tested this since beta of 2019.3 with HDRP 7.0 through latest 2019.3.13f1 with HDRP 7.3.1. The issue still persists.
     
    TacticalShader, MichalDev and Rowlan like this.
  2. Kamael

    Kamael

    Joined:
    Mar 11, 2013
    Posts:
    15
    Yeah, I have the same problem with flicking when i'm using light layers;/ Waiting for any solution, please.
     
  3. MichalDev

    MichalDev

    Joined:
    Mar 1, 2017
    Posts:
    33
    Hey guys. I'm facing a similiar issue right now and I'm using newest version of Vegetation Studio Pro and some other 3rd party plugins. Would be eternally grateful if someone can introduce a valid solution to that matter. Thanks
     
  4. ahumanbeing

    ahumanbeing

    Joined:
    Dec 5, 2016
    Posts:
    15
    same here, waiting to see how unity responds
     
  5. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    440
  6. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    440
  7. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    I've pretty much given up on Unity answering questions about how their shaders work and stuff like this.
     
    Bordeaux_Fox and Prodigga like this.
  8. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    This.
     
    Bordeaux_Fox likes this.
  9. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    440
  10. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    440
    Time goes by, questions are left unanswered...
     
  11. jbooth

    jbooth

    Joined:
    Jan 6, 2014
    Posts:
    5,461
    Maybe start a large campaign and get everyone to change their icons into a broken light icon..
     
    Bordeaux_Fox, nehvaleem and Kirsche like this.
  12. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    440
    I am one step away from trying to pull that off :)
     
  13. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    440
    I've submitted a bug report: case 1268590. Maybe this would help somehow.
     
    waken likes this.
  14. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    440
    Extra gif demonstrating the issue

     
  15. Shaunyowns

    Shaunyowns

    Joined:
    Nov 4, 2019
    Posts:
    328
    Bug report will totally help us, thank you!
     
    nehvaleem likes this.
  16. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    440
    @Shaunyowns - Almost another month is passing by - could you give us an update regarding?
     
  17. Shaunyowns

    Shaunyowns

    Joined:
    Nov 4, 2019
    Posts:
    328
    Hey I had a look I believe you've been sent a response?
     
    nehvaleem likes this.
  18. thomas-weltenbauer

    thomas-weltenbauer

    Joined:
    Oct 23, 2013
    Posts:
    72
    Hello,
    we have the same problem after enabling the light layers. Is there any solution or estimation for a solution yet?
    Thanks!
     
  19. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    440
    Yes, indeed. Many thanks!

    I've got a response from the QA team with info that the problem is solved in HDRP 10.0.0-preview.27 and above. I can confirm that there is an improvement. Meaning that the artifacts are gone and objects are lit. Sadly the instanced meshes can only receive light from the default light layer. Until the API is extended there is no way to lit instanced meshes using lights from any other Light Layers. The QA team told me that they are currently working on this issue and we could expect a fix in future versions of unity. This being said I doubt that it will land on 2020.2.
     
    maxxa05 likes this.
  20. thomas-weltenbauer

    thomas-weltenbauer

    Joined:
    Oct 23, 2013
    Posts:
    72
    Thanks for the information.
    Sadly I can't find the commit for the fix in Unity's Graphics repository. I want to have a look to check if there is any possibility to backport the fix to HDRP 8.2.
     
  21. SebLagarde

    SebLagarde

    Unity Technologies

    Joined:
    Dec 30, 2015
    Posts:
    936
  22. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    440
    Hi @Shaunyowns, @SebLagarde - circling back because I think that there might be something that caused this issue to resurface. I've upgraded my project from HDRP 10.0.0-preview.27 to 10.2.2 (with Unity 2020.2.1f1) and the issue with the lack of light on instanced meshes when using LightLayers is back sadly :(

    Could you check this one out? Do I have to submit another (the same) bug request?
     
    Last edited: Jan 4, 2021
  23. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    440
    @Shaunyowns, @SebLagarde
    I submitted another bug report, with the updated reproduction project. It got a case number 1303589. I really hope for the fix since it seems to be a regression. It worked in HDRP 10.0.0-preview.27 and it is broken again in HDRP 10.2.2.
     
  24. nayden_dochev

    nayden_dochev

    Joined:
    Nov 11, 2019
    Posts:
    7
    Hi, I experience the same issue.
    HDRP 10.2.2
    The sphere on the left is created from the editor. The sphere on the right is DOTS entity instantiated from the original but it is not affected by the sky.
    upload_2021-1-5_14-9-12.png
     
  25. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    That is a different DOTS specific issue. Hybrid Renderer doesn't yet have proper indirect lighting support.
     
  26. nayden_dochev

    nayden_dochev

    Joined:
    Nov 11, 2019
    Posts:
    7
    Thanks for the info, I thought its the same because the same shader worked fine with 2019 + DOTS + Hybrid renderer 1

    Code (JavaScript):
    1. -    "com.unity.entities": "0.10.0-preview.6",
    2. -    "com.unity.render-pipelines.high-definition": "7.4.3",
    3. -    "com.unity.rendering.hybrid": "0.5.0-preview.6",
     
  27. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    440
  28. nayden_dochev

    nayden_dochev

    Joined:
    Nov 11, 2019
    Posts:
    7
    Indeed, disabling the light layers option in the hdrp settings does not affect my case.
     
  29. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    440
    hi @Shaunyowns
    any updates on the bug? Is there any ETA?
     
  30. UnityMaru

    UnityMaru

    Community Engagement Manager PSM

    Joined:
    Mar 16, 2016
    Posts:
    1,227
    When was the last email you got from case 1303589?
     
  31. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    440
    The last email that I've got from case 1303589 was from Jan 5, but this case was a duplicate and was closed in favor of 1268590.

    The last email regarding 1268590 was sent to me on Jan 18, but it contains no info besides that there is no ETA atm. I am inquisitive about what to do about it - it blocks me from upgrading, it is a regression, and there is no info. The bug was discovered by me almost 9 months ago :(
     
  32. UnityMaru

    UnityMaru

    Community Engagement Manager PSM

    Joined:
    Mar 16, 2016
    Posts:
    1,227
    I am sorry that this has stopped your work :( I'm looking at the bug ticket too and I do see there are still working on it, so it's not a case of it being sat in a queue doing nothing. It'll be a case of remaining patient. The QA team will certainly email you when they have any updates.
     
  33. CosmosBear

    CosmosBear

    Joined:
    Aug 2, 2012
    Posts:
    67
    Just to add a bit more pressure, this issue really problematic for us too, could you please hurry up and fix this issue and while at it could you please stop adding new stuff that can potentially break useful stuff?
     
    nehvaleem likes this.
  34. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    440
    @CosmosBear have you voted on the issue on the issuetracker? I don't know a better way to increase the UserPain value of an issue rather than this.
     
  35. alexandre-fiset

    alexandre-fiset

    Joined:
    Mar 19, 2012
    Posts:
    717
    Hey!

    I was trying to workaround that issue for an important milestone build, and I found out that if you disable and enable light layers on your camera frame settings, it kind of return to the previous HDRP behaviour.

    Long story short that works for me:

    Code (CSharp):
    1.  [RequireComponent(typeof(Camera))]
    2.     public class DemoLightLayersHack : MonoBehaviour
    3.     {
    4.        
    5.         private void OnEnable()
    6.         {
    7.             Debug.Log("Light layer hack applied");
    8.             StartCoroutine(Hack());
    9.         }
    10.  
    11.         private IEnumerator Hack()
    12.         {
    13.             var camera = GetComponent<Camera>();
    14.             if (camera == null) yield break;
    15.             var cameraData = camera.GetComponent<HDAdditionalCameraData>();
    16.             var frameSettingsOverrideMask = cameraData.renderingPathCustomFrameSettingsOverrideMask;
    17.             cameraData.customRenderingSettings = true;
    18.             yield return null;
    19.             frameSettingsOverrideMask.mask[(uint)FrameSettingsField.LightLayers] = false;
    20.             cameraData.renderingPathCustomFrameSettingsOverrideMask = frameSettingsOverrideMask;
    21.             yield return null;
    22.             frameSettingsOverrideMask.mask[(uint)FrameSettingsField.LightLayers] = true;
    23.             cameraData.renderingPathCustomFrameSettingsOverrideMask = frameSettingsOverrideMask;
    24.         }
    25.     }
     
    Last edited: Feb 3, 2021
  36. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    440
    ahh, thank you! I'll try this but only as a last resort. I suppose it won't work during edit time and so it won't be really convenient to work with.
     
  37. CosmosBear

    CosmosBear

    Joined:
    Aug 2, 2012
    Posts:
    67
    I'm going to make a change. org petition, so they fix it... jk, I voted for the issue
     
    nehvaleem likes this.
  38. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    440
  39. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    440
    Sorry for the bump, but I think it is okay since no one is answering and this is really disturbing (I mean changing the regression parameter at this point without any explanation).
    Maybe @Shaunyowns can take a look?
     
  40. alexandre-fiset

    alexandre-fiset

    Joined:
    Mar 19, 2012
    Posts:
    717
    Still marked as not regession. @Shaunyowns please?
     
  41. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    440
    I emailed one of the QA Team members a while ago about this and this is the explanation (I do have permission to post those here):

    After that I wrote about this doesn't sound valid for me, this was the next response I've got:

    After that... I gave up. I'm tired of this and will focus on alternative solutions or workarounds.
     
  42. JarkkoUnity

    JarkkoUnity

    Unity Technologies

    Joined:
    Feb 1, 2021
    Posts:
    17
    Hi there!

    I investigated the issue, and the problem is that currently the instanced draw script API doesn’t provide a good way to pass light layer flags to the low-level rendering code, but the flags are zero-initialized (i.e. all flags off thus no lighting on the instances). I didn’t check the history of the changes, but judging from the code I doubt this has ever been properly fixed, and might have been just a fluke (e.g. uninitialized variables) that it happened to work in a previous build. This might have got “broken” by adding the initialization, thus it’s not considered a regression (just a guess).

    Regardless of the bug status, we are looking to improve the draw API to enable passing the flags amongst other things. There’s a bit ugly workaround you can use meanwhile though via material properties:
    Code (CSharp):
    1. void Update()
    2. {
    3.     int total = width * depth;
    4.     int batches = Mathf.CeilToInt(total / BATCH_MAX_FLOAT);
    5.  
    6.     int flags = 0xff; // enable all light layers
    7.     float flagsFloat = System.BitConverter.ToSingle(System.BitConverter.GetBytes(flags), 0);
    8.     for (int i = 0; i < batches; ++i) {
    9.         int batchCount = Mathf.Min(BATCH_MAX, total - (BATCH_MAX * i));
    10.         int start = Mathf.Max(0, (i - 1) * BATCH_MAX);
    11.  
    12.         MaterialPropertyBlock matProps = new MaterialPropertyBlock();
    13.         float[] renderingLayerFlags = new float[batchCount];
    14.         for (int j = 0; j < batchCount; ++j)
    15.             renderingLayerFlags[j] = flagsFloat;
    16.         matProps.SetFloatArray("unity_RenderingLayer", renderingLayerFlags);
    17.  
    18.         Matrix4x4[] batchedMatrices = GetBatchedMatrices(start, batchCount);
    19.         Graphics.DrawMeshInstanced(mMeshFilter.sharedMesh, 0, meshMaterial, batchedMatrices, batchCount, matProps);
    20.     }
    21. }
    Cheers, Jarkko
     
  43. nehvaleem

    nehvaleem

    Joined:
    Dec 13, 2012
    Posts:
    440
    Hi @JarkkoUnity
    That's something. Thanks for taking your time. I can confirm that this is a functional workaround if anyone is wondering. I guess we have to stick with it until the team will come with a proper solution by extending the API.
     
  44. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    For instanced indirect you can set the light layer mask in the indirect setup function. At this time the unity_RenderingLayer has turned into a float4.

    Set unity_RenderingLayer.x to the flagsFloat

    in the example from @JarkkoUnity the flags int is a 8 bit mask.

    layer 0 = 1
    layer 1 = 2
    layer 2 = 4

    enabling layer 0 and 2 would be 1+4

    int flags =5;
    float flagsFloat = System.BitConverter.ToSingle(System.BitConverter.GetBytes(flags), 0);
     
    Katkob and nehvaleem like this.
  45. DEEnvironment

    DEEnvironment

    Joined:
    Dec 30, 2018
    Posts:
    437
    Hello sir any news or progress regarding this topic
    its been about a year or more and 2021.2 also seams to have the same issues in HDRP specifically
     
  46. JarkkoUnity

    JarkkoUnity

    Unity Technologies

    Joined:
    Feb 1, 2021
    Posts:
    17
    Hi!

    Yes, there is "new draw API" in 2021.2 with a function Graphics.RenderMeshInstanced() that enables you to define per-instance renderingLayerMask for example. The doc page has also an example how to do it.

    Cheers, Jarkko
     
    TerraUnity and ProGameDevUser like this.