Search Unity

Feature Request URP Decals on transparent surfaces

Discussion in 'Universal Render Pipeline' started by AdamLacko, Apr 27, 2022.

  1. AdamLacko

    AdamLacko

    Joined:
    Oct 10, 2017
    Posts:
    41
    I'm trying to figure out a way to force Unity's URP Decal Projector to also influence transparent objects.

    I do know that URP Decal system does not support transparency, most likely due to transparent geometry not writing into depth buffer.
    However, I noticed a few new options in URP that I hoped could help "hack" my way around this limitation. For instance, URP Shade Graph provides a way to force writing into depth buffer, even for transparent shaders (confirmed with Frame Debugger). In the latest URP (14.0), there's also an option in the renderer asset to copy scene depth after transparents (instead of opaques).

    I have two questions:

    1) Does Unity plan on supporting decals on transparent surfaces in the future?

    2) Isn't there at least a hacky way to overcome this limitation of the URP Decals? Custom render features, material render order, shaders, anything.
     
    meijiehuuu, Lampys and pixelR like this.
  2. AdamLacko

    AdamLacko

    Joined:
    Oct 10, 2017
    Posts:
    41
    Upon further trial-and-error experimenting, I suppose I found a solution. When using Screen Space technique for Decals, I managed to get the transparent objects to be influenced by the decals simply by changing the render event of DecalScreenSpaceRenderPass, in the URP package source code. That did the trick.

    I don't know if there are any possible side effects of this, but for my use-case (projecting Fog Of War texture over environment), I found none. Transparent objects are influenced by the projected fog, and there is no sorting issue (which I have experienced before when trying to change material render order and use custom projector shaders).



    However, since I created this thread, I'd like to point out another possible feature request I found after I managed to get this to work.

    Screen space decal shader pass produces a different blending than DBuffer (visually, despite having the same blending setup in code). I've been noticing this since the Decal system release and that's why I tended to avoid Screen space decals. Now that the Screen Space decals allowed me to use transparency as well, I went ahead and manually changed the blending setup in the generated code from the Shader Graph's Decal graph to get the same visual results as in DBuffer decals.

    So I think it could be useful to have the blending options exposed in the Decal master node settings, just like in other graphs.
     
    Last edited: Apr 28, 2022
    meijiehuuu, BFE_lstarc, A51DE and 3 others like this.
  3. amit-chai

    amit-chai

    Joined:
    Jul 2, 2012
    Posts:
    80
    Hi! please can you explain how you did it? "changing the render event of DecalScreenSpaceRenderPass, in the URP package source code." what does it even mean? how you can access the code? does this mean you set "Lit" to act as a decal material?
     
  4. amit-chai

    amit-chai

    Joined:
    Jul 2, 2012
    Posts:
    80
    OK so I've found the DecalScreenSpaceRenderPass and changed the script, but not sure how to use your example. looks like you are settings a Lit material, and not a Decal material. please can you explain?
     
  5. A51DE

    A51DE

    Joined:
    Nov 10, 2022
    Posts:
    2
    Usefull hack. Much appreciated.
     
  6. DrSilverman

    DrSilverman

    Joined:
    Jan 19, 2018
    Posts:
    2
    Hey! I see you managed to make it work! Could you share more infos?
    I changed the renderPassEvent to RenderPassEvent.AfterRendering;
    But it does not work
    Is it because Transparent material do not write to the depth buffer anyway?
     
  7. DrSilverman

    DrSilverman

    Joined:
    Jan 19, 2018
    Posts:
    2
    OK I get what you happens here
    The Decal actually renders on top of the Opaque object (your terrain). But since you changed the RenderPassEvent setting to AfterRenderingTransparent, the decal is drawn after the transparent. Since your transparent objects are very close to your opaque terrain, and from you camera angle, it looks like the Decal is drawn on the Transparent object, but that is not the case.

    To summarize, the Decal is drawn on the Opaque object, but above the Transparent object
     
    A51DE likes this.
  8. A51DE

    A51DE

    Joined:
    Nov 10, 2022
    Posts:
    2
    Yep that's totally correct. Worked for me cus decal was hidden by transparent grass. In my case rendering on a terrain is acceptable.
     
  9. meijiehuuu

    meijiehuuu

    Joined:
    Feb 6, 2019
    Posts:
    1
    Can you explain how to edit the script in the packages? I am new to Unity scripting and would like some guidance on this hack.

     
    Last edited: Jan 26, 2024
    Gosciu likes this.