Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Bug BatchRenderGroup API : Transparent material rendered as if it was opaque

Discussion in 'Graphics for ECS' started by J_Revel, Sep 20, 2023.

  1. J_Revel

    J_Revel

    Joined:
    Nov 22, 2021
    Posts:
    7
    Hello !
    I'm trying to use the BatchRenderGroup API to render some custom mesh that is generated every frame (it's an animated spine asset rendered as a new mesh every frame)

    I have a problem that looks like an engine bug : I use a transparent shader, because I want it to be rendered last, but the engine keeps putting it here according to the frame debugger :
    upload_2023-9-20_11-42-16.png

    But that's not the weirdest part : as soon as I change anything in the configuration of the material, it starts rendering properly, and it's now put inside the DrawTransparentObject pass :
    upload_2023-9-20_11-36-28.png

    The data sent to the GPU is exactly the same in both cases (at least what is shown in the frame debugger), and the bug is also present on builds : characters are rendered properly only if I have modified their materials at least once after launching the editor...
    That's really puzzling, any idea why it behaves like that, and/or any workaround ? I don't actually need the mesh to be considered as transparent, I just need to make sure it will be rendered after opaques.
     
    Last edited: Sep 20, 2023
  2. JussiKnuuttila

    JussiKnuuttila

    Unity Technologies

    Joined:
    Jun 7, 2019
    Posts:
    352
    Are you using the BatchDrawCommandFlags.HasSortingPosition flag for these objects? If not, try setting that flag, I think anything with that flag should render in the transparent pass.
     
  3. J_Revel

    J_Revel

    Joined:
    Nov 22, 2021
    Posts:
    7
    Thank you for the quick answer !
    But I just tried it, and it does not solve the problem unfortunately...
    Is there any way to see what the SRP batcher does under the hood ?
     
  4. JussiKnuuttila

    JussiKnuuttila

    Unity Technologies

    Joined:
    Jun 7, 2019
    Posts:
    352
    SRP Batcher assigns draws to passes using Material.renderQueue and Shader.renderQueue. Perhaps there is something weird going on with one of those two.

    I would start investigation by logging those values for the Material in question and see if there's something that looks fishy.
     
  5. J_Revel

    J_Revel

    Joined:
    Nov 22, 2021
    Posts:
    7
    Thank you ! It actually seems to come from the material, which gets a Custom Render Queue of 2000 ish at load if I keep the QueueControl to auto, but gets refreshed properly after I change anything in the material... It doesn't have this problem with UserOverride though, so there's still a bug, but at least I have a workaround !

    Thanks a lot :)
     
    JussiKnuuttila likes this.