Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  3. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Deferred Decals Built in with new SRP ?

Discussion in 'Graphics Experimental Previews' started by Ziboo, Jan 25, 2018.

  1. Ziboo

    Ziboo

    Joined:
    Aug 30, 2011
    Posts:
    356
    Hi,

    Was wandering if you thinking of having a built in decals solution with the new SRP coming.
    Decals is a must have feature in pretty every other engine out there.

    Thanks
     
    parker2k, dmennenoh and AntonioModer like this.
  2. JakubSmaga

    JakubSmaga

    Joined:
    Aug 5, 2015
    Posts:
    417
    Yes, SRP supports decals. I'm not really sure how to use them right now but there is a "Decal Projector" Component under GameObject->Render Pipeline>High Definition-> DecalProjector and every material has "Enable Decal" toggle.
     
  3. Ziboo

    Ziboo

    Joined:
    Aug 30, 2011
    Posts:
    356
    Awesome !
     
  4. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    842
    Use the projector and reference a material with the decal shader. You'll get the main texture projected onto.. everything.
     
  5. JakubSmaga

    JakubSmaga

    Joined:
    Aug 5, 2015
    Posts:
    417
    Tried doing that few hours, didn't work. Does it work for you?
     
  6. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    You even get a neat little decal stamper icon too :p

     
    AntonioModer likes this.
  7. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    842
    Yes, it works. Now that I downloaded 1.26, it seems to take a bit to update though.
     
  8. Ziboo

    Ziboo

    Joined:
    Aug 30, 2011
    Posts:
    356
    Projector are really bad performance though. It's not deferred decal.
     
  9. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    842
    Do you think? I tried 200 decals without any noticable change in performance.
     
  10. Ziboo

    Ziboo

    Joined:
    Aug 30, 2011
    Posts:
    356
    I'm talking about Unity Projector, the old one. haven't tried the new thing yet. The version I have right now doesn't have a Decal option in maerial, might need to update
     
  11. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    842
    It's not a decal option (well, there is one for transparent materials, but you don't need it), you need to use HDRenderPipeline/Decal shader
     
  12. Thall33

    Thall33

    Joined:
    Sep 18, 2013
    Posts:
    134
    Love to see this in action, anyone got some screen shots to pimp and talk about performance, pros and cons?
     
  13. sqallpl

    sqallpl

    Joined:
    Oct 22, 2013
    Posts:
    384
    Do they work with semitransparency+shadows?
     
  14. Ziboo

    Ziboo

    Joined:
    Aug 30, 2011
    Posts:
    356
    With 2018.1.0b4 , new project with HD Template I got that:
     
  15. Onigiri

    Onigiri

    Joined:
    Aug 10, 2014
    Posts:
    490
    @Ziboo Delete Library folder
     
  16. Ziboo

    Ziboo

    Joined:
    Aug 30, 2011
    Posts:
    356
    Tried but still failed to compile
     
  17. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    842
    Click on the shader in your project window and reimport it. It'll either be available or you'll get an error message in the inspector. If some kernel is missing, search for the key word (lighting, subsurface scattering etc.) and reimport the hlsl include. After that, reimport the decal shader.
     
  18. Ziboo

    Ziboo

    Joined:
    Aug 30, 2011
    Posts:
    356
    This is the error message:

    Code (CSharp):
    1. failed to open source file: 'ShaderLibrary/SampleUVMapping.hlsl'
    2. Compiling Vertex program
    3. Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING UNITY_ENABLE_DETAIL_NORMALMAP SHADER_API_DESKTOP UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_LIGHTMAP_FULL_HDR
    Cannot reimport the hlsl since it is build in and not in the project view...
     
  19. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    842
    It's in Core/CoreRP/ShaderLibrary/Sampling/
     
  20. Ziboo

    Ziboo

    Joined:
    Aug 30, 2011
    Posts:
    356
    Again, use the build in template from 2018.1.0b4. Nothing in the project view
     
  21. JakubSmaga

    JakubSmaga

    Joined:
    Aug 5, 2015
    Posts:
    417
    Same here.
     
  22. Finepointcgi

    Finepointcgi

    Joined:
    Jul 5, 2017
    Posts:
    14
    does anyone know if lightweight is going to have decals? I know is forward rendering so im not sure if it can
     
  23. JakubSmaga

    JakubSmaga

    Joined:
    Aug 5, 2015
    Posts:
    417
    Right now when you check decals scripts/shaders on github there is info only about HDRP, @SebLagarde are they HD only?
     
  24. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    I'm not the HD dude so I can't say much about how things should work / the issues you are seeing. I can say though that for now decals are HD only.
     
    Necronomicron likes this.
  25. SebLagarde

    SebLagarde

    Unity Technologies

    Joined:
    Dec 30, 2015
    Posts:
    935
    Yes, Decals are HD only, here is more details about the implementation. Have in mind that this is WIP, thus why you may experience different problem. We currently use a DBuffer approach, but this may evolve in near future.


    Cons of classic deferred decal

    • Don’t work in forward (Opaque/Transparent)

    • Applied after Gbuffer pass so it doesn’t affect GI

    • Requires blendable uncompressed GBuffer

      • Want to avoid to make a blendable buffer as it puts more restriction on GBuffer:

        • Requires blendable data in RGB channel

        • Requires no compression (like no normal compression to be blendable)

        • Requires to know where element are stored in GBuffer to do mask correctly (HD allows users to configure their GBuffer as they want; we use abstract function to sample and store attribute)
    • Combinatorial explosion of blend mode when we want to support several case (multiply albedo, lerp normal, add smoothness…) which is a nightmare with an unknow Gbuffer (as users can change the layout).

    • Difficult to deal with multiple materialId in Gbuffer (what to do when blending specular color, whereas the material is Subsurface scattering type ?)


    The DBuffer approach

    Restrict decal attribute to: diffuse albedo, metal, normal and smoothness (metalness workflow)

    • RT0: diffuse, opacity in alpha RT1: normal, opacity RT2: metal, smoothness, opacity

    • Decal can blend only a set of attribute if desired
    Restrict blend mode to Lerp


    Step:

    1. Full Z-prepass

      1. In deferred

      2. In forward there is a full z-prepass anyway.
    2. Render deferred decals buffer (diffuse, specular, smoothness, normal) - This requires additional memory to store the attributes.

    3. Gbuffer pass that sample the decals buffer and lerp them (limitation of blending mode to restrict combinatorial explosion but also to match PBR requirement). The GI and emissive are correct.

    4. Deferred Lighting

    5. Forward pass with opaque that correctly handle decal (i.e switching between deferred and forward don't change the result for opaque).

    Pros:

    • Compatible between deferred and forward opaque

    • Decals support GI

    • Particles/Postprocess could affect the DBuffer to allow others effects

    • No restriction on Gbuffer
    Pros/Cons

    • Require additional depth prepass

      • There is a an obvious CPU impact here in case of deferred (forward have a full depth prepass anyway)

      • However on GPU it can be a win in case of deferred depends on context

        • With heavy Gbuffer pass (like with scene where objects use a lot of LayeredLit shader), depth prepass is a win.

        • With a lot of alpha tested object, doing prepass with alpha test objects is a win

        • Doing a full prepass may allow to re-organize the rendering to throw async computation earlier, like light list creation, depth pyramid construction
    Cons:

    • Forward transparent don’t support decal

    • Don’t support normal fading (i.e as we don’t have access to normal from Gbuffer or because of forward rendering, we can’t fade badly oriented project based on normal of the receiver)
     
    neuroKip, Elecman, Ghosthowl and 8 others like this.
  26. Tyrathect

    Tyrathect

    Joined:
    Jul 10, 2012
    Posts:
    38
    How does Unreal do it, and why can't you guys do the same thing? I just want to be able to place bullet holes in a performant way.
     
  27. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,995
    Unreal has a very different pipeline, so answering that question will unlikely lead to anything useful I am afraid.

    If this is all you want to do, what is stopping you from doing this now? How many bullet holes are you trying to place that you cant do this now? Why not do the 3D decal method, using a GPU instanced shader. Then you could place 1000s of them and have them mostly cost a single draw per shader pass etc

    Unity developers have not been forgoing decals up until now, we have gotten around them not being directly supported in the shader for a long time. Also a lot of games do it this way anyway. both methods have pros/cons.
     
  28. Devil_Inside

    Devil_Inside

    Joined:
    Nov 19, 2012
    Posts:
    1,119
    Will this ever come to the core render pipeline or LW SRP?
     
  29. RockSPb

    RockSPb

    Joined:
    Feb 6, 2015
    Posts:
    112
    Why you think it's completely different?
     
  30. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    MadeFromPolygons likes this.
  31. AntonioModer

    AntonioModer

    Joined:
    Jul 29, 2014
    Posts:
    65
    Decals render by ID materials/objects, last created material/object render last:


    But, after reloading editor, decals render mess:
    f34.PNG
     
    Last edited: May 30, 2018
  32. AntonioModer

    AntonioModer

    Joined:
    Jul 29, 2014
    Posts:
    65
  33. Deadcow_

    Deadcow_

    Joined:
    Mar 13, 2014
    Posts:
    135
    I just unable to make Decal Projector work. I've got a simple png texture with transparency, material with HDRP/Decal shader and Blend Factor set to my texture. Floor material with HDRP/Lit shader and "Enable decals" toggled on.
    Material preview in project view is pitch black and Decal Projector do nothing.

    May be I need to set some specific texture import settings? I just can't find any info about new decals
    2018-08-30_16-07-03.png 2018-08-30_16-11-39.png 2018-08-30_16-12-52.png
     
  34. Remy_Unity

    Remy_Unity

    Unity Technologies

    Joined:
    Oct 3, 2017
    Posts:
    704
    In your screenshot you disabled "albedo contribution" in the decal material.
    This means that the decal will only use the texture alpha to affect metal/smoothness/normal, but you don't have maps for those.

    Enable the setting, and it should work properly :).
     
  35. Deadcow_

    Deadcow_

    Joined:
    Mar 13, 2014
    Posts:
    135
    I tried it too, all the same :(
    I also tried to project decal on simple plane with DefaultHDMaterial
     

    Attached Files:

  36. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    842
    It may sound dumb, but does it really intersect with the floor?
     
  37. Deadcow_

    Deadcow_

    Joined:
    Mar 13, 2014
    Posts:
    135
    I double checked it)
    2018-08-31_20-20-17.png 2018-08-31_20-20-23.png
     
  38. MegamaDev

    MegamaDev

    Joined:
    Jul 17, 2017
    Posts:
    77
    Check the HRDP asset. I had to go there and manually enable the decal buffer before I could get it to work.
     
    Deadcow_ likes this.
  39. Deadcow_

    Deadcow_

    Joined:
    Mar 13, 2014
    Posts:
    135
    Thanks! I didn't notice that toggle in settings)
     
  40. MegamaDev

    MegamaDev

    Joined:
    Jul 17, 2017
    Posts:
    77
    No problem.
    If you ask me, documentation on these previews can't come fast enough. It's a real headache to have to crawl the internet, hoping that someone else figured it out for you~
     
    Necronomicron likes this.
  41. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,201
    I'm curious whether we'll see any improvements to decals in the near future? Specifically, the following three features are important to me:

    Emission: I'm using emission on another decal system, and I'd like to use it here too.

    Angle Limits: Currently, decals looks silly if they get drawn on anything other than a perfectly flat surface. Here's a tire track decal I made, which draws stripes on the sides of this cube:

    upload_2018-10-31_16-4-10.png

    Ideally I could adjust the angle (relative to the decal's direction) to draw on. Even if I make the decal extremely thin, you'll still see a weird line on the bottom of the cube.

    Limited to specific objects: I use decals to put burn marks on dynamic objects. As the objects move, the decal goes with them. However, I only want that decal to affect the specific mesh I've placed it on.
     
    Last edited: Oct 31, 2018
    id0 likes this.
  42. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Pretty sure for tyre marks you're using the wrong tool for the job, try a trail renderer with decal material (it works on meshes).


    But regarding box projection, I don't know of any projected decal system that can do triplanar mapping as well...
     
  43. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,201
    I've been using Decalicious for decals in the built-in rendering engine. While it doesn't do triplanar mapping, it does include an angle limit such that if the angle is too great, it just don't draw anything at all on that surface. That's all I was hoping for here.
     
  44. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    dgoyette likes this.
  45. Ziplock9000

    Ziplock9000

    Joined:
    Jan 26, 2016
    Posts:
    360
    So what is the best and performat approach for placing 1000's of 2d decals (like blood, 2d stones and 2d foliage) on a unity terrain? Presumably the terrain would be using a 3rd party shader like CTS or Microsplat, so the shader itself would not be rendering the decals. So the decals would have to be extra geometry.. ?
     
  46. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    It matters what pipeline you're using. You can't use those shaders in HDRP. But you an use HDRP decals on HDRP terrain fine as far as I know. I am not sure why you mention extra geometry unless you want to make mesh decals like star citizen.
     
    Ziplock9000 likes this.
  47. bulldog57rus

    bulldog57rus

    Joined:
    Nov 4, 2018
    Posts:
    2
    Is there any way now, to use SRP decals with mobile? I couldn't find any nice asset to draw pictures on by book (pages are not strait)
     
    Last edited: Feb 23, 2019
    NeatWolf likes this.