Search Unity

[RELEASED] Dynamic Decals

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

  1. gonzalitosk8

    gonzalitosk8

    Joined:
    Jun 30, 2013
    Posts:
    31
    the secret I use for the txt inside the decal is the following:
    I instantiate a transparent texture, and as a child, I create a TextMesh.
    the scale of the textmesh has to be adapted to the total widt of the decal (you will have to make your own conclusion).
    You will also have to separate it 2 centimeters to simulate the effect.
    good luck on your code!
     
  2. DanielDickinson

    DanielDickinson

    Joined:
    Aug 4, 2013
    Posts:
    278
    Alternatively, why not have all the numbers you plan on using in a texture atlas, model a few quads over where the numbers would show up & sample the numbers you need by changing the sample offset.

    This way you get the numbers deforming with the skinned mesh correctly. A projection will never accomplish that perfectly, & may look off when the characters shoulder blades move.
     
  3. EFFalcon2

    EFFalcon2

    Joined:
    Apr 28, 2014
    Posts:
    17
    Does anyone know if using the Material masking, can it be done at runtime?
     
  4. clownhunter

    clownhunter

    Joined:
    May 26, 2013
    Posts:
    59
    You can control masking with the instanced properties of the projection renderer.
     
  5. Recon03

    Recon03

    Joined:
    Aug 5, 2013
    Posts:
    845
    Thanks for making this Open and allowing someone to add it to GIT, this has been helpful, I used your asset since you released.
     
  6. LandePlage

    LandePlage

    Joined:
    May 21, 2016
    Posts:
    33
    I'm having some trouble where some of my particles are always renderered behind the decals. Does anyone know what might cause this? I've tried a bunch of different settings for ZWrite, Queue tag, RenderType tag - both on the particles shader and on the decal shaders. I'm not an expert on shaders, so not sure how one might go about fixing this.

    If I switch the main camera to "Deferred" rendering, it gets fixed - but I'd prefer to use forward rendering.

    Other than this issue, I'm super happy with this asset. Seems really cool.

     
  7. DanielDickinson

    DanielDickinson

    Joined:
    Aug 4, 2013
    Posts:
    278
    It's been so long since I've touched this but I might be able to point you in the right direction. In forward rendering I was using a custom pass to render everything into depth/normal buffers. The decals then used this as you would the GBuffers for traditional Deferred Decals.

    It looks like the particles, for whatever reason, aren't being picked up & rendered into this pass, so are being ignored. The decals are rendered before transparent objects though. So you could have the particles use a transparent shader, or even just render them in the transparent queue with a custom shader & an alpha of 1. This may present sorting issues though.

    Alternatively you could investigate why the particles aren't being drawn in the shader replacement pass. I remember having issues with vertex displacement not being rendered into this correctly. (Shader in shader replacement pass would have no knowledge of this).
     
  8. StarTwinkle

    StarTwinkle

    Joined:
    Jul 13, 2015
    Posts:
    13
    It looks like the asset does not work on android devices.
    The application crashes immediately after launch.
    I tried different versions of Unity and different devices. The result is the same, application crash.

    2022-05-05 11:51:31.807 8445-8551/? E/Unity: Missing Vulkan framebuffer attachment image?
    (Filename: Line: 0)
    2022-05-05 11:51:31.830 8445-8551/? E/CRASH: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
    2022-05-05 11:51:31.830 8445-8551/? E/CRASH: Version '2019.4.12f1 (225e826a680e)', Build type 'Release', Scripting Backend 'mono', CPU 'armeabi-v7a'
    2022-05-05 11:51:31.830 8445-8551/? E/CRASH: Build fingerprint: 'POCO/vayu_tr/vayu:11/RKQ1.200826.002/V12.5.4.0.RJUTRXM:user/release-keys'
    2022-05-05 11:51:31.830 8445-8551/? E/CRASH: Revision: '0'
    2022-05-05 11:51:31.830 8445-8551/? E/CRASH: ABI: 'arm'
    2022-05-05 11:51:31.830 8445-8551/? E/CRASH: Timestamp: 2022-05-05 11:51:31+0300
    2022-05-05 11:51:31.830 8445-8551/? E/CRASH: pid: 8445, tid: 8551, name: UnityGfxDeviceW >>> com.LlockhamIndustries.DynamicDecals <<<
    2022-05-05 11:51:31.830 8445-8551/? E/CRASH: uid: 10320
    2022-05-05 11:51:31.830 8445-8551/? E/CRASH: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x1b8
    2022-05-05 11:51:31.830 8445-8551/? E/CRASH: Cause: null pointer dereference
    2022-05-05 11:51:31.830 8445-8551/? E/CRASH: r0 00000000 r1 b69d5020 r2 b2859400 r3 eec37390
    2022-05-05 11:51:31.830 8445-8551/? E/CRASH: r4 00000003 r5 00000001 r6 00000000 r7 00000000
    2022-05-05 11:51:31.830 8445-8551/? E/CRASH: r8 00000004 r9 b99f5b18 r10 00000227 r11 ce5c0270
    2022-05-05 11:51:31.830 8445-8551/? E/CRASH: ip 00000000 sp b99f5970 lr 00000000 pc bb9ae816
    2022-05-05 11:51:31.830 8445-8551/? E/CRASH: backtrace:
    2022-05-05 11:51:31.830 8445-8551/? E/CRASH: #00 pc 000a0816 /vendor/lib/hw/vulkan.adreno.so (BuildId: 9d8956fe85e6c3248f5d4c200274d111)
    2022-05-05 11:51:31.830 8445-8551/? E/CRASH: #01 pc 0002cc12 [anon:libc_malloc]

    Any suggestions to fix it?
     
    socialtrens likes this.
  9. YagirX

    YagirX

    Joined:
    Jan 16, 2016
    Posts:
    15
    I confirm. I have the same problem.
     
  10. Recon03

    Recon03

    Joined:
    Aug 5, 2013
    Posts:
    845
    It did work for it, I used it in the early days, of the plugin, and used it mostly for mobile. Did you check the crash log to see what error it is??
     
  11. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    First of all thanks for the awesome and free decal solution!

    May I know why you decided to not use unity's Depth and DepthNormal textures?
    These replacement shaders consume quite a bit. In my case, it uses ~1600 drawcalls out of 6100 total.
    For example:
    upload_2022-7-30_18-18-1.png
    I'm using various image effects that require unity to generate both Depth and DepthNormal textures.
    So basically, I'm drawing the same depth texture 3 times, and the normals texture 2 times. o_O

    I'm wondering if is it possible to use unity's textures instead of buffers generated by the replacement shaders to draw decals.

    UPD
    Looks like Shader Method - Mobile does what I'm looking for.

    UPD 2
    I changed Projection.cginc DepthNormalMask method to use PrecisionDepth for mobile. With low precision depth from unity's DepthNormal texture, there are some artifacts. And since I need high precision depth texture anyway, I could use it also for decals.
     
    Last edited: Jul 30, 2022
  12. DanielDickinson

    DanielDickinson

    Joined:
    Aug 4, 2013
    Posts:
    278
    It's been so long since I've touched this, but the primary reason was the precision of the combined depth-normal* buffer. The low-precision normals create "banding" on rounded surfaces & the low precision depth could create depth artefacts when the cameras far plane was set higher than standard (ie. in the scene-view).

    Using my own shaderpass also allowed me to draw objects into a "Mask" buffer, to allow object masking, a solution Unity is now using for it's rendering & decal layers. By writing to multiple target buffers you can render all 3 of these within a single drawcall/pass. So if you're using decal layers you may as well use high-precision depth/normals as they are basically free.
     
  13. Maria_Tonia

    Maria_Tonia

    Joined:
    Feb 28, 2019
    Posts:
    36
    Great asset, exactly what i need. But how can i install the package? The link to asset store is broken, install via Git or from local file doesn't work either. Or is the way to go just to copy the contents to my project directory? Thx!
     
  14. DanielDickinson

    DanielDickinson

    Joined:
    Aug 4, 2013
    Posts:
    278
    Hey, you should be able to just drag all the files from the git repo into where ever you like in your project's asset folder. No special install process required. I intentionally left everything as basic scripts in Unity so it could be easily modded. I don't think the hosted git repo is set up to work with the package manager either, though I may be wrong.
     
    Maria_Tonia likes this.
  15. clownhunter

    clownhunter

    Joined:
    May 26, 2013
    Posts:
    59
    Sorry, the git repo isn't setup correctly for installing packages from git. I'll try to get that updated. For now, you can download the latest .unitypackage from here: https://github.com/EricFreeman/DynamicDecals/releases/tag/2.0.5
     
    Maria_Tonia and DanielDickinson like this.
  16. Maria_Tonia

    Maria_Tonia

    Joined:
    Feb 28, 2019
    Posts:
    36
    Great, it works the manual way (and i love the decals for the build-in-renderpipeline by the way!).
    A direct integration via package would the icing on the cake (also for updates, etc.)!
     
  17. Abnormalia_

    Abnormalia_

    Joined:
    Jul 23, 2013
    Posts:
    128
    Is there a version of this that works on Unity 2021 and the standard pipeline in VR?
     
  18. clownhunter

    clownhunter

    Joined:
    May 26, 2013
    Posts:
    59
    Yes, read the description here for upgrade notes: https://github.com/EricFreeman/DynamicDecals/releases/tag/2.0.5

    Unity switched the namespace from UnityEngine.VR to UnityEngine.XR so it's mostly renaming a few using statements.
     
  19. Abnormalia_

    Abnormalia_

    Joined:
    Jul 23, 2013
    Posts:
    128
    Thanks, it compiled and worked, but only in Stereo rendering mode "Multipass", "Single Pass Instanced" mode gives this.

    upload_2022-10-4_10-29-0.png
     
  20. v2-Ton-Studios

    v2-Ton-Studios

    Joined:
    Jul 18, 2012
    Posts:
    238
    Recently came across this asset / package and was super happy to find a decal solution for the standard/default pipeline!

    However, I cannot see to get masking to work. Using the 'Standard' Shader Method, decals draw on top of everything, regardless of what I see in layers or the rendering pass I use.

    Setup:

    - Unity 2021.3.8f1
    - Windows 11 machine

    Here's what I've tried.

    - Forward and Deferred rendering, makes no different
    - Switching to the 'Mobile' Shader Method gets things to render on the ground (which is what I want) but if I walk into the decal projection 'box / volume' the decal is projected on my character
    - I've set up masking layers for character and terrain and tried to set a decal's masking to 'Only Draw On' = terrain or 'Everything except' = character, neither have any effect on layer masking.
    - IF I choose a masking of 'Only Draw On' and unselect all the layers they I get no decals, which is correct, and shows that masking is working at some level.

    Possible hack:

    - Make the decal have very little depth so that it's nearly impossible for the character to get "inside" it's volume... this might work for footprints and wall decals on perfectly flat ground/walls, but it's definitely not ideal :).

    Any ideas / suggestions? Thanks in advance!
     
  21. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    481
    You can debug mask rendering using Frame Debugger window. It should help to understand what part of decal rendering is broken. On 2020.3 it works fine(almost)
     
  22. socialtrens

    socialtrens

    Joined:
    Oct 23, 2017
    Posts:
    65
    I had the same problem with Android build. I fixed it by disabling Vulkan.

    1. Go to Player Settings
    2. Other Settings
    3. Disable Auto Graphics API
    4. Remove Vulkan from the Graphic APIs list.
    5. Done.
     
    StarTwinkle likes this.
  23. CreatureWithoutSpecies

    CreatureWithoutSpecies

    Joined:
    May 10, 2020
    Posts:
    5
    Can anyone guide a fella on how to modify this wonderful asset to work with an orthographic camera with a scaled projection matrix?

    Background: My project has a 3/4 overhead view. For a while I was scaling and rotating the physical world by sqrt(2) and 45 degrees, respectively. However, this had a lot of undesirable knock-on effects, so I managed to get the exact same worldview by simply scaling the orthographic camera's projection matrix vertically.

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class CameraScale : MonoBehaviour
    4. {
    5.     Camera cam;
    6.     public float height = 1f;
    7.     public float width = 1f;
    8.  
    9.     void Start()
    10.     {
    11.         cam = GetComponent<Camera>();
    12.     }
    13.  
    14.     void Update()
    15.     {
    16.         //stretch view//
    17.         cam.ResetProjectionMatrix();
    18.         var m = cam.projectionMatrix;
    19.  
    20.         m.m11 *= height;
    21.         m.m00 *= width;
    22.         cam.projectionMatrix = m;
    23.     }
    24. }
    This works perfectly, except the Dynamic Decals now "float" and parallax at a different rate than the rest of the world. This doesn't happen if I change the camera from orthographic to perspective.

    Anyway, I'm still something of a beginner in C# (about two years, solely working with Unity), so I was hoping a helpful soul might have some guidance on where/what to tweak to fix this.
     
  24. Maria_Tonia

    Maria_Tonia

    Joined:
    Feb 28, 2019
    Posts:
    36
    In newer Unity Versions (e.g. 2022.2) i get the warning message that PrefabType and GetPrefabType are obsolete. Is there any updated version of DynamicDecals available?
     
  25. Maria_Tonia

    Maria_Tonia

    Joined:
    Feb 28, 2019
    Posts:
    36
    I worked with an unlit and additive decal projection (logos on a spaceship). But when i set the game to night time (lights off), the projections were still visible. Any suggestions? Switching to a partly metallic seemed to work almost, but all the others didnt. Is there a better way?
     
  26. ttttkk

    ttttkk

    Joined:
    Oct 2, 2016
    Posts:
    7
    hi, i hope this post is still active. I implemented one decal in my vr (oculus) scene, but notice that it greatly increase tris even if only one single texture added. Is there any way to optimize it?
     
  27. theBachi

    theBachi

    Joined:
    Jul 23, 2017
    Posts:
    3
    Hi all, is there a way to extend the layer masks for decals, so it can select between more than 4 layers on which to draw on?
     
  28. Maskeowl

    Maskeowl

    Joined:
    Apr 24, 2021
    Posts:
    8
    hi i need help with blood decal i wwannto make it random sprite so i need to projector.albedo. sprite = random.mysprites[] bbut i cant make projector.albedo how i can reach albode do you lnow ?
     
  29. CreatureWithoutSpecies

    CreatureWithoutSpecies

    Joined:
    May 10, 2020
    Posts:
    5
    What I did was make as many prefabs as I had sprites, then create a script for my particle system with a list of all the prefabs, and then instantiate a random one from the list on particle collision. (For efficiency/performance, you'd probably want to create a pool of them to pull from rather than constantly instantiate new ones, I just wanted to get it working first.)
     
  30. Max-om

    Max-om

    Joined:
    Aug 9, 2017
    Posts:
    499
    As anyone gotten this to work with Singel pass instanced?
    On multipass it renders fine. But with singel pass instanced its not visible.

    I'm on 2020.3.48 built in rendering and forward.
     
  31. sirleto

    sirleto

    Joined:
    Sep 9, 2019
    Posts:
    145
    i am new to this, trying it from github via https://github.com/EricFreeman/DynamicDecals

    and what i have is aprox 75ish decals on a test spaceship, all in view, and at playtime (in editor, not build) i disable and enable them to see what the performance cost is.

    as one expect the imact on milliseconds/fps is negletable, either we see all or zoom in one one then see those pixels.

    BUT strangely i have this:

    DISABLED
    batches: 62
    tris: 94k
    verts: 138k
    set pass calls: 28
    shadow casters: 32

    ENABLED
    batches: 200
    tris: 126k
    verts: 182k
    setpass calls: 130
    shadow casters: 32

    anybody any idea why 75ish decals will cause 140 draw calls, 102 set pass calls, and a total of 32k triangles !?!?!
    i tried this in two differenr test projects, pretty empty, and in both it results in such a big amount of tris and draw calls.
    why is this?

    ----

    PS: just 1 decal produces this:

    DISABLED
    batches: 62
    tris: 94k
    verts: 138k
    set pass calls: 28
    shadow casters: 32

    ENABLED
    batches: 85
    tris: 125k
    verts: 182k
    set pass calls: 39
    shadow casters: 32

    so just 1 decal will cause 23 draw calls, 11 set pass calls and 30k triangles !?!?!

    PS: this is built in render pipeline with defferred camera, on unty 2021.3 aswell as on 2022.3
     
  32. mgeorgedeveloper

    mgeorgedeveloper

    Joined:
    Jul 10, 2012
    Posts:
    324
    This system will render all game objects that are involved in your decal layers, using a replacement shader. It is building up a mapping of what is visible where in terms of layers.

    This means that if you have only 1 decal, you hit a sort of fixed overhead, but then displaying 1000 decals won't make a lot of difference beyond that.

    Ensure that decal rendering is not enabled for any other cameras (it's been a few years, so I can't remember how this was done.)

    Also ensure you don't use tonnes of different layers (I can't remember exactly if there is a linear relationship between the overhead and the number of decal layers, but I guess so).
     
    hopeful and sirleto like this.
  33. sirleto

    sirleto

    Joined:
    Sep 9, 2019
    Posts:
    145
    perfect reply, thanks.

    i was under the assumption ALL decals do is write into deffered g-buffer ... NOT rerendering existing object geometries.
    i have spaceships with few hundre k of geometry and want to add (at most) a few thousand decals.

    so rendering few thousands of cubes (like small lights, local in their range) seems way more faster than rerendering whole geometry ...

    but atleast i know now how i have to benchmark properly to understand the performance impact.

    thanks a lot for the fast reply, very appreciated <3
    ----

    PS:
    1. does anyone know what rsi is using on star citizen / squadron 42 (abstractly speaking about the rendering)?
    2. does anyone know what easy decals is doing? https://assetstore.unity.com/packages/tools/utilities/easy-decal-22867
    3. does anyone know any other good decal systems / store assets / github or other that can be used in unity (BiRP)?
     
  34. kreso

    kreso

    Joined:
    Sep 7, 2013
    Posts:
    147
    SOLVED:
    WebGL decals work! Yay!

    What fixed it for me was changing the color space:
    Build Settings -> Player Settings -> Other Settings -> Color Space -> Gamma

    P.S. I have tried Dynamic Deals in Unity 2021, 2022, 2023 and it works in all of them.

    It is sad the author abandoned the plugin only because it doesn't work on other pipelines. I use built in pipeline for most of my projects and this plugin works extremely well. And there is no other solution (not even for other pipelines + platforms like Dynamic Decal supports).

    Dynamic Decal rocks!

    ==
    Original post:

    Apologies for going back in time, but this still seems only decal asset that potentially works.
    The WebGL is not rendering decals for me. I can see them in editor and on mobile.
    I did try setting the 'Mobile' shader setting when building WebGL, it did not help.

    I tried fixing this for the past week no success. Luckily I found this thread full of DynamicDecal aficionados :)

    Does it work for WebGL for anyone?

    I'm using Unity 2021.3 if that matters at all.

    Kind regards,
    Kreso
     
    Last edited: Feb 13, 2024
    YagirX likes this.
  35. Sonicboomcolt

    Sonicboomcolt

    Joined:
    Oct 2, 2013
    Posts:
    5
    Now I'm wondering what would be the best way of optimizing the decals. I have been hitting the batch count hard with just three of them in my scene.