Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Bug [HDRP] Ambient probe is not applied to meshes, rendered using Graphics.DrawMesh

Discussion in 'High Definition Render Pipeline' started by iamarugin, Dec 3, 2020.

  1. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    884
    Unity 2020.1
    HDRP 8.2.0

    Or this is an expected behaviour?
     
  2. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    884
  3. antoinel_unity

    antoinel_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    267
  4. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    884
    Thanks for info!
     
  5. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    884
    One more question. Meshes, that I want to draw don't exists in the scene and don't belong to any gameObject, so I can't use ScriptableRenderContext.DrawRenderers. Could I do that by using command buffer and ScriptableRenderContext.ExecuteCommandBuffer in the custom pass? What injection is the best for that?
     
  6. antoinel_unity

    antoinel_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    267
    It depends on what you want to do. For unlit objects, the approach you mentioned may be fine but for Lit objects that require to be rendered multiple times by HDRP (depth pre-pass, buffer, motion vectors, etc.) it won't work. So I recommend using Graphics.DrawMesh() and similar functions, internally these calls will register what you're trying to render as part of the things to render in your scene and thus will be included in the DrawRenderers() calls HDRP does.

    So something like this works quite well:
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class DrawMesh : MonoBehaviour
    4. {
    5.     public Mesh mesh;
    6.     public Material material;
    7.  
    8.     void Update()
    9.     {
    10.         Graphics.DrawMesh(mesh, Vector3.zero, Quaternion.identity, material, 1);
    11.     }
    12. }
    13.  
    Note that some things still don't work with this approach as Graphics.DrawMesh() doesn't have enough parameters to handle everything (like light layers for example) and motion vectors might be broken too, especially with DrawProcedural.
     
  7. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    884
    And as far as I understand, ambient probe will be broken too?
    Are there any plans to make a similar API, like Graphics.DrawMesh or Graphics.DrawMeshInstanced, but fully supported by HDRP? It is pretty common task to render something custom, that doesn't exists in the scene.
     
    Arathorn_J likes this.
  8. Arathorn_J

    Arathorn_J

    Joined:
    Jan 13, 2018
    Posts:
    51
    Looking at the latest version of HDRP 10.2 vs URP 10.2, it doesn't look like HDRP fully supports Graphics.DrawMeshInstanced. I logged a bug ( 1299828 ) for the issue, because it looks like the render isn't able to receive shadows only cast them and the surfaces don't look properly lit either.
     
  9. antoinel_unity

    antoinel_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    267
    Sorry, I misunderstood the problem, I confused myself between the DrawMesh from CommandBuffer and Graphics. Graphics.DrawMesh should support ambient probe indeed as well as light/shadows in realtime or baked setup because it's directly passed to DrawRenderers()

    I did a quick test with HDRP 10 and it seems to work for me (tested sky ambient, light probes, baked and realtime light/shadows, and reflection probes). Could you elaborate on the setup you're using so we can find a repro?

    Btw I confirm that DrawMeshInstanced doesn't work with lighting and shadows.
     
  10. iamarugin

    iamarugin

    Joined:
    Dec 17, 2014
    Posts:
    884
    Hmm, looks like on empty project everything works too in 2020.1
    But here is the screenshot from my game
    upload_2020-12-17_15-0-38.png

    All ground rendered using Graphics.DrawMesh and here you can see that ambient probe is applied to starting table, but not to the ground.
    Will try to make reproducable project.
     
  11. Arathorn_J

    Arathorn_J

    Joined:
    Jan 13, 2018
    Posts:
    51
    Just to follow up, you are confirming that is a bug with DrawMeshInstanced in HDRP? I am just concerned that maybe the call is being deprecated or not intended to work fully in HDRP? If it is being worked on, that would be wonderful to know so I can decided whether to keep using HDRP or to find a new approach for my project that relies on DrawMeshInstanced.
     
  12. antoinel_unity

    antoinel_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    267
    Yes, it's a bug that the DrawMeshInstanced doesn't work in your version.

    I investigated a bit the case and it's the light layers (I disabled them in the HDRP asset and it worked). It has probably something to do with the default value of the light layers because you can't provide a value for them with Graphics.Draw* calls.
     
  13. Arathorn_J

    Arathorn_J

    Joined:
    Jan 13, 2018
    Posts:
    51
    Thanks I discovered that as well. Disabling light layers fixed it temporarily though I don't know if I'll have issues where anything would be dependent on that functionality but I'm not currently doing anything specific with light layers. Thanks again for following up and looking into it.