Search Unity

[RELEASED] Dynamic Decals

Discussion in 'Assets and Asset Store' started by DanielDickinson, Jan 12, 2017.

  1. Killersan

    Killersan

    Joined:
    May 27, 2014
    Posts:
    76
    I got such error: Assets/Dynamic Decals/Scripts/Core/DynamicDecalSettings.cs(2,7): error CS0246: The type or namespace name `UnityEditor' could not be found. Are you missing an assembly reference?
    It's clean project with only dynamic decals and this error occurs while I'm trying to build player, even I have new default scene which I want to build without any DD object only Directional Light and main Camera, so pretty default. It seems that there are some issue in 2.0.
     
  2. DanielDickinson

    DanielDickinson

    Joined:
    Aug 4, 2013
    Posts:
    278
    @castor76 - Cheers, I'll go through and update all the samplers. Nice catch :).

    This is the technique I was already using for the system in forward, and I'm packing masking into the same draws (ie. rendering depth, normals, masking all at once in a single call). If your not making heavy use of the system, ie. just drawing a few decals on objects you know will be rendered in deferred, and don't need to mask anything, the old deferred technique will suit you better. But even when you have few decals, you still usually need to mask a fair amount. I've always got copies of 1.6 for anyone interested, but in 99% of cases I would definitely suggest 2.0.

    @Killersan - snacktime got this bug, patch incoming later in the week, if you want an immediate copy send me an email at Support@LlockhamIndustries.com :).
     
  3. grujicbr

    grujicbr

    Joined:
    Aug 19, 2014
    Posts:
    18
    Hi,

    I found another issue with the decals rendering the grass rendering with the default unity terrain.

    It looks like no matter what layer i set this on, it renders on top of the grass
    (the unity grass shader is just alpha test I believe...)
     

    Attached Files:

  4. DanielDickinson

    DanielDickinson

    Joined:
    Aug 4, 2013
    Posts:
    278
    @grujicbr - Unfortunately there's no reasonable way to separate the terrain from the grass in Unity's current terrain engine. The grass is tied into it on the same rendering layer. It might be possible to dig into it, get the positions of all the grass, factor in wind etc. and render all the grass into a mask buffer using a command buffer, but this would be far too slow to be practical. Unity's new terrain engine cannot come soon enough.

    Remember though, that masking should always be your secondary option. If you don't want to project onto grass, in a lot of cases you can get away with simply reducing the thickness of the projection bounds.
     
    Last edited: Sep 2, 2017
  5. djarcas

    djarcas

    Joined:
    Nov 15, 2012
    Posts:
    246
    Couple of things.

    1) It doesn't work properly with Single-pass stereo. Some patches only appear in the left eye, some only in the right eye.
    2) Performance... isn't brilliant. I can go over some of in in more detail if you like, I did some profiling. Can do it here or directly via email if you'd prefer. (~400 decals, forward rendered, 4.8 ghz i7 is taking 10 ms!)
     
  6. DanielDickinson

    DanielDickinson

    Joined:
    Aug 4, 2013
    Posts:
    278
    @djarcas - Any chance you could provide me with a few details.. Which headset are you using? Do you have the shader replacement set to VR (Dynamic Decals settings menu)?

    As for performance profiling, feel free to share here, but definitely email me as well. I'd like to get a back and forth going, need to figure our why it's so expensive and get it down to something reasonable. Cheers.
     
  7. djarcas

    djarcas

    Joined:
    Nov 15, 2012
    Posts:
    246
    Shall I just guess at an email address? ;-)

    helpmewithmydecals@llockhamindustries.com ?
     
    Martin_H likes this.
  8. grujicbr

    grujicbr

    Joined:
    Aug 19, 2014
    Posts:
    18
    I don't really see how the projection box depth will solve any of this, the moment it is behind any grass it will get projected onto it. I dont see Unity's new terrain engine coming anytime soon, probably be a year or two from now.

    As far as performance goes, whats the primary reason for going forward with 2.0 update? You still have to render each decal regardless of forward/deferred but its primarily the cost of lighting them that will be much more expensive if you go with forward...

    The update is seeming a lot less appealing for anyone seriously considering using this for a game.
     
  9. djarcas

    djarcas

    Joined:
    Nov 15, 2012
    Posts:
    246
    Note : You can't make builds with the current code due to DynamicDetailSettings incorrectly referencing Editor stuff in builds. Simple to fix tho.
     
  10. djarcas

    djarcas

    Joined:
    Nov 15, 2012
    Posts:
    246
    Er, instancing? ;-)

    Let's be honest tho, Unity's terrain system was a joke when it came out, and it's a joke now. Agreed with "A replacement can't come soon enough"
     
  11. grujicbr

    grujicbr

    Joined:
    Aug 19, 2014
    Posts:
    18
    GPU Instancing i assume is only happening to instance render the bounding boxes used to project onto surfaces. While yes gpu instancing of that is great, that on its own can work in deferred as well
     
  12. djarcas

    djarcas

    Joined:
    Nov 15, 2012
    Posts:
    246
    Given that all of the decals use the same shape to render with, and the same material can be used thousands of times, it's a great candidate. Sadly, I think this is using the 'Unity gameobject' way of instanced rendering, as opposed to generating internal lists and shunting them to the renderer; I've used that method in my own games, and best of all, it means you can actually start doing a bunch of the hard work off on a thread.
     
  13. grujicbr

    grujicbr

    Joined:
    Aug 19, 2014
    Posts:
    18
    Again, instancing is great, I just dont see why you have to instance in forward, and pay the cost of lighting each decal, versus only paying the cost per decal of writing into the gbuffer and lighting it once :)
     
  14. DanielDickinson

    DanielDickinson

    Joined:
    Aug 4, 2013
    Posts:
    278
    @djarcas - Apologies, use my support address (Support@LlockhamIndustries.com). Thanks. Have a few ideas on how to speed up shader replacement for VR, need to test to see if they'll work though. Would also like to see if you doing something I didn't expect that's causing the performance issues, show me the details :).

    @grujicbr - I'm not sure where you got the impression the decals themselves where being rendered in forward rendering, but your definitely correct, Deferred decals is the perfect candidate for GPU-instancing. In forward sadly only the first pass is able to be instanced, though this still gives massive benefits (and Unlit decals only require one pass). The decals themselves are rendered in deferred if your using the deferred rendering pipeline, with all of your other mesh and skinned mesh renderers. It's just not using the deferred buffers as a normal source (As you can't read from and write from the same render-texture at once). Instead it draws your normals while doing the shader-replacement for masking.

    I also experimented with internal lists passing to the renderer via Command-Buffers, the systems built on dependency Injection so all the information was already there. Culling was still the major culprit here though. This is already performed asynchronously, but you can't poll transforms and update culling sphere arrays on another thread, as it's tied too closely to the transform component which isn't currently thread-safe. If we could guarantee all projections would never move it wouldn't be a problem, but the whole point of the system is that your free to do what you wish with the decals. Doing it the Game-object way gives us culling at C++ speeds (Saves about 3ms per 10,000 decals in the scene (not just on screen, which adds up fast!)), and gives massive performance boosts over command buffers.

    Also consider that the last version (1.6) couldn't mask terrains to begin with, so while you may not be able to mask terrain grass & detail meshes independently, it's still definitely a step in the right direction :).
     
  15. grujicbr

    grujicbr

    Joined:
    Aug 19, 2014
    Posts:
    18
    :) Good to know that is in fact what you are doing (I didn't have time to look at the source code, was going by the comments).

    Aside from the terain vbo being rebuilt, I'm quite happy with the package with one exception. Is there a specific reason you decided to pull out the RandomScale / Fade scripts to be outside of the .asset files?
     
  16. DanielDickinson

    DanielDickinson

    Joined:
    Aug 4, 2013
    Posts:
    278
    @grujicbr - from the asset files I assume you mean the projections themselves? I don't think it makes a lot of sense to have have them included as part of the projection, as projections can have multiple renderers that reference it, so fading the alpha of a projection would fade it for all renderers referencing that projection. It could be included in the renderer itself, but not all renderers need to fade/have a random scale, so it makes more sense to have these scripts separate, and allow printers to print with these scripts attached, when there required. They also serve as example scripts for people wishing to script with the system :).
     
  17. Thermos

    Thermos

    Joined:
    Feb 23, 2015
    Posts:
    148
    Hi,
    Is it possible to exclude layers from the entire system? for example, I don't want characters to receive any of those decals, instead of render mask buffer, the system should not render the "character" layers at all to save these upfront cost. I debugged your code, where you seems to render all layers with culling layermask = -1, it's definitely possible to do so, just lack an editor setting to exclude layers from decal system.
     
  18. DanielDickinson

    DanielDickinson

    Joined:
    Aug 4, 2013
    Posts:
    278
    @Thermos - You still need depth and normals of your characters to be rendered, even if you never want decals projected onto them. Otherwise the system won't know your characters are there and will render projections over the top of where your characters are in screen-space. ie. you need to render your characters as occluders, this applies to masking as well.
     
  19. DanielDickinson

    DanielDickinson

    Joined:
    Aug 4, 2013
    Posts:
    278
    2.0.1 has been submitted to the store. It should be available within the week. It includes fixes to all the bugs listed here, as well as a few more that have been brought to my attention. Thanks to everyone who submitted bug reports and posted here on the forum. Appreciate your time and your patience.

    If anyone would like a copy of the fixes early I'm always happy to send out early copies. Email me at Support@LlockhamIndustries.com & I'll send you a build :).
     
    spaceemotion likes this.
  20. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    864
    Hi, I'm interested in this system and have a questions before I buy:
    Is it for me to use this decal system to create a persistent ( not forever but may linger longer than an hour in real time) footsteps system for animals? How is the optimization and will massive decals cause frame drop?
     
  21. DanielDickinson

    DanielDickinson

    Joined:
    Aug 4, 2013
    Posts:
    278
    @Harekelas - Persistent decals are definitively possible, now more than ever as 2.0 has close to no cost for offscreen projections (as Unity gameObject culling is so insanely cheap). Massive decals are relatively cheap, as the shaders are very cheap to run (no branching/ shadow passes not required etc.) And with instancing, if you atlas all your tracks you can draw 500 - 1000 per drawcall :).
     
    ZoneOfTanks likes this.
  22. Teh_Lemon

    Teh_Lemon

    Joined:
    May 12, 2015
    Posts:
    17
    Hi. Currently have a system set up with Unity Projectors to do real-time fake-shadows. Looking to possibly switch over to something more modern.
    Do your decals have perspective projection with adjustable field of view, near/far clip planes and support for falloff like Unity's Projectors?
    Thanks.
     
  23. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    864
    great to know! I'll try your system out!
     
  24. DanielDickinson

    DanielDickinson

    Joined:
    Aug 4, 2013
    Posts:
    278
    @Teh_Lemon - Currently the system only supports Standard (Orthographic) projection and Omni-directional projection (Think blast craters, ripples etc.) Perspective based projection definitely sounds useful though. Added to my list of things to try out, no promises yet though.
     
    Lukinovo likes this.
  25. ZoneOfTanks

    ZoneOfTanks

    Joined:
    Aug 10, 2014
    Posts:
    128
    Looks good :)
    Does this system supports normal maps for decals? Or tessellation?
     
  26. DanielDickinson

    DanielDickinson

    Joined:
    Aug 4, 2013
    Posts:
    278
    @abrasive - The system definitely supports normal maps. As for projecting onto tessellated geometry, I've not tried but I don't think it would work perfectly, simply because the shader replacement used by the system would not factor in tessellation. It would still render over the surface, but the depth tessellation gives you wouldn't be present underneath the projection.
     
  27. ZoneOfTanks

    ZoneOfTanks

    Joined:
    Aug 10, 2014
    Posts:
    128
    I just need to paint marks from vehicles on tessellated terrain. For example in CTS terrain shader in real-time.
    Hmmm...
    Does this system can place meshes or materials on terrain?
     
  28. DanielDickinson

    DanielDickinson

    Joined:
    Aug 4, 2013
    Posts:
    278
    @abrasive - You can definitely place decals on your terrain at run-time. The system includes printers that allow you to print decals based on collision, particle collision, ray collision etc. You can instantiate and move decals at run-time like you would any other gameObject though, so if you want to place them via script yourself, you are certainly able too as well.

    As for tessellation, it's great, but it limits what you can a lot. To my knowledge there's no way to incorporate custom geometry shaders into Unity's shader replacement (Without replacement variants for every variant of tessellation). So if your using Tessellation you might have to give up deferred rendering as well as any screen-space image effects/ techniques. Your effects will be sampling from non-tessellated buffers, which could cause issues. If you give it a go, tell me how it goes.
     
    ZoneOfTanks likes this.
  29. akareactor

    akareactor

    Joined:
    Apr 6, 2015
    Posts:
    108
    During build got this:

    Shader error in 'Projection/Decal/Specular/Forward': failed to open source file: '../Cginc/ForwardProjections.cginc' at line 112 (on d3d11)

    Compiling Vertex program with DIRECTIONAL LIGHTMAP_ON
    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
     
  30. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    864
    Hi again,
    I've imported dynamic decal to unity 5.6.3 then opened the demo showcase scene
    But I got a lot error with this same message:

    NullReferenceException: Object reference not set to an instance of an object
    LlockhamIndustries.Decals.ProjectionData.AssertOrder (System.Int32& Order) (at Assets/Dynamic Decals/Scripts/Core/DynamicDecals.cs:1185)
    LlockhamIndustries.Decals.DynamicDecals.OrderRenderers () (at Assets/Dynamic Decals/Scripts/Core/DynamicDecals.cs:271)
    LlockhamIndustries.Decals.DynamicDecals.LateUpdate () (at Assets/Dynamic Decals/Scripts/Core/DynamicDecals.cs:579)

    any ideas?
     
  31. DanielDickinson

    DanielDickinson

    Joined:
    Aug 4, 2013
    Posts:
    278
    @Harekelas - For now, you can just enter and exit play mode and the issue will resolve itself. I've fixed this internally, it will be included in the next patch. If it's bugging you to no end, send me an email (Support@LlockhamIndustries.com) and I'll send you an immediate fix :).
     
  32. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    864
    thanks for the reply, I'm not in a hurry of implementing this asset into me project so I can wait the next update ;)
     
  33. docsavage

    docsavage

    Joined:
    Jun 20, 2014
    Posts:
    1,021
    Hi @Llockham-Industries,

    I think this decal system could be really useful in my game and it looks great. Just want to check how it runs on different platforms as I can't find any info on this. I've scan read part of this thread and checked the store page but no joy.

    Just need to know if there's any devices /modes it won't run on. I'm using linear for higher end builds and gamma for lowe end. All cameras are perspective. Plan on releasing on as many platforms as possible except VR and AR.

    Thanks

    doc
     
  34. DanielDickinson

    DanielDickinson

    Joined:
    Aug 4, 2013
    Posts:
    278
    @docsavage - The system should run on every platform Unity supports. The only one I can't confirm it working with is holo-lens. I've either tested myself or had reports that it works on PC, Max, UWP, XboxOne, PS4, IOS, Android (Currently requires a shader fix being uploaded in the next patch) Vive & Occulus. But there's no reason it shouldn't work on platforms not mentioned as well. It even has shader variants to support ShaderModel 2.0, for anyone developing for insanely old hardware :).
     
  35. tolosaoldfan

    tolosaoldfan

    Joined:
    Sep 14, 2012
    Posts:
    92
    Hello,
    I just install your product on the Unity2017.2.b9 on Windows 10 and I got this error :

    NullReferenceException: Object reference not set to an instance of an object
    LlockhamIndustries.Decals.ProjectionData.AssertOrder (System.Int32& Order) (at Assets/Dynamic Decals/Scripts/Core/DynamicDecals.cs:1200)
    LlockhamIndustries.Decals.DynamicDecals.OrderRenderers () (at Assets/Dynamic Decals/Scripts/Core/DynamicDecals.cs:271)
    LlockhamIndustries.Decals.DynamicDecals.LateUpdate () (at Assets/Dynamic Decals/Scripts/Core/DynamicDecals.cs:617)

    It's not urgent, nor critical for the moment for us, but it's was just to warn you.
     
    DanielDickinson likes this.
  36. docsavage

    docsavage

    Joined:
    Jun 20, 2014
    Posts:
    1,021
    Thanks for the reply. Good to hear this. Will be having a good think but am sure your system will work out better than what currently using.

    Thanks
     
    DanielDickinson likes this.
  37. sacmanis

    sacmanis

    Joined:
    Feb 25, 2016
    Posts:
    9
    I can't find a way to print on mouse click. This is the only reason I purchased the asset although I can see other uses for it in the future. So what I did was add a Mouse option to the collision printer script and look for a mouse click.

    While this works, there seems to be an issue. I am printing a specular decal to add cracks to a wall. I need both the color and the normals and this seems to be the best method. Using constant or delay or any of the other option results in the decal as expected with normals. Using my new method which simply adds a new condition and looks for a mouse click before printing, the normal seems to be missing. I am calling the same PrintCollision(collision) function. I have not changed that at all.

    I can't imagine why this would happen.

    Other than adding Mouse to the enumerator, this is the entirety of the code I added right below the Constant condition check.

    Code (CSharp):
    1. if (condition == CollisionCondition.Mouse)
    2.                 {
    3.                     if (Input.GetMouseButtonDown (0))
    4.                     {
    5.                         PrintCollision(collision);
    6.                     }
    7.                 }
     
  38. sacmanis

    sacmanis

    Joined:
    Feb 25, 2016
    Posts:
    9
    To add to the above here are the three cases. The top is the Mouse click. The middle is what the positioner shows, and the bottom is using delay print.

    upload_2017-9-10_0-24-0.png
     
  39. DanielDickinson

    DanielDickinson

    Joined:
    Aug 4, 2013
    Posts:
    278
    @sacmanis - How you print a projection won't effect the projection itself, it's essentially just instantiating your projecting (or pulling an instantiated copy from the pool). If normals aren't working my best guess is that the it's likely the projection is facing backwards. I'd also recommend against modifying the in-built printers, as you'll have to remake these modifications when you want to update.

    Instead I'd recommend using a Ray Printer and passing it a ray by calling it's PrintOnRay() method in an attached script (You could pass Camera.ScreenPointToRay(Input.mousePosition)).

    Alternatively you could cast the ray yourself, get the position and rotation of the decal you want to place and use that with a plain printer. You would then call Print() with the position and rotation you calculated.

    These approaches give you all the benefits of using an in-built printer (Pooling, Printing behaviors, overlap detection, Tag/Layer based printing etc.) without having to hack one apart.

    Your third option is to simply instantiate the projections from a prefab yourself, and place them where-ever you like, at whatever rotation you like. This seems more work than is necessary, but if you want complete control the option is available to you.

    Hope this helps clear things up :).
     
    hippocoder likes this.
  40. sacmanis

    sacmanis

    Joined:
    Feb 25, 2016
    Posts:
    9
    Thanks for the quick reply. I needed to sleep on it. What was happening is during that very brief period that the mouse button was down, a lot of fixed updates were happening and it was layering them. So I handled that and all is well.

    While I agree that modifying the underlying code is not the best way, it is probably the easiest way for me. Reading all of your possible solutions, they are all more complicated than the simple few lines of code I have added. I will read through them again in a bit and see if one of them is a better solution. I have to head out for a little while. This might be something you could consider adding in a future update. Imagine being able to add graffiti or posters to a wall in a 'build' type game or an open sandbox style game.

    Thanks again!
     
  41. benthroop

    benthroop

    Joined:
    Jan 5, 2007
    Posts:
    263
    I came across a bug which was a bear to track down but is easy to reproduce. If you have a particle system that has cast shadows set to ON, and it is drawing in the same area as a Dynamic Decal, the particle billboards will turn to face the light source, not the camera. It's a pretty easy repro. Current workaround is to shut off shadow casting on particle systems, which if you're using billboards is almost always what you want anyway. I just happened to be using an asset that had shadows on.

    Repro:
    1. Empty scene
    2. Cube floor
    3. Place a sphere on the cube so it casts a shadow (EDIT: forgot this one before)
    4. Place a Dynamic Decal so it projects onto the floor
    5. Create a default particle system intersecting with the decal volume
    6. You can set up layers on the decal system if you want - I don't think it matters
    7. Turn on Cast Shadows on the Particle System
    8. Note the particle billboards turn away from the camera
    9. Turn off Cast Shadows on the Particle System
    10. Particle billboards return to face camera

    Edit - added sphere on cube to create a single shadow caster. Without this the shadow render doesn't happen and the particles do not turn.

    Also, This is on Unity 2017.1.1
     
  42. DanielDickinson

    DanielDickinson

    Joined:
    Aug 4, 2013
    Posts:
    278
    @benthroop - Nice find, Unity haven't gotten back to me and confirmed it's a known bug caused when drawing in OnPreRender() (ie. performing shader replacement). The current work around is to move the system into OnWillRenderObject() but this will check each projection once per camera, and when you have a few thousand projections this quickly adds up to a performance hit. Either that or generate a render-able object for each camera that cannot be culled, so we can get reliable calls, but this will likely fall apart in corner cases and cause more bugs.

    As, like you said, shadow casting for bill-boarded particles is very uncommon, I'm trying to avoid implementing either approach into the main branch and instead waiting for Unity to patch the issue. If anyone needs a fix immediately though, I'll be happy to set this up for them :).
     
  43. benthroop

    benthroop

    Joined:
    Jan 5, 2007
    Posts:
    263
    OK yeah it's easy enough to work around for now. Agreed it's best to just wait for Unity to fix. Thanks for investigating.
     
  44. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Shadows on billboards is becoming a lot more common with the new standard particle system shader (bullet casings , blood, proxy geo etc) I do it a lot. It does look like a problem solved with SRP or at Unity's side though - to confirm, you guys reported this already right?
     
  45. Fairennuff

    Fairennuff

    Joined:
    Aug 19, 2016
    Posts:
    88
    upload_2017-9-14_20-26-41.png

    Getting this when creating a projection Renderer in my project. It is a VR project and I did not see an option for Vr in the settings menu. Any ideas?
     
  46. DanielDickinson

    DanielDickinson

    Joined:
    Aug 4, 2013
    Posts:
    278
    @hippocoder - Yeah bug report has been submitted. I built a quick demo scene for them. They're actually the ones who got back to me suggesting I use OnWillRenderObject() or OnPostRender().

    @Fairennuff - Known bug, but thanks for submitting a bug report :). It'll be fixed in the next update. If your on 2017.1 you won't need to set shader replacement in VR, it should automatically detect VR use on a per camera basis and adjust accordingly.
     
  47. mrBeam

    mrBeam

    Joined:
    Mar 17, 2014
    Posts:
    11
    I'm trying to edit the shaders that you use. Your UnlitAdditive ends up rendering between Alphatest and Transparent layer. But when I try to change this to Opaque render queue it does not show up at all. Even with ZTest Always. Am I misunderstanding something?

    This works the other way as well, even with render queue Overlay it does not render over transparent layer.
     
  48. DanielDickinson

    DanielDickinson

    Joined:
    Aug 4, 2013
    Posts:
    278
    @mrBeam - Projections don't write to the depthBuffer. So it's possible that, by moving it forward, the projection is being rendered before the object it's meant to be rendered on. The object it's meant to be rendered on is then simply being rendering over it?
     
  49. mrBeam

    mrBeam

    Joined:
    Mar 17, 2014
    Posts:
    11
    Thank you for the quick reply, the problem seems to be when mixing sprites in a 3D-world. The sprite sorting layers combined with render queues. The objects that did not occlude the decal could be moved to Sprite order layer 2 and that fixes it. Very strange, because they both uses the same render queue and thus should not behave differently. So it's probably out of your control.
    Thanks again!
     
  50. Fairennuff

    Fairennuff

    Joined:
    Aug 19, 2016
    Posts:
    88
    So if it's a known bug, is there no fix? Nothing renders when I put a projection renderer on anything. Haven't had time to test anything else yet.