Search Unity

Deferred Decals

Discussion in 'Works In Progress - Archive' started by Zicandar, Jul 1, 2015.

  1. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    Hello!
    I've recently started work on a deferred decal system, it's base is similar to what Aras kindly gave an example of, however due to how unity's deferred works, his example system is to limited.
    What I want to achive is a much more complete deferred decal system, where I also write to AO, Roughness, Spec color (metalness), and emissive.
    It not getting any ambient light is also not acceptable, so that will also be "fixed".

    Note all of this is very early in development, but even so, ideas and feedback on the ideas I have written and have on the trello board are very welcome! (Comments are open on the trello board.) DecalsGameView.PNG DecalsFullView.PNG
    The ability to have "Layers" for decals, so that materials can have one or multiple layers, and decals can effect only or exclude one or multiple layers.

    The downsides:
    No lightmaps on things affected by decals.
    Reflection probes are unlikely to work unless they update a global cubemap.
    Lightprobes will most likely not work, considering getting past this and using per pixel interpolated lightprobes. (This can also make them less "good" in some cases, and it'd be low on the priority list.)

    Link to the Trello board I created for this:
    https://trello.com/b/lE1py1zX
     
    one_one, DennG, ElectroMantis and 3 others like this.
  2. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,790
    Deferred decals with rough/spec channel would be AWWEESSOOMMEE. No reflection or light probes might be an issue though.
     
  3. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    I can use the global cubemap, (can be set runtime), but reflection probes placed around in the enviorment that unity blends between per object would be alot tricker, I have some ideas for it, but even so limits would exist. Sometimes it'd be enough to simply blend between 2-3 light probes, and all visible objects share those, that I can easily do.
    Per object solutions would require storing what lightprobes affect each object, and have all relevant lightprobes acessible in the lighting pass.
     
  4. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Good work so far. Having them only affect some layers is fairly vital, otherwise in a lot of situations where you need a bigger projection area, you would end up overlapping objects you didn't want just to have a valid projection, ie dynamic characters.
     
  5. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    Best of all, it won't "steal" layers from your physics as I won't be using unity's layers, downside is that the layer count will be even more limited. (Stencil buffer)
     
  6. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Unity is doing per pixel probe lookup for SSRR in 5.2 or .3 - check roadmap, which may or may not contain functionality that could be expanded for your use cases - best ask them.
     
  7. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    The curvature of the lines is not known in advance because the tarmac shape itself is procedurally generated. I can't integrate the lines in the tarmac texture because there would be way too many combinations and the tarmac itself is 4k, so that would likely overflow the GPU memory.

    I could create a bunch of curves and then match the closest one. Would it be possible to pack those curves nicely in a texture like this, or will the UVs be a problem?

    curves.jpg
    One advantage of that is that mesh tessellation is not visible.

    It is to be used for lines on airport taxiways:
    taxiway.jpg
     
  8. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    Could you potentially give the shader enough information to mathematically construct a very similar curve?
    (I can probably help with the math if needed)

    Yes and no, it'd be pretty hard to know what line is what when packed so tightly (y-overlap), but if you don't need colors in the texture we could use the 4 channels for alternating lines, so the y-overlap would never happen within a y-range.

    One other possible solution/idea I'm thinking of is to remap the UV from xz Object space to something else.
    This could probably be done with textures, and they could then be blended!
    The blending should get you near perfect variations without having to create to many textures for it. (2 channels needed per remap, so you could pack 2 remaps per render texture if that's what your using).
     
  9. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
    Yes, the taxiways can be slightly modified to follow the curve of of available lines, but not too much. Alternatively, I could construct the taxiways out of pre-set curvatures. I suppose that should work as well.

    The lines do need colors, but the color can be added globally in the shader, because most lines have the same color i.e. yellow and white. So the base texture can be monochrome, that should be no problem.

    By the way, there is no specific need to pack the textures so tightly, if that poses problems, it is ok to pack them in a non-overlapping way.
     
  10. DennG

    DennG

    Joined:
    Dec 5, 2013
    Posts:
    158
    Nice!
    I was testing the unity example at the weekend and I've discovered one big issue with the "normal only" decal shader.
    It overwrites the normals under the decal instead of multiplying/combining it somehow.
    Is combining even possible? In this state it's unusable for me.

    I hope you've got something like that in the pipeline.

    Edit: I just saw it on the trello board :)
     
    Last edited: Jul 20, 2015
  11. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    Its on the todo list, however my time spent on this project has been reduced drastically, but that one feature I'll see if I can't get done today, after that if people want it, pm me and I can send you a copy. I don't want to put it on the asset store, as its to far from finished, but if people want it in it's current state and/or want to help develop it please ask! If others help out it will be uploaded for free on asset store, with a license that allows free development and sharing, (and github or such). If it ends with me doing everything somewhere in the future it will have a cost to it.

    I still have the major issue of ambient light and lightmaps, thankfully unity have a plan for that, but its not out yet...
     
    DennG likes this.
  12. chelnok

    chelnok

    Joined:
    Jul 2, 2012
    Posts:
    680
    I am more than interested no matter what the current status is. Though i wouldn't be any good what it comes to ambient light and lightmaps, as either one of those are not used in the project i am hoping to use some dd's. PM sent anyway :)
     
  13. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Yeah same, would be awesome to just have basic decals. I don't use baked lightmaps (but I do use enlighten).
     
    Mister-D likes this.
  14. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    Well, sadly I have put this project on hold as mentioned, at least until I can get either enough interest to make it open source, or I get time to spend on it again.
    Once (if) unity decides to make the GI be applied in the deferred pass instead of the initial pass, well, that would allow me to make them "complete".
    But there are a LOT of things that would need to be done to have all the functionality that is needed also. Alot of that revolves around normals and normal blending.
     
  15. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Ah I see - well I think they'd be open to that if you contact them. The new Unity (NU for short!) listens to users and implements great things.

    For example 5.2 extends the plugin api, allowing middleware to inject rendering into a precise stage. It's really great so gives me hope that robust deferred decals are possible.
     
  16. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    Well, what I need from them is something they have in their todo plan. However there is a lot more that could and probably needs to be done for it to be releasable as a genericly usable defererred decal solution. Such as the matrix for the normals not necessarily being the same as the one for the game object!
     
  17. cAyouMontreal

    cAyouMontreal

    Joined:
    Jun 30, 2011
    Posts:
    315
  18. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    My version might work better, however it really depends on how what the bug with the SSAO pro is. My guess would be stencil buffers, in what case no. If it's depth related it'd be really odd. It could also be something else completely. My suggestion to your graphics programmer is to download and learn RenderDoc. Note that it can be run with the unity Editor! So no need to make builds to get a LOT of information!
    The main problem with my decals would be that they are to a degree built upon the UT version, more complete, and they get past an issue or two, but still the same base. As I said in the beginning, it's all dependent on what the bug is, as they bug is VERY weird!
     
  19. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,901
    @Zicandar how do you set up blending to write the values into the gbuffer?
    or do you use 2 passes and color masks?
     
  20. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    I currently use 2 passes as I chose not to modify unity's deferred g-buffer layout. However I have done this before, but for a specific game. And in that case I changed around the layout a bit of the g-buffer, leaving the AO in the alpha channel, making it so I didn't need dual passes.
     
  21. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    Unity 5.2 is here!
    Good news for anyone who wants proper deferred decals, it's now quite easy to make them! As unity at long last defers the application of reflection probes. (And I'm going out on a limb here and assuming also the global cubemap if there are no local reflection probes).
    While I personally won't have time currently to complete my deferred decal implementation, this has now opened up deferred decals "properly" as long as we don't require lightmapping.
     
    HakJak and theANMATOR2b like this.
  22. HakJak

    HakJak

    Joined:
    Dec 2, 2014
    Posts:
    192

    I would love it if someone made this properly, and with layers, and put it on the Asset Store. I've been using projectors and dynamic mesh decals, but the former is so damn computationally expensive and the latter doesn't work for complex geometry.
     
    Zicandar and ElectroMantis like this.
  23. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    I started doing something similar to that, not with Unity layers, but "self defined" ones, (stencil buffer, so a drop-down menu on materials that care).
    Problem is not getting it to work, it's all the "extras" that while not needed, make it alot easier and improve the quality of them.
    And I currently don't have the time free to complete this project.
     
  24. ruj

    ruj

    Joined:
    Feb 28, 2013
    Posts:
    113
    Is there a way for the deferred decals to use an existing mesh? I am looking into the system used by Star Citizen and described here: http://www.polycount.com/forum/showthread.php?t=155894 . I am still trying to wrap my head around it, but based on what I can make sense of it seems like this system is more or less using a system of projecting the normal detail onto the object from meshes that are placed in model? Wondering if it is some variant of what you were describing here.
     
  25. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,436
    Check this thread out:
    http://forum.unity3d.com/threads/ho...algbuffer-modifier.356644/page-2#post-2327120
     
  26. ruj

    ruj

    Joined:
    Feb 28, 2013
    Posts:
    113
    Thank you! This is exactly what I was wondering.
     
  27. Filhanteraren

    Filhanteraren

    Joined:
    May 14, 2014
    Posts:
    47
    Did this project die?, was really looking forward for an good easy to use decal system for Unity( since Unity team seems to hate the idea of making something for the engine themselves) Would be cool to have something opensourced up on github so everyone could help out.
     
  28. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    Looks dead... Sad, since I really need some good deferred decals.
     
  29. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,436
    chelnok likes this.
  30. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,374
  31. chelnok

    chelnok

    Joined:
    Jul 2, 2012
    Posts:
    680
    Martin_H likes this.
  32. Filhanteraren

    Filhanteraren

    Joined:
    May 14, 2014
    Posts:
    47
  33. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
  34. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,436
    I'm still looking for something like that myself. Please let me know if you find a solution.
     
  35. bigd

    bigd

    Joined:
    Feb 14, 2014
    Posts:
    40
    I too am interested in a "production-ready" deferred decal solution.
     
  36. Filhanteraren

    Filhanteraren

    Joined:
    May 14, 2014
    Posts:
    47
    It´s quite bad that there is nothing like it somewhere. A proper deferred decal system on the assetstore would be quite popular i think.

    Since the lack of stuff i decided to give it a go myself. I have never done any shader work so it might be a slow start. If I get something decent I will put up in Github to share it.
     
    ArthurT and Martin_H like this.
  37. ArthurT

    ArthurT

    Joined:
    Oct 26, 2014
    Posts:
    75
    Still amazes me that up to this day we don't have a proper deferred decal system, but if anything I'd like help with extending on that if possible. Having PBR support and parallax would be fantastic to have, it'd add so much detail for levels and more.
     
  38. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Shame about the framerate nightmare that follows though, so this isn't the be all, end all. Alloy has a setup for deferred decals if anyone is impatient.
     
    JamesArndt likes this.
  39. chelnok

    chelnok

    Joined:
    Jul 2, 2012
    Posts:
    680
    I thought deferred decals were better for performance, like it goes with deferred lighting. Not the same?

    I haven't test Alloy's deferred setup yet as it's not supporting runtime iirc. Have you done any test with it?
     
  40. Filhanteraren

    Filhanteraren

    Joined:
    May 14, 2014
    Posts:
    47
    What´s the biggest problem performance issues would you say?
    I tested with an empty scene and around 400 decals takes around 1ms on the gpu.
    Going to test some more and see how it turns out.

    Does the Alloy setup work with runtime decals yet?
     
  41. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    Sadly this project is currently dead due to lack of time for me to work on it.
    I got pretty far but there are some issues that are near-unsolvable without storing more information.
    Blending normals is one of the big issues.

    Here is what I have, not sure if it's actually the latest code or not, but it's a start:
    https://www.dropbox.com/s/ir8f3pj3yk9bdkp/DecalExport.unitypackage?dl=0
    I'll look on my computer later and see if I can find the original code I was working on...

    The main performance issue hits if you need them to be more "correct", but that's something I'm not going to start explaining now. Otherwise the main cost are the additional draw calls, and if using the same decal 400 times it might not be so bad, but when you have 200 different ones it might cost a little. Then again, so does every alternative.
     
    Last edited: Mar 21, 2016
    SpreadcampShay, KWaldt, moure and 2 others like this.
  42. JacobK

    JacobK

    Joined:
    Jun 18, 2013
    Posts:
    20
    Thanks for sharing, Zicandar!

    Did you manage to solve the ambient / lightmapped not getting lit issue?
     
  43. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
    Ambient light can be solved quite easily now that Unity has moved WHEN they apply that if I remember correctly. ( http://docs.unity3d.com/ScriptReference/Rendering.CameraEvent.BeforeReflections.html )

    However lightmaps would require more work. As they generally don't use world space co-ordinates but per-object/UV info. It's solveable, (somewhat), but not something I would suggest trying unless you really need it. (You will need to defer WHEN the lightmap is applied, and apply them yourself).

    If there is major interest and one or two programmers/people who would be willing to collaborate on this project it might be possible for me to find some time to do it.
     
    CrisisSystem likes this.
  44. DanielDickinson

    DanielDickinson

    Joined:
    Aug 4, 2013
    Posts:
    278
    [Shameless (but hopefully helpful) Plug]

    If anyone is still interested in a deferred decal solution I just released one on the asset store. Its supports both forward and deferred decals. (Deferred uses the deferred screen space method discussed here). This thread, you guys, actually got me over a few hurdles when developing it so it seems only fitting I come back and share the result.

    Cheers, Dan

    Asset Store
    Forum Page