Search Unity

Question HDRP Decal Mesh Draw Order

Discussion in 'High Definition Render Pipeline' started by EnlightenedOne, Dec 17, 2020.

  1. EnlightenedOne

    EnlightenedOne

    Joined:
    Jun 17, 2015
    Posts:
    14
    Meshes using the Decal material in HDRP do not have any obvious functionality that allows for them to be sorted. In its simplest form on HDRP/Lit (grass) with two mesh decals HDRP/Decal (sand and an i) using Unity's plane mesh:
    HDRPDecalMeshPain.gif
    The "Mesh Decal Depth Bias", has no impact because the meshes are drawn by camera distance. Does anything exist in HDRP's workflow that would allow me to control the draw order of these meshes without using decal projectors?

    I can batch both meshes into a single mesh and use a texture array and two quads with a tiny height offset to force the draw order in theory but that would be my last resort solution.
     
    Last edited: Dec 19, 2020
  2. Ziflin

    Ziflin

    Joined:
    Mar 12, 2013
    Posts:
    132
    I have the same issue. There really needs to be a "Decal" Surface Type on Materials that enables the Sorting Priority found on Transparent materials. This is very much needed (as is an opacity just *just* ambient occlusion in the decal shader) for them to be useful for us.

    I feel like this is another case of if Unity was making an actual game, they'd have run into these issues already and fixed them...
     
    Ruchir likes this.
  3. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,555
    I'm not familiar with HDRP, but in URP you can create Decal Shader Graphs which have the Priority slider, ..maybe it works for HDRP as well ?

    sorting.priority.decals.1.jpg

    sorting.priority.decals.2.jpg
     
  4. Ziflin

    Ziflin

    Joined:
    Mar 12, 2013
    Posts:
    132
    Thanks for the suggestion @polemical, but HDRP doesn't have that setting. Here's what it has:
    upload_2021-8-23_15-57-8.png

    • Draw Order - This is only for projectors for some reason!?!?
    I tried it just to see, but it has no effect on two plane quads with different decal materials using different Draw Order values. Mesh Decal Bias/ Depth/ View also do nothing useful for this case.

    So Unity, can we please get priority sorting in HDRP similar to URP for mesh-based decals? I see no reason this can't use the same "Draw Order" value (or rename it to Priority to match URP).

    They'd should also be secondarily sorted (or just guaranteed) by their sub-mesh index. We have multiple submeshes using the same decal material (this is on a large terrain) so that they are culled spatially. We need to ensure that the draw sorting sorts by material Draw Order (Prioirty) first and then by sub mesh index otherwise the overlapping decals will pop/switch order as the camera moves.
     
    Last edited: Aug 23, 2021
  5. Ziflin

    Ziflin

    Joined:
    Mar 12, 2013
    Posts:
    132
    I'd also like to point out that there is also no stable sort/draw order between GameObjects using the same material. So based on the camera location, decals will pop and randomly draw on top of one another if they overlap.

    Can we please get a way to sort decal meshes and sub-meshes with a stable sort comparison so this doesn't happen? We use a lot of mesh decals and without a fix for this, we would not be able to ship. So ideally something along the lines of:
    Material Priority > Shader > Material >Mesh > Sub Mesh Index > Mesh Renderer
     
    Ruchir likes this.
  6. SebLagarde

    SebLagarde

    Unity Technologies

    Joined:
    Dec 30, 2015
    Posts:
    934
  7. Ziflin

    Ziflin

    Joined:
    Mar 12, 2013
    Posts:
    132
    Thanks @SebLagarde. Does this also fix sorting issues for decals using the same material in different GameObjects or sub-meshes of the same GameObject? If not, we still need an option for this otherwise all our terrain decals pop/change order as the camera moves.
     
  8. SebLagarde

    SebLagarde

    Unity Technologies

    Joined:
    Dec 30, 2015
    Posts:
    934
    It provide sorting by Mesh renderer and by Material. So should fit your need
     
  9. Ziflin

    Ziflin

    Joined:
    Mar 12, 2013
    Posts:
    132
    @SebLagarde Ok, as long as it's stable down to the sub-mesh then it should work for us. Thanks for fixing it!
     
  10. BrightRocket987

    BrightRocket987

    Joined:
    Jul 26, 2021
    Posts:
    8
    you can also, instance your own materials:

    Code (CSharp):
    1. using UnityEngine.Rendering.HighDefinition;
    2.  
    3. Material decalMaterial = GameObject.GetComponent<DecalProjector>().material;//get material
    4. Material instanceMaterial = new Material(decalMaterial);//instance new (lone) material
    5. GameObject.GetComponent<DecalProjector>().material = instanceMaterial;//set new material
    then directly set the draw order by using
    GameObject.GetComponent<DecalProjector>().material.SetInt("_DrawOrder", int)