Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Standard Deferred Decals

Discussion in 'Assets and Asset Store' started by cubrman, Mar 5, 2018.

  1. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    403
    I've modified the Standard shader in such a way that now you can alpha-blend models into the GBuffer. This is not the magic bullet that allows to have lit and shadowed semi-transparent objects, because lighting still happens after the GBuffer stage and still only lights one layer of objects, but it allows you to have mesh-based deferred decals that have absolutely consistent lighting with the Unity's Standard shader. Here are the advantages of this system over the existing deferred decals solutions on the Asset Store:

    - allows to set decals as "static" and have them receive baked and realtime Enlighten GI as well as contribute to it;
    - receives correct Image Based Lighting when the scene is lit with the custom skybox;
    - does not require the recepient models to be rendered more than one time;
    - costs $5;

    Here is the shader in action:
    Standard deferred decals.gif

    Here are some comparison shots before and after adding decals (enlarge the images - they are huge):
    1.jpg

    6.jpg

    11.jpg

    66.jpg

    Asset Store link:

    https://assetstore.unity.com/packages/vfx/shaders/standard-deferred-decals-115178
     
    Last edited: Apr 21, 2018
    chelnok, osss, Korindian and 2 others like this.
  2. xDeveloper

    xDeveloper

    Joined:
    Sep 27, 2015
    Posts:
    10
    Great pictures and maybe will a good asset.
     
  3. MylesLambert

    MylesLambert

    Joined:
    Dec 31, 2012
    Posts:
    61
    For $5 I'd get it just as a base to build on :)
     
  4. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    403
    Hey thanks for the feedback! I plan to include the road (without the buildings) and the sand with rocks into the package, The rough release date is early April (due to legal reasons in the country where I live - Ukraine).
     
  5. form_d_K

    form_d_K

    Joined:
    Jul 12, 2017
    Posts:
    14
    Is there any way this could be used to add PBR decals? I think it would be pretty neat to decal with Megascan assets, full tessellation & all. What would be even cooler is if you could blend decals & the underlying textures together, like in Quixel Mixer.
     
  6. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    403
    This is exactly what this plugin is for.



    Tessellation and decals is an incredibly tricky issue. It is not supported in the current shader, moreover, you really need to know what you are doing if you want to use tessellation with decals.


    I do not know how Quixel mixer works, but Standard Deferred Decals allows you to alphablend decals into their underlying surface. There is no other type of blending (add/subtract/multiply) supported in this shader.
     
    form_d_K likes this.
  7. f1chris

    f1chris

    Joined:
    Sep 21, 2013
    Posts:
    335
    Very interesting asset. How is this working on mobile devices ? I don’t mean low-end ones but iOS Metal ones.

    Thx
     
  8. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    403
    I cannot comment on that unfortunately. I developed it for my PC project and I am using Deferred Rendering (I hope you are aware that the decals only work for the deferred rendering path). I cannot test it either as I do not posess any devise capable of running a Unity game (funny enough :)).

    Overall I can only say that SDD shader has a handful more instructions than the Standard shader and also renders the model twice (the first pass is an incredibly simple shader) so you can draw the conclusions yourself.
     
  9. bearlike

    bearlike

    Joined:
    Mar 11, 2016
    Posts:
    6
    Hi, your assets looks very promising. I bought it, but can't find the demo scene you mentioned in your documents.
     
  10. f1chris

    f1chris

    Joined:
    Sep 21, 2013
    Posts:
    335
    but you can compile for iOS or Android and run it from the simulator, isn't ?
     
  11. zero_null

    zero_null

    Joined:
    Mar 11, 2014
    Posts:
    159
    looks very interesting. Just like f1chris I am also curios how well it works on a mobile device.
     
  12. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    403
    Very sorry for the late reply,


    I've just realized how confusing it is to find the scene - it is located in the Demo/Road folder and is called "Road".


    I can do it, if you can explain which simulator to use and how to measure performance.

    Like I said I just don't have a device to test it on (I have no smartphone, just a regular 8 year old one - I hate touch phones). If you can tell me how to test it on PC I can give you all the data you need.
     
  13. DeFScythe

    DeFScythe

    Joined:
    May 15, 2015
    Posts:
    3
    does decals works with terrain? can they be placed at runtime?
     
  14. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    403
    A good question. I will download Adam demo right now, try it and let you know.


    Decals are but a shader. Moreover, it is a variation of the Standard shader or "Material". You create a material, add textures to it and then you can do whatever you want with it. So yes you can place them at runtime - for instance by spawning a prefab that has a MeshRenderer and the Standard Deferred Decals material.
     
  15. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    403
    Here is the rock from the Standard Deferred Decals' demo scene resting on top of Adam's terrain:



    As you can see it's pretty smooth. Be careful when using my decal shader with terrain though - to get the best visuals and prevent lighting glitches the decal mesh should perfectly follow the terrain mesh (sit just a few millimeters atop of it).
     
  16. eejitb

    eejitb

    Joined:
    Apr 7, 2014
    Posts:
    6
    Hi
    i've just picked this up, looks really cool. One strange thing though - it seems to require a camera in the scene for Alpha cutoff = 0 to work? I'm only instantiating a camera at runtime
    obviously it can be worked around (have a camera enabled for editing purposes) but wondering if this was by design/a prerequisite of the shader somehow
     
  17. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    403
    This is strange.

    First: why would you ever need 'Alpha cutoff' to be zero? I've set it to an incredibly low number and I remember that there was a reason for it (like a graphical bug) but right now I cannot recall what was that reason exactly. I would need to test it to remind myself. In any case what purpose would the zero cutoff serve? When it is just above zero you would allow every pixel through that carries any useful information and remove (clip) those that do absolutely nothing. Why is that bad?

    Second: what do you mean that 'Alpha cutoff = 0' does not work without an instantiated camera? Do the decals not render at all? For instance in my game I have a standard Unity networking system where the player GameObject (which has the camera) is disabled at the start of the game. Maybe it's not the same as your situation but in mine everything works fine.

    Theoretically my shader should work 100% the same way as the standard shader works as I literary change only a fraction of the code of the standard shader.

    So please do provide more details.
     
  18. beard-or-die

    beard-or-die

    Joined:
    Jul 12, 2017
    Posts:
    5
    Just checking before I purchase: has it been tested with 2018.2 ? Would it work with HDRP and LWRP? Could it be useduin combination with the new shader graph (putting decal onto an object that has a shadergraph material/shader on it? I'd love to use this along with the new prefab workflow. Someone said something about the new unity supporting decals but I haven't seen anything about how to do so.
     
  19. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    403
    Standard Deferred Decals were tested in 2018.2 and work fine with the builtin (Standard) pipeline, however, they cannot work with either HDRP or LWRP neither would it work with the shader graph as the latter is HDRP/LWRP only. HDRP has their own decal system, however, I would not dive into new SRP-s with a serious project if I were you. Unity themselves said that the pipeline is in preview mode and not ready for production until 2018.3, moreover, some think (me included) one should wait even longer (maybe like half a year from now) for the thing to be robust enough.

    P.S. If you want to use HDRP anyway, you can buy the package for the HQ asphalt decals included in the sample scene (road markings, tar marks, manholes, etc.) their textures are fully compatible with HDRP, you would just need to specify the correct HDRP shader.
     
  20. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,141
    I'm already using a DD system, though the deciding factor for me to use this is if it supports texture atlases? This would reduce the number of materials and textures used in a scene, which is a welcome benefit.

    Is that something you're interested in adding in the future?
     
  21. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    403
    Sorry for the late reply, was traveling.

    Really you can treat my shader exactly like a Standard shader. If Standard shader supports it mine supports it automatically. There is next to no difference between SDD and the Standard shader.

    What I can suggest in terms of atlases and reducing number of materials and textures is this asset:

    https://assetstore.unity.com/packages/tools/utilities/pro-draw-call-optimizer-54360

    It would bake the selected materials, using Standard shader, into 1 big atlas while keeping all the channels (diffuse, metallic/smoothness, ao, specular, etc.) while creating a mesh that has the UVs necessary to work with the atlas. And then you can basically use the resulting mesh and the atlases with the Standard Deferred Decals shader to (potentially) have all your decals in the scene be rendered with only 2 draw calls (keep in mind that SDD shader renders every decal with 2 draw calls and that cannot be reduced).

    Disclaimer: I did not use the Pro Draw Call Optimizer asset and did not try the approach described here.
     
    Last edited: Aug 21, 2018
    StaggartCreations likes this.
  22. zt3ff3n

    zt3ff3n

    Joined:
    Feb 19, 2016
    Posts:
    36
    Just bought this. The shader seems to be working in the sense that I'm not getting those pink materials or any errors. But I can only find the shader under the "Failed to Compile" section. Should that worry me? v.2018.1.f1
     
  23. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    403
    It turns out there is currently a bug in U2018 that prevents shaders from compiling. Good news is, all you need to do to overcome it is to reimport the shaders like this:



    If you want to read more about the bug, check out this reddit thread:
    https://www.reddit.com/r/Unity3D/comments/8kjzdf/standard_shader_invalid_subscript_uv2_error/

    Please try this (reimport both shaders SDD (Specular setup) as well as Standard Deferred Decals) and tell me if the problem persists.
     
    Last edited: Aug 24, 2018
  24. zIyaGtVm

    zIyaGtVm

    Joined:
    Dec 27, 2017
    Posts:
    131
    Hi, can transparent decals receive shadows?
     
  25. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    403
    Sure. Keep in mind that there is a specific checkbox in the shader's inspector dedicated to just that: "Write into ZBuffer". Each decal is depth-tested when it is being drawn, because buildings and obstacles should cover parts of the decal properly and not have the decal render on top of them. This means that each decal you place should be slightly above the surface that it is "decaling". For these cases you uncheck the "Write into ZBuffer" checkbox and have the decal receive the same shadows the underlying surface would otherwise receive. However, decals can actually be complex meshes, as long as their ends "touch" the underlying surface - like the rock spoilers in the gif file I show in this thread. Those spoilers actually have "Write into ZBuffer" set to "true" (checked) so that they receive their own shadows and cover the objects properly via GPU depth testing.

    This was a very technical and convoluted answer, sorry, for some reason I could not word it any other way :). Basically the simple answer is "yes every decal can receive shadows", just keep in mind that they should be placed just above the surface you are "decaling".
     
  26. zIyaGtVm

    zIyaGtVm

    Joined:
    Dec 27, 2017
    Posts:
    131
    That's very kind of you to show me a so much detailed answer.:)
     
  27. Efril

    Efril

    Joined:
    Aug 31, 2013
    Posts:
    81
    Can this decals system selectively project decal on objects based on their layer? For example decal object located to cover two cubes which belongs to different layers and decal drawn only on one of them.
     
  28. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    403
    Sorry for the late reply,

    no you cannot apply decals only to certain levels. Standard Deferred Decals is a barebones system designed to be as simple as possible. In order to apply decals to certain layers one would need to render base geometry twice and that was something I was trying to avoid with my decal system.

    Moreover, Standard Deferred Decals are mesh-based non-projected decals, which means that in order to "project" a decal you would need to build a mesh that closely follows the mesh of the base object, that you want decals on.
     
  29. McDev02

    McDev02

    Joined:
    Nov 22, 2010
    Posts:
    661
    I just gave it a try and it works great!
    Can you explain why it has to render in two passes? I see that it does dulling but why is that?
     
    Last edited: Aug 17, 2019
  30. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    403
    Glad you enjoyed it! You need 2 passes because you cannot alphablend the alpha channels and Unity's GBuffer holds AO and smoothness in alpha channels.
     
    McDev02 likes this.
  31. whidzee

    whidzee

    Joined:
    Nov 20, 2012
    Posts:
    161
    @cubrman Does this system project decals onto curved surfaces? also does it work in the shadows? I've tried unity's built in defered decal system and as my scene is only lit by the sun when my object is in shadow the decals vanish
     
  32. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    403
    No my decals only work with a static mesh you provide. So if the mesh you are using is perfectly following the underlying geometry - the decals will look consistent, otherwise they will look odd.


    It seams that you are using HDRP, keep in mind that my decals only work with builting rendering pipeline.


    Yes my decals accurately receive and even cast shadows - they are basically a version of the standard shader with some benefits (alphablending) and some caviats (must follow underlying geometry perfectly in places where thexture alpha is less than 1).
     
  33. whidzee

    whidzee

    Joined:
    Nov 20, 2012
    Posts:
    161
    I'm not using HDRP.
    does your system project the decals? so i can use them on a curved surface?
     
  34. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    403
    No, my system does not project decals, in order for you to use my system on curved surfaces, you would have to create geometry that exactly follows your curved surfaces and then apply decals to it.
     
  35. IanItor

    IanItor

    Joined:
    Dec 21, 2017
    Posts:
    12
    I'm curious how hard it would be to port your shader to amplify editor version. I'd like to get full control of it, but i'm not sure i could tackle if there are many lines of code with complex math involved.
     
  36. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    403
    Well, you would have to edit complex shaders man. The general idea is simple enough, but you would need to understand shaders and, especially, Amplify shaders. Moreover, making the final shader work with Amplify shader editor is an additional layer of work.
     
  37. UnityRocksAlt

    UnityRocksAlt

    Joined:
    Dec 28, 2015
    Posts:
    156
    I bought your asset and I like it. How do you write to normals only?
    I figured it out. Amazing
     
    Last edited: Jul 1, 2021
  38. cubrman

    cubrman

    Joined:
    Jun 18, 2016
    Posts:
    403
    @UnityRocksAlt hey! I'm glad to hear you enjoy the asset. Please feel free to ask me any time you need anything. I might reply faster at cubrman@gmail.com.