Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

[RELEASED] Decalicious – Deferred Decal System

Discussion in 'Assets and Asset Store' started by Daerst, Nov 21, 2016.

  1. Thermos

    Thermos

    Joined:
    Feb 23, 2015
    Posts:
    51
    Because some shaders are loaded at runtime via scripts. Like Shader.Find("xxx");
     
    Deckard_89 likes this.
  2. Daerst

    Daerst

    Joined:
    Jun 16, 2016
    Posts:
    211
    Exactly. Need to fix this in the next Decalicious release.
     
    Deckard_89 likes this.
  3. Daerst

    Daerst

    Joined:
    Jun 16, 2016
    Posts:
    211
    Decalicious 1.5.1 has just been submitted for review to the AssetStore.
    It restores Metal compatibility in Unity 2018 and should resolve all problems with missing shaders in builds.
     
  4. patrykk

    patrykk

    Joined:
    May 20, 2017
    Posts:
    13
    I have an issue - if I set a parent object to limit the decal display in "Limit To", it no longer draws on the unity terrain, even though the terrain is a child of the gameobject I selected: https://www.screencast.com/t/A9KoSY1NjQ
    Can you look into it?
     
  5. SimonsCat

    SimonsCat

    Joined:
    Mar 11, 2015
    Posts:
    19
    Hi, we found and interesting bug(feature?) while using the decals in our project.
    We usually create textures with Substance Painter and export the files in Unity using the default export settings. However, we discovered that the settings used to export textures for the standard shader does not work with Decalicious.
    Instead of NormalMap OpenGL format we must set NormalMap DirectX format... and only in this case the normal maps behave correctly under different lighting conditions (for example, a single directional light).

    Any idea why the Shader "Decalicious/Deferred Decal" uses the normal map in DX format and not the OpenGL as all other standard unity shaders? Do we miss something in the process?

    Can I add something to the shader to flip the NM from -Y to +Y? And the decalTangent?
     
  6. Wintermute-

    Wintermute-

    Joined:
    Sep 5, 2017
    Posts:
    14
    Hello,

    I bought your decal plugin, and it is absolutely amazing. The only problem is that I am using double pass for VR and did not see the Trello posts. I wanted to know if you are still working on the solution for double pass or if you plan to fix it in the future. I will release the game start of next year and would like to know if I should wait or change the decal system for this project in particular.

    Thank you.
     
  7. Daerst

    Daerst

    Joined:
    Jun 16, 2016
    Posts:
    211
    I'll check it out, thank you.

    That's interesting. I'll look into it.

    Flipping the Y should be easy - the normal is sampled in DecaliciousDeferredDecal.shader, line 136.
    I don't fully understand the second question "and the decalTangent" though. If you want to flip the normal map's tangent (X component?), you can also do it there.

    Sorry @Darkwind27, I've tried several things and it's really tough to find a solution that works for all modes (single pass, double pass, desktop). There won't be any official fix this year.

    Thank you all for the feedback! I hope we'll be able to address the issues soon.
    David
     
  8. UnityRocksAlt

    UnityRocksAlt

    Joined:
    Dec 28, 2015
    Posts:
    134
    Is there a quick way to sort out Decals by Layer? or by Name.
     
  9. Jribs

    Jribs

    Joined:
    Jun 10, 2014
    Posts:
    45
    Hi what email should I contact for a refund? I misunderstood the description thinking only part of it was for deferred rendering. I'm doing VR so I need forward rendering.
     
  10. Daerst

    Daerst

    Joined:
    Jun 16, 2016
    Posts:
    211
    There is no built-in function for this, but you can manually disable the Decals in question using whatever filter you want.

    There is an e-mail link here (the small envelope under the logo): https://assetstore.unity.com/publishers/13112
    Please send your invoice number.
     
  11. Jribs

    Jribs

    Joined:
    Jun 10, 2014
    Posts:
    45
    @Daerst
    Hi i decided to keep it since it seems to be the only asset that works on skinned meshes.

    One issue I'm running into is the "Limit To" field doesn't seem to be working at all. No matter what object I put in there, it just makes my decal disappear completely. Is there some trick that I am missing?

    I am placing the decal on the model, I can see the model displaying on the mesh fine. But if I drop the object that It is currently on top of into the "Limit To" field, the decal disappears.

    Edit: It looks like Limit To might not be supported for skinned meshes, is this true?
     
    Last edited: Jan 16, 2019
  12. Daerst

    Daerst

    Joined:
    Jun 16, 2016
    Posts:
    211
    True. I had it working, but it is currently untested.
    However, if you want to enable it, uncomment lines 206 and 207 in DecaliciousRenderer.cs and see if that does the trick. Warranty ends here, but maybe it works for you :)
     
  13. protopop

    protopop

    Joined:
    May 19, 2009
    Posts:
    1,092
    I'm wondering what does this mean : "use decals to get rid of those hard mesh-terrain edges"

    Do you have any examples? Is this a way to hide hard edges in a unity terrain?
     
  14. Daerst

    Daerst

    Joined:
    Jun 16, 2016
    Posts:
    211
    You can see it in the example scene, you can use a decal that affects both mesh and terrain to do a manual blending that hides the edge. Left is without decals, right with decals:
    upload_2019-1-24_19-50-24.png upload_2019-1-24_19-50-36.png
     
    protopop likes this.
  15. protopop

    protopop

    Joined:
    May 19, 2009
    Posts:
    1,092
    cool - thank you for the example :)
     
  16. Manul_

    Manul_

    Joined:
    Jul 28, 2015
    Posts:
    12
    Hi, I bought this asset because I thought that I could limit the drawn decals to a unity terrain. This does not seem to work. Is there some sort of workaround to have them only be drawn on the unity terrain?
     
  17. holdingjason

    holdingjason

    Joined:
    Nov 14, 2012
    Posts:
    89
    Same problem with terrain. Limit to does not appear to work with terrains.
     
  18. Daerst

    Daerst

    Joined:
    Jun 16, 2016
    Posts:
    211
    @Manul_ @holdingjason The Limit To feature only works with MeshRenderers. Here's why:
    In order to limit to a specific object, we need to know which pixels are covered by this object. To achieve this, the meshes used as LimitTo targets are rendered into a special buffer with a custom replacement shader. This is easily doable for MeshRenderers. It's somewhat doable for SkinnedMeshRenderers (but requires you to use BakeMesh and is pretty slow at that). From the Unity terrain, afaik, it's not possible to get the mesh directly - so I have nothing I can render for the LimitTo.

    Current workarounds are:
    1) not using the Unity terrain, but meshes.
    2) Placing an invisible mesh (e.g. Cutout shader with alpha = 0) that fits the shape of the terrain slighty above it, and using that for LimitTo.

    I know it's not great, but working with Unity terrain really isn't that nice if you need access to the internals :/
     
  19. holdingjason

    holdingjason

    Joined:
    Nov 14, 2012
    Posts:
    89
    Do you have a link or good example of creating a mesh on the fly that would overlay a portion of the terrain? I know I have seen some stuff out there on this before but having a tough time tracking it down again. Thanks and what you said does make sense. I guess that would be in essence a mesh decal.
     
  20. Manul_

    Manul_

    Joined:
    Jul 28, 2015
    Posts:
    12
    Hey, I found a hacky solution to accomplish what I wanted (But I understand that it cannot be a solution for everyone, because it involves some manual shader adjusting).
    The alpha value of RT2 of the deferred shading path is unused (https://docs.unity3d.com/Manual/RenderTech-DeferredShading.html) and defaults to a value of 1. So in the terrain shader and grass shader where I want the deferred decals I set this value to 0. In the decal shader I then check this value and only draw if the value is zero.
    If someone needs the exact implementation details, you can PM me.
     
  21. drcrck

    drcrck

    Joined:
    May 23, 2017
    Posts:
    279
  22. jamespaterson

    jamespaterson

    Joined:
    Jun 19, 2018
    Posts:
    31
    Hi! I have generally been very impressed with Decalicious - it is very useful for dynamically applying damage to my terrain :) However, I have noticed something a little odd with normal mapped decals and I was hoping you could please confirm if this is expected behaviour.

    Essentially, normals always seem to be applied in the coordinate frame of the decal gameobject, without correction for the rotation of this object back to a world-coordinate frame. The net effect of this can be seen below. Here I have a normal mapped "crater" decal applied to a flat plane:

    Untitled1.png

    If I rotate the decal object about Y (the axis normal to the plane), then the decal rotates, as I might expect, however the shading moves as well giving the impression the light source has moved with the decal. Ideally I would want to rotate the decal whilst correcting the normals to account for the rotation to the shading direction remains constant.

    Untitled2.png

    Many thanks in advance for your help!
     
  23. Zargy

    Zargy

    Joined:
    Jul 13, 2014
    Posts:
    8
    Hey, does asset support Global Illumination or Baked Lighting? I've heard that deferred decals don't contribute to GI. Will those features still at least work if we use Decalicious? I know HDRP decals support that but I'd rather not switch to it because we're in the middle of a large project and we want to make sure said project performs well on older or lower-tier machines. I don't know if contributing to GI is something we absolutely need or not but I'd like to know.
     
  24. CianNoonan

    CianNoonan

    Joined:
    May 19, 2017
    Posts:
    29
    Hey,

    Is there any way to use this while having Deferred Reflections set to no support in the Graphics options? We need to be able to use the reflection probe anchor overrides and would like to make use of Decalicious.
     
  25. jamespaterson

    jamespaterson

    Joined:
    Jun 19, 2018
    Posts:
    31
    Hi all,

    So in the meanwhile regards my question above FYI i implemented a quick hack to the shader to manual rotate the normals about the y axis. This would probably not generalise very well but it solved the problem for me in the short term...
     
  26. kavika

    kavika

    Joined:
    Feb 23, 2017
    Posts:
    4
    In the profiler, I'm seeing per-frame allocation.


    PlayerLoop
    PostLateUpdate.FinishFrameRendering
    Camera.Render
    Culling
    SceneCulling
    CullSendEvents
    Decal.OnWillRenderObject() // I'm getting 0.8k/frame w/ 8 decals
    DecaliciousRenderer.OnPreRender() // Looks like O(1) of 400 bytes


    I have managed to do some hacks on my end that eliminate this, but I'd like to see if you have a better solution, or would like to do a better version of it.

    This is all happening inside DecaliciousRenderer. I was able to hack it locally by:
    • Using a Dictionary + List, instead of SortedDictionary, for _deferredDecals and _unlitDecals. This helps avoid the allocation in GetEnumerator() (which I couldn't seem to eliminate otherwise?). This requires me to re-sort the list and rebuild the dictionary every time I encounter a new RenderOrder (in AddDeferred, AddUnlit), but this was not a big deal for my use cases, since I think we aren't using many different values. Maybe there's something even more involved that can be done here, to keep sorting to a minimum, while still allowing quick insertion, and no (non-pooled) allocation per frame.
    • Doing internal pooling of HashSet<Decal>s, instead of always allocating them at runtime in AddDeferred/AddUnlit
    • Increasing the initial capacity of the HashSet<Decal>s using this ONE WEIRD TRICK (tm): https://stackoverflow.com/a/24452106/232593
     
    Last edited: Mar 1, 2019
    SimonsCat and jamespaterson like this.
  27. Daerst

    Daerst

    Joined:
    Jun 16, 2016
    Posts:
    211
    Thanks for pointing this out, I'll see if any of the proposed solutions are feasible.

    You're right, there is indeed something wrong with the calculation of normals. Needs fixing on my end, hopefully making your quick fix obsolete :)

    You can use GI / baked lighting, but the decal (being a dynamic object projected in screen space at runtime) won't reflect any light, and thus not contribute to the GI.

    Sorry, I don't know off the top of my head. Maybe you could try it out in your project?

    Thanks, I'll see if I can eliminate them!
     
    Last edited: Mar 11, 2019
  28. jamespaterson

    jamespaterson

    Joined:
    Jun 19, 2018
    Posts:
    31
    Hi Daerst! Many thanks for getting back to me / us. Look forward to the update when you are ready.
     
  29. Daerst

    Daerst

    Joined:
    Jun 16, 2016
    Posts:
    211
    Decalicious 1.5.2 is live on the AssetStore!
    • Fixed errors in the normal calculation of decals
    • Negative-scale decals are now drawn correctly
    • Improved LimitTo compatibility with Static Batching (requires Unity 2018 or newer)
     
  30. holdingjason

    holdingjason

    Joined:
    Nov 14, 2012
    Posts:
    89
    Just found an issue with LimitTo. Using a mesh and normal mesh renderer so that is not an issue. However if you limit to a gameobject/mesh/render that has multiple materials on it ie two or more materials it will only render the decal on the first one in the list not any of the others. So in this case the decal shows up on the wainscot part of the mesh but not any part that is using the 2nd material. Works fine if we are not LimitTo.

    Also anyway this could work with more then one limit to ie an array so I could feed in multiple objects to limit to?

    upload_2019-3-12_11-45-16.png
     
    Last edited: Mar 12, 2019
  31. Daerst

    Daerst

    Joined:
    Jun 16, 2016
    Posts:
    211
    Thanks for pointing this out. True, LimitTo doesn't play nice with submeshes yet. I'll try to include a fix in the next update :)
     
  32. holdingjason

    holdingjason

    Joined:
    Nov 14, 2012
    Posts:
    89
    Cool if you need to test something let me know and I would be happy to check it out for you.

    Also anyway this could work with more then one limit to ie an array so I could feed in multiple objects to limit to?
     
  33. r_carter

    r_carter

    Joined:
    Apr 4, 2013
    Posts:
    8
    The camera in the example scene uses graphics settings, so when I ran the example no decals were visible.
    After changing the settings decals appeared but only in game mode.
    How to enable them on the scene in the editor?
     
  34. Daerst

    Daerst

    Joined:
    Jun 16, 2016
    Posts:
    211
    For now, you can only use one and limit to all its children that have a MeshRenderer. I've tested so many different things with LimitTo, and so far haven't found anything that is perfect, but I will gradually introduce changes to LimitTo with the next couple of updates.

    If you set your project to Deferred in the Quality settings, Decals should also be visible in the scene view. It actually should also work if you just set the Main Camera to Deferred, so I wonder what's wrong. Please provide more detail (what you did, Unity version, OS, GPU manufacturer etc.).
     
  35. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    740
    Hi, just bought the asset and testing it out.
    Is there any way to limit decals to certain layers? Or, I'm trying to only let decals to be rendered on terrain, but now it seems to also be rendered on any objects come into the volume.
     
  36. Buka

    Buka

    Joined:
    Feb 22, 2013
    Posts:
    36
    Hi, this asset is good so far but as as Harekelas mention we have the same issue and we need some way to avoid this and have it render only on terrain. Layer option would be nice, i cannot fix it with one object options since Terrain does not have Mesh Renderer. You can add an option for example: UseOnTerrain only, Ignore Trees etc, that would be great. Thanks!!!
     

    Attached Files:

  37. SmashedAvocado

    SmashedAvocado

    Joined:
    Dec 19, 2013
    Posts:
    36
    I'm having an issue here as well where no decals are showing in scene view but are in the game. It's a new project. Unity 2018.3.10f1

    All cameras and settings are on deferred.

    Windows 10, GTX 1080 Ti

    Any ideas?
     
  38. Deckard_89

    Deckard_89

    Joined:
    Feb 4, 2016
    Posts:
    199
    Does Decalicious work on skinned meshes?
     
  39. JamesHorn

    JamesHorn

    Joined:
    Jan 10, 2019
    Posts:
    2
    Having the same issue where no decals are showing in scene view but are in the game view.
    Unity 2019.1.0f2 using deferred, Windows 10, Nvidia Geforce GTX 2070
     
  40. mons00n

    mons00n

    Joined:
    Sep 18, 2013
    Posts:
    224
    Just picked up Decalicious and am having some real performance problems in scene view any time a Decal component is added to any object (even without a material added). The scene basically pauses for 1-2 seconds every second making it impossible to use the scene view unless you remove the Decal component or disable the MeshRenderer on that object. Anyone else run into something similar? Unity 2018.3.13f1 on MacOS.

    (ugh this was my fault. someone ended up with having 2 game tabs open)
     
    Last edited: May 3, 2019
  41. Radu392

    Radu392

    Joined:
    Jan 6, 2016
    Posts:
    47
    Anyone found a way to limit decals to a terrain only?
     
  42. kavika

    kavika

    Joined:
    Feb 23, 2017
    Posts:
    4
    Any progress on on the per-frame allocation stuff? I grabbed the latest update and didn't see any changes in the code that was causing the issue.

    Let me know if I can clarify the problem or the solutions I came up with any further.

    I'm probably going to just end up doing hacks on my end to fix it, so no big deal for me. But it's probably a good thing to resolve for your game and for people using this library.
     
    SaltyMaia and angrypenguin like this.
  43. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    12,039
    I grabbed Decalicious recently as I need to draw interactive areas on an instanced terrain. Drag and drop and it's working - neat!

    I do have two questions, though.
    1. As Radu392 asked, is there a way to limit this to only terrain? Ideally a layer based system would be great, but from what I understand that might not be feasible with the way deferred decals work.

    2. Have you tested with MicroSplat, by any chance? The shader generally works, but there are patches where the decal doesn't show on the terrain, as pictured here below. The blue is the decal, and should be a consistent fat line.
    upload_2019-5-17_15-2-11.png
     
  44. SF_futurlab

    SF_futurlab

    Joined:
    Feb 4, 2016
    Posts:
    9
    Hi, I'm also not seeing decals in the scene view with 2019.1.1f1 (seeing them in game view - all cameras and settings set to deferred, Windows10, gtx1070). Any acknolegment of this issue would be appreciated.
     
  45. Manul_

    Manul_

    Joined:
    Jul 28, 2015
    Posts:
    12
    @angrypenguin @Radu392
    Well I found a way to limit the decals to the terrain (it is a hacky solution). But as I wrote before it involves changing the decalicious shader and the terrain shader (I have my decals on a microsplat terrain and vegetation studio grass). So if changing these shaders is no problem for you, I can tell you more specifically how to get it running.
     
  46. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    12,039
    @Manul_, sounds reasonable to me. I haven't quite decided exactly how I want this feature to work, so I'm open to options.
     
  47. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    12,039
    So do you get "patchy" looking decals like in my image above?

    I've got some areas where there's more hole than decal. I haven't yet investigated what's causing it, I assume a conflict with one of MicroSplat's features. I'll do some digging when I can.
     
  48. Manul_

    Manul_

    Joined:
    Jul 28, 2015
    Posts:
    12
    @angrypenguin
    Regarding the patchy look, I guess this happens at very steep parts of the terrain. There is a angle limit parameter on the decalicious shader and it looks at the normal in the g-buffer at this position and clips it away if the angle between decal normal and terrain normal is too big. So for me this issue is fixed if I set the angle limit to -1.
     
    angrypenguin likes this.
  49. Manul_

    Manul_

    Joined:
    Jul 28, 2015
    Posts:
    12
    Decalicious shader on specific materials (e.g Unity Terrain) only:
    Disclaimer:
    - you have to adjust every shader you want your decals on
    - if something else uses the alpha value of RT2 it will not work

    The main idea:
    The alpha value of RT2 of the deferred shading path is unused (https://docs.unity3d.com/Manual/RenderTech-DeferredShading.html) and defaults to a value of 1. So in the terrain shader and grass shader where I want the deferred decals I set this value to 0. In the decal shader I then check this value and only draw if the value is zero.

    Adjusting the decalicious defered decal shader
    1. in line 71 after "// Get normal from GBuffer" change
      float3 gbuffer_normal = ...
      to
      float4 gbuffer_normal = ...
    2. in the following line add
      clip(gbuffer_normal.w > 0.9 ? -1 : 1);
      this will clip away everything with the default RT2 normal value.
    3. Repeat step 1 and step 2 for the second pass (~ line 116)
    4. In line ~87 change
      color *= float4(ShadeSH9(float4(gbuffer_normal, ...
      to
      color *= float4(ShadeSH9(float4(gbuffer_normal.xyz, ...
      because gbuffer_normal is now a float4 but we only want to take the float3 here.

    That's it for the decalicious shader.

    Adjusting a surface shader to have decals shown on it
    1. Click on the shader you want to modify in your project
    2. In the inspector click on "Show generated code" (after "surface shader")
    3. copy the generated code and paste it into your shader file (overwrite the existing stuff in the original shader file)
    4. search for "// call lighting function to output g-buffer" in the shader file
    5. every time it occurs add the line
      outGBuffer2.w = 0;
      after the line
      outEmission = ...
      which is after the comment
    You are done - it should work now :)

    With microsplat it is the MicroSplat*_Base shaders that you want to modify. (you have to do this every time you modify the shader by enabling or disabling a microsplat feature)

    If anything is unclear or misleading in this instruction just ask me :)

    Things you could do:
    • you can have a decalicious shader that only shows on these specific materials and annother one that shows everywhere (but you will have to modify the decalicious renderer to render both shaders and the decal script so that it detects that both shaders are decalicious deferred shaders)
    • I guess you can have the clip value as a property of the shader and then have multiple layers that tell on which material which decals should appear, but I did not test this.

    Greetings Manuel
     
    Radu392, Larzarus and angrypenguin like this.
  50. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    12,039
    This makes sense, I'll give that a go!

    It happens in geometrically flat areas, but I didn't think of the normal map.