Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Decal System

Discussion in 'Assets and Asset Store' started by Dantus, Jun 29, 2012.

  1. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    Thanks for the positive attitude, Dantus. For this, you get my money (and also because I've been using your system for more than a month and so far it seems rock solid).

    As far as selection goes, I've gotten used to click on the nice little "D" icon/gizmo to select a decal, which is really practical and precise. I really hope you can find a way to make the render mesh unselectable! :)
     
  2. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Oh man! I haven't though about the "D". The mesh can certainly be made unselectable with that in mind. I'll see what I can do for the next release.
    Thanks for the donation!
     
  3. vegenarie

    vegenarie

    Joined:
    Jan 5, 2011
    Posts:
    287
    Just found this thread. I am trying to learn how to make decals, i can make very nice decals with plain surfaces like planes but i would like to know how to make the decal follow the surface of a wall with bumped shader or follow irregular shapes. I tried with proyectors using decal shader but it just repeats the texture all along the wall it hits and color is not the same as the texture.
     
  4. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    @vegenarie, just read the very first post of this thread. The Decal System is available in the Unity Asset Store for free, you just need to download it. There are also several video tutorials that describe how to use it.
     
  5. vegenarie

    vegenarie

    Joined:
    Jan 5, 2011
    Posts:
    287
    I know its free, just would like to know how to do it myself, just poiting me the direction, some guidelines about how to do it.
     
  6. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Not sure what you mean. Would you like to know how to use it? Then watch the video tutorials. Or would you like to know how it is implemented?
     
  7. Karmarama

    Karmarama

    Joined:
    Jul 11, 2011
    Posts:
    261
    Thanks for the update about the smoothing, I guess that leaves me to modifying the shaders a little more and setting up colliders decently.

    I think he's asking how you made the decal system, it is rather interesting. It seems like you're using a projector for the application, but then it morphs or modifies itself to the below surface it projects onto with a new mesh. Quite different to a flat plane raycast or unity's typical projector.
     
  8. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Thanks Karmarama.
    It works indeed differently. The Decal System takes all the affected meshes, cuts everything away that is outside of the projector area and then computes the uv coordinates for the remaining part.
     
  9. ddeaco

    ddeaco

    Joined:
    Jan 17, 2012
    Posts:
    44
    Is it possible to get a Decal to fade out, based on its distance from the surface its being projected on?

    I'm asking as I think its might work well as a simple shadowing solution.

    Thanks.
     
  10. Zozo2099

    Zozo2099

    Joined:
    Jul 15, 2012
    Posts:
    478
    Can I know if it is compatible with Unity 4? Thanks
     
  11. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    You can fade decals by using the vertex color of the mesh. There is a colored bullet example scene that demonstrates how to use them.
    Though, in general it is probably not the best decision to use decals for shadows. It may use for some special scenarios, but I personally would try to find another solution.
     
  12. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Yes.
     
  13. MCHammond

    MCHammond

    Joined:
    May 15, 2009
    Posts:
    74

    I am used this decal system to do something similar.

    You can fade out a Decal by creating a texture atlas with a few different steps of fade and then use the UV Offset and Scale to control the fade.

    In the end though the solution I went for was to use a liner light with a shadow shaped cookie cutter above my character. I then created a shader that converts the light hitting it to alpha and set the color of the materiel to black. It was a draw call for every character though :(
     
  14. vegenarie

    vegenarie

    Joined:
    Jan 5, 2011
    Posts:
    287
    I mean how to script it, i am not using proyectors but planes and i am using a wall with a bumped specular shader and a decal with transparent bumped specular but they dont fit, and i would like to know how to make them fit. I know i could use just a diffuse shader but the look doesnt seem as convincing to me.

    Also i am wondering how this can be done with decals http://blog.wolfire.com/2008/10/first-blood-part-2/, a mesh using an animation ?
     
  15. spectrum7

    spectrum7

    Joined:
    Dec 24, 2012
    Posts:
    2
    Hey Dantus,

    Im having huge impact on cpu with the single decal system that is on a dynamic object with a custom 2pass shader. Its 100-200ms sometimes and its not affordable at all. I beleive the probem is where the script has to run 5-6 times per update to spawn the decals at the hitpoints. Is there anything I can do to help it? Maybe use second mesh without cutting it and just project the decals on the surface?
     
  16. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    It should be possible to match every decal shader with the underlying surface. You can setup the projection mode and specify where the uv data should come from, how the tangents and normals need to be computed. If the shader is not too special, you should get it to work.

    I don't know how they achieve the animation. I know this could be achieved with a uv animation, but I have never tested it.
     
  17. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Welcome to the forum!

    It is not possible to leave any steps in the decal computation process away, because the result would be totally wrong. I don't know the context enough to help you to optimize it.
    If there are only few objects, you may think about caching the vertex/normal,... whatever data is needed and pass it directly.
    A heavy usage of static batching doesn't help the Decal System's performance as well. There is a lot more geometry than needed that has to be cut away. An option here would be to still have the original meshes, but just for the Decal System. This certainly needs quite some runtime memory.
    If you remove all the projectors, make sure that you always remove the last one!

    Other than that, you may think about using Unity's projectors. They are probably better suited to your situation.
     
  18. spectrum7

    spectrum7

    Joined:
    Dec 24, 2012
    Posts:
    2
    Thank you, Dantus.

    The scene is an example of a gun array firing at the target. Its quite heavy already and Im fighting with everything that is eating cpu time. Theres a lot of FX going on at the impact time tho everything is instantiated from the object pool. Your decal system would be a great solution for my project, and what I love is that its the single mesh calculated and expanded which makes all the decals look correct (Im using animated decals 2 passes multiply and add in my shader). However the Bootcamp example is much faster but its spawning the meshes for each decal and what Ive noticed is the mesh reordering at extreme camera angle...

    Caching the mesh data sounds good and processing the impacts with some time separation hopefully will reduce the cpu time.

    And yes, thanks for your reply.
     
  19. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I am aware that the Decal System is slightly slower than the Bootcamp solution. I constantly compared the performance and in general it should nearly match the one from the Bootcamp example. What may happen is that the very first decal projections have some overhead due to memory allocations. But other than that, I am not aware that the Decal System is much slower. If you have some reproducible example, I would be very interested to find the reason and improve the Decal System accordingly if possible.
    Just for the completeness: The Decal System is slightly slower when the projectors are computed because it is a generic solution that is highly configurable. Further all projectors are combined into one mesh, which improves the performance in general, but has a slightly negative effect as a new projector is added.
     
  20. Kariesschutz

    Kariesschutz

    Joined:
    Jan 9, 2013
    Posts:
    1
    Thank for your work first of all on this great tool!
    I followed your introduction video and had been able to set some decals on a plane but when I move the camera the decals start to flicker or even disappear for some time. Also when I click "add projector" the big with "D" does not show up like on your video. Anybody got an idea what I'm missing or doing wrong?
     
  21. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    There is a Gizmos folder in the Decal System folder. It's written in the readme file that you need to move that one to the root folder. That should do the trick.
     
  22. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    Hey Dantus, would it be possible to use your system to project decals on the surface of tessellated water? I'm using the AdvancedWater4 system that comes with Unity Pro and the surface of the water is being animated and deformed in real-time. Is there a way to make a decal stick to the surface?

    Thanks,
    Seith
     
  23. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Hi Seith,
    I haven't used or checked Water 4 for some time. As far as I know, it hasn't really changed. If I remember correctly, the animation is shader based and the vertices themselves are all on a plane. That means as a consequence for the Decal System, that you can use it, if you create a specialized shader which offsets the vertices identical to the Water 4 shaders.
    As the mesh vertices are on a plane, you need to make sure for the projection that the projectors are at a position where they hit the actual flat mesh and not the shader offset vertices. This certainly leads to a small incorrectness if the projection is not straight downward and even then there is some small stretching, compared to a precise one. But I imagine that this may be acceptable for lots of potential use cases.
    Hope this helps
     
  24. Ken-T

    Ken-T

    Joined:
    Jun 15, 2012
    Posts:
    19
    I'm generating decals dynamically and everything seems to be working except after about 3 seconds the decals disappear.

    Any ideas? I know this vague, but I'm hoping it something simple.
     
  25. WendygoGames

    WendygoGames

    Joined:
    Dec 11, 2012
    Posts:
    53
    Hey Dantus,
    Gotta say this product is awesome. However sadly it doesn't work in Flash! Unsupported types (dictionary lists I believe, or something like that). Do you plan on making this flash-able? Because I would pay this instant for a decal system that works in Flash.
    Thanks, Brandon.
     
  26. Ken-T

    Ken-T

    Joined:
    Jun 15, 2012
    Posts:
    19
    Never mind, the capsule container was falling off the mesh after the collision and taking the decal with it.
     
  27. dannykario

    dannykario

    Joined:
    Jul 28, 2012
    Posts:
    10
    Hi,

    short q - Is it possible to use the decal system with unity4 and flash export ?
    I got some errors on the terrain object, fixed them, but now I get:
    Internal compiler error: Could not load type 'UnityEngine.Terrain' from assembly 'UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'..
    (I dont need and there is no terrain support for flash, of course)

    Any ideas ?
    thanks best
    danny
     
  28. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    @Ken T, thanks for telling you found the solution on your own.

    @Straight Rainbox and dannykario, the Decal System does not work with Flash. I made the required changes some time ago, for testing. As the Flash compilation is very limited, some fundamental changes had to be made. Even if it worked, the performance was unacceptable slow and the shader would have to be rewritten from scratch. Long story short: It does not work and no support is planned as long as the Mono -> AS compilation is not more advanced.
     
  29. WendygoGames

    WendygoGames

    Joined:
    Dec 11, 2012
    Posts:
    53
    Darn. Ok, thanks for the quick reply there Dantus :)
     
  30. vegenarie

    vegenarie

    Joined:
    Jan 5, 2011
    Posts:
    287
    I have problems with this system, when i place it over the floor it works fine but when i put the decal over a wall it just show lines of a color similar to the texture of the projector, like a bar code.

    Also i am wondering if there is a way to make a decal over a wall with a door and when the door opens the part of the decal over the door moves with the door.
     
  31. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Please check this post: http://forum.unity3d.com/threads/141792-Decal-System?p=1086258&viewfull=1#post1086258
    This kind of issue can usually be resolved by increasing the offset of the shader. You may try that out. Otherwise it would be useful to get some more information, like which shader that is being used for the wall.
     
  32. vegenarie

    vegenarie

    Joined:
    Jan 5, 2011
    Posts:
    287
    I will try that

    About the decal over the door and wall, there is any solution?
     
  33. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
  34. vegenarie

    vegenarie

    Joined:
    Jan 5, 2011
    Posts:
    287
    But then if i try for instance an explosion on a door and i want to see the smoke over the door and walls, it wouldnt be very realistic see different decals on wall and on door
     
  35. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    If you are using the same texture atlas, the same uv rectangles for both decals and then place the projector for both decals at the very same position for the time when the decal mesh is computed, in your case when the explosion takes place, it should be just like you want it.
     
  36. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,813
    Not necessarily. You could project two decals in this case - one is static and affects the wall and the other is projected onto the door itself and follows the door. As long as both decals use the same material and are projected from the same position, you won't be able to notice any difference between them.

    EDIT: Dantus beat me to it.
     
  37. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    It was a matter of seconds :)
     
  38. vegenarie

    vegenarie

    Joined:
    Jan 5, 2011
    Posts:
    287
    Dantus and PhobicGunner, if i guess you mean that i should put 2 decals but one disabled cause if both are enabled i would see double, when i open the door enable the one in door, but when door is completely open the decal on it would project over the wall which is behind the door once opened.
     
  39. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    You can have the door and the wall on different layers and take care that the projector only affects the one it needs to, in the case that you set it up in the editor. At runtime you have full control over it in any way.
     
  40. vegenarie

    vegenarie

    Joined:
    Jan 5, 2011
    Posts:
    287
    Ah, yes, forgot layers. I will try what you both told me, many thanks.
     
  41. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    You're welcome. Let me know how it turned out.
     
  42. vegenarie

    vegenarie

    Joined:
    Jan 5, 2011
    Posts:
    287
    About my other problem with decal system is the images seen as bar code on wall, i am using bumped diffuse on walls and diffuse on door, and i cant see them properly in any of them.
     
  43. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I tried to reproduce to issue, but didn't get your described effect. Can you post a reproduction here?
     
  44. vegenarie

    vegenarie

    Joined:
    Jan 5, 2011
    Posts:
    287
    I am not in the computer where i have Unity installed now, but decal works fine when i put it on ground and not in walls, i think there is no difference but maybe the tiling in the bump texture.
     
  45. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,813
    It could be that your decal is casting parallel to the wall. Try setting the minimum angle to something a little smaller than 90 (it won't fix the streaking, it will just not cast on the wall if the decal is parallel)
     
  46. vegenarie

    vegenarie

    Joined:
    Jan 5, 2011
    Posts:
    287
    Yes, the decal is parallel to the wall, but what is the problem with that
     
  47. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,813
    This is actually a very common problem in games, it's how projectors work in general.
    Think of it this way: if you were to stick an orthographic camera in your scene and point it straight down, you would not be able to see the sides of the wall because they perfectly align with the direction of the camera (akin to looking at a sheet of paper edge-on)
    Similarly, the decal projector cannot "see" the wall if it's pointing straight down, or rather the entire height of the wall maps to the same pixel space (causing those streaks)
    The solution is to make sure the decal ignores the wall (last I checked, in this decal framework you could specify a maximum angle, anything less than 90 degrees should work, try 80 degrees for example), other than that you can't really fix the streaking (nearly all decal systems suffer from the same issue, I've even seen it in AAA games)
     
  48. vegenarie

    vegenarie

    Joined:
    Jan 5, 2011
    Posts:
    287
    Thanks, i see the problem now
     
  49. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    @PhobicGunner: Thanks!
     
  50. mrbdrm

    mrbdrm

    Joined:
    Mar 22, 2009
    Posts:
    510
    do we must use atlas for the decals ? i want to use single texture for every decal i have.