Search Unity

Decal System

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

  1. jeffries7

    jeffries7

    Joined:
    Jun 25, 2014
    Posts:
    59
    Hey Dantus,

    Love the Decal system, however i've got a script that allows the user the upload they're own image and manipulate it at runtime. The issue is that I can't add the script to Decals Mesh Renderer, any thoughts?
     
  2. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    You are not supposed to access the DecalsMeshRenderer at all. Every DS_Decals instance is using a material. You have to replace the texture in that material in order to modify it. Maybe you need to set the material again in there. But that should already work.
     
  3. jeffries7

    jeffries7

    Joined:
    Jun 25, 2014
    Posts:
    59
    Thanks for the quick reply, I am modifying the material's texture which in turn changes everything with that material, everything except the Decal.
     
  4. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    You probably picked the wrong material if everything changed but the one from the decals. You can get the material using the CurrentMaterial property of the DS_Decals instance. If you modify the material and it doesn't show up, try to assign it to the property and check if that works.
     
  5. Berandas

    Berandas

    Joined:
    Jan 4, 2013
    Posts:
    15
    Hello.
    Is it possible to create a separate mesh per Decal Projector?
    In my project I'm using decals on a spaceship part, when that ship part gets damaged it changes it's mesh and the decal is then floating in the air. But since all the decals on the spaceship are as one mesh, I can't disable it. It would be handy if I could disable the one particular decal mesh only.
    Is there any solution for this, other than having whole separate decal system for every single decal?
     
  6. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    An alternative you have besides creating a decal system for each projector would be to generate the decal system at runtime and then remove the projectors when needed.

    Or you may create a script that stores the mesh indices per projector. This script may be used to trigger that the decal's mesh is updated in the editor and then takes all the mesh index information it needs and stores them. At runtime, you may then disable the Decal System and modify it's mesh directly. In order to make some parts invisible, you may e.g. move all the relevant vertices to the origin or give them a transparent color in the case that you are using vertex colors. It would certainly be possible to remove those vertices directly and adjust all the triangle indices accordingly.
    This approach would certainly require you to implement a special solution on your own and as far as I can see, you would likely need the Decal System Pro in order to be able to modify the mesh data directly. If you have questions regarding that solution, I would certainly do my best to answer them.
     
  7. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I would like to inform everyone, that the free version of the Decal System will disappear. Everyone who is interested should get it as long as it is freely available.

    Edit: We expect a removal within the next few days.
     
    Last edited: Jul 23, 2014
  8. Draco18s

    Draco18s

    Joined:
    Aug 15, 2011
    Posts:
    110
    Hmm. Having some trouble programmatically displaying two projectors over the same area.

    Code (csharp):
    1.     point = BuiltTower.transform.position + BuiltTower.transform.forward * (t.range/2);
    2.     point.y += 5;
    3.     decalProjectorLine.position = point;
    4.     point = BuiltTower.transform.rotation.eulerAngles;
    5.     point.y -= 90;
    6.     decalProjectorLine.rotation.eulerAngles = point;
    7.     decalProjectorLine.scale = new Vector3(t.range,10,t.width);
    8.    
    9.     point = BuiltTower.transform.position;
    10.     point.y += 5;
    11.     decalProjectorCirc.position = point;
    12.     point = BuiltTower.transform.rotation.eulerAngles;
    13.     point.y -= 90;
    14.     decalProjectorCirc.rotation.eulerAngles = point;
    15.     decalProjectorCirc.scale = new Vector3(t.range*2,10,t.range*2);
    16.    
    17.     addAllGeometry(decalProjectorCirc,decalProjectorLine);
    18.  
    19. //...
    20.     private void addAllGeometry(DecalProjector p, DecalProjector q) {
    21.         Matrix4x4 l_WorldToMeshMatrix;
    22.         Matrix4x4 l_MeshToWorldMatrix;
    23.         MeshFilter l_MeshCollider;
    24.         Mesh l_Mesh;
    25.         decalsMesh.ClearAll();
    26.         decalsMesh.AddProjector(p); //add both projectors...
    27.         decalsMesh.AddProjector(q); //...only this one renders
    28.         foreach (Transform child in levelGeometry) { //loop adds all world geometry to the decals mesh object
    29.             l_WorldToMeshMatrix = child.worldToLocalMatrix;
    30.             l_MeshToWorldMatrix = child.transform.localToWorldMatrix;
    31.             l_MeshCollider = child.GetComponent<MeshFilter>();
    32.             l_Mesh = l_MeshCollider.sharedMesh;
    33.             decalsMesh.Add (l_Mesh, l_WorldToMeshMatrix, l_MeshToWorldMatrix);
    34.         }
    35.         m_DecalsMeshCutter.CutDecalsPlanes (decalsMesh);
    36.         decalsMesh.OffsetActiveProjectorVertices ();
    37.         decalInstance.UpdateDecalsMeshes (decalsMesh);
    38.     }
    Basically, I have three different projectors, a cone, line, and circle. For one case I want to display both the Line and the Circle (differentiating a tower that is aimed by the player to hit a given area vs. a tower that hits a given area, but can rotate on its own). This code doesn't throw any errors, but will only render the second projector. There's a similar post about this on Page 4, but it doesn't appear to be doing anything different: it's just looping through a set of decals and calling decalsMesh.AddProjector(arr) on each, with only a single mesh object being used (whereas I've got several meshes).
     
  9. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    @Draco18s, there is a misunderstanding with the logic of how the Decal System works. You need to first add a projector, then add all the meshes just for this projector. As you add meshes, they will only be relevant for the last projector that was added! Now you have to call the cutting operation and if you want you can offset the active projector vertices. At this point you are done with the first projector. Now you have to add the second projector, add the meshes and make exactly the same you did with the first one.
    After the computations are done, you certainly need to update the decals mesh in order to visualize everything.

    Hope this helps.
     
  10. Draco18s

    Draco18s

    Joined:
    Aug 15, 2011
    Posts:
    110
    Ah! Ok, yes, a bit of a misunderstanding on how the system works, thanks! Had to rekerjigger a couple other lines (the mesh cutting) but those three lines should have been inside the function anyway.



    Perfect! May need a little tweaking on the decal end of the spectrum so they overlap better (they have their own sets of dashed lines and the non-square aspect ratio of the line is a pain to work with) but it works!
     
  11. eblovam

    eblovam

    Joined:
    Apr 24, 2014
    Posts:
    1
    I do not have time to download the free version 1.5 from Asset Store. Where can I download it? really need to test before buying the paid version. Thank you.
     
  12. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    The free version of the Decal System is not anymore available.
     
  13. konsnos

    konsnos

    Joined:
    Feb 13, 2012
    Posts:
    121
    Hey Dantus,

    Does Decal System supports tiled textures? I would like to scale a border texture in one axis to take up all sides of the map.
     
  14. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Tiling is not supported. Could you explain what your expectations would be?
    I was thinking about that possibility already quite a few times, but never implemented it because I couldn't find a good solution.
     
  15. konsnos

    konsnos

    Joined:
    Feb 13, 2012
    Posts:
    121
    Well, to be honest the result I have doesn't look bad. I took a texture 256x256, added it to the decal. Scaled it to fit my preferred position to the map's width/height, and duplicated the whole decal another 3 times for the rest of the sides of my rectangle map. As I said result looks pretty good since I only have I one-colored texture with transparency to each width sides, and it is easily scaled on its height axis.
    Here is a usage example of Total War : Rome 2
    Case 1: Would a simple color look even better tiled?
    Case 2: If instead of a simple colored texture I had another texture with a shape how would this work?
     
  16. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    For such a case you may consider to use a special shader which has a main texture, the actual decal, and some kind of noisy texture that is blended with the decal texture. The noise texture needs to be tiled depending on the size of the decal projector. Like that you should be able to get comparable results as shown in the picture. The noise texture could be used to influence the transparency and/or the color.
    Let me know if you didn't explain something clear enough.
     
  17. konsnos

    konsnos

    Joined:
    Feb 13, 2012
    Posts:
    121
    Crystal clear. Thanks for the help :)
     
  18. Arterius

    Arterius

    Joined:
    Jun 18, 2013
    Posts:
    14
    Hello, I have been working some with the free decal system and using the examples as a base I got dynamic decal creation to work as I want during runtime. The problem here is that I now have to be able to remove individual projectors/decals. Reading this tread it seems like using vertex colors to hide them would be the way to do that (since the meshes are combined to one mesh I can't really remove a part of the mesh without removing everything right?).

    So this means I would have to get the pro version though, is there any other way it could be done or do you have some suggestions?
     
  19. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    You have two possibilities. You can actually remove them, meaning the vertices will be removed. This approach is demonstrated in the demo scripts, just like adding projectors. Alternatively, you may use vertex colors, which require the Decal System Pro as you already mentioned.
    In both cases it is required that you reconstruct the whole decals instance using a script like the bullet example ones.

    Even another solution would be to store the vertex indices per projector in the editor somehow and then use that at runtime to modify the vertex colors.

    It is not possible to make a suggestion regarding one of those approaches, as it heavily depends on your use case.
     
  20. Arterius

    Arterius

    Joined:
    Jun 18, 2013
    Posts:
    14
    Alright, will look into that first suggestion.

    Thanks for the help :)
     
  21. U7Games

    U7Games

    Joined:
    May 21, 2011
    Posts:
    943
    How good is it for mobile devices?.. i´m developing for android...
     
  22. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    What exactly are you trying to achieve? Do you want to place decals in the editor and just show them at runtime, or is your goal to place decals at runtime?
     
  23. U7Games

    U7Games

    Joined:
    May 21, 2011
    Posts:
    943
    i want them to put in editor and show then in runtime... .. :)
    just want to make dark and dirty some areas..
     
  24. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    The Decal System creates a mesh based on the underlying geometry and batches as many decal projectors together as possible (within the same decals instance). This mesh is shown as any other mesh using a mesh renderer and uses a transparent or cutout shader.
    The performance is identical to a transparent mesh.
     
  25. Arterius

    Arterius

    Joined:
    Jun 18, 2013
    Posts:
    14
    Hi, got another question. Been working a bit on and off with this and think I have a way that works with removing certain projectors. The problem I have is that I need a way to find a projector I want to remove.

    For this let's say there is going to be a object which will have a collider/trigger which should be able to detect projectors it intersects. Does the projectors have anything which I can use to detect them this way, for instance a collider/trigger box?

    Tried adding colliders to projectors on creation but didn't get it to work. Although maybe I just missed something.

    Right now I can't really find something like that. So if you have any suggestions or ideas it would be appreciated.
     
  26. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    The Decal System itself doesn't cover that kind of functionality. A projector just contains the data for the size and a few more things. If it comes to intersections and related functionality, you will most likely be more successful to use Unity's physics engine with colliders and triggers. If you explain the approach more detailed, I'll do my best to help you. It looks like the most valuable approach in my opinion.
     
  27. Arterius

    Arterius

    Joined:
    Jun 18, 2013
    Posts:
    14
    Sorry for the late reply, hasn't had much time latelly to really work on this.

    Yeah, using colliders&Triggers seems like the best way to go about it, but so far I havn't found a good way to attach them to either a projector or a decalmesh at runtime. Would be easy if they had a unity-transform so I could attach a component.

    When you mean the approach, are you talking about the whole system or just how I'm trying to get the detection to work?

    Right now it uses a DecalSingelton script which containes references to all decals and the scripts that created them (which also can be used to destroy them), this also gives an easy way to control the maximum amount of decals.

    Other than that I'm using a script that places static decals, dynamic objects need a dynamic-decals script in order to recieve decals.

    Right now I can create decals with no problem and I can remove which one I want, the only problem lies in identifying which decal that should be removed. For this project it can be a mesh which covers a collider/trigger which should detect the decal and then message the decal singelton to remove it.

    Just need to find a good way to attach a collider or trigger the the decal instance when it's created.

    Did overview of the system help or did you feel that I missed something?
     
  28. Arterius

    Arterius

    Joined:
    Jun 18, 2013
    Posts:
    14
    Currently have an idea about linking decals implicitly by creating a spherecollider along with the decal and save it with the decal in a dictionary in the singleton. And when that trigger activates it means that decal should be removed. Will have to elaborate on it later but that's the gist of it.
     
  29. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    You didn't miss anything. That kind of functionality is not built in. I believe that you found a workable solution using a dictionary. Let me know if you have further questions.
     
  30. nwsx

    nwsx

    Joined:
    Apr 12, 2013
    Posts:
    11
    Hi, I'am making an isometric game in which walls become transparent when character gets behind them.

    Of course decals located on transparent wall should also become transparent.

    I got decals pro to use vertex color, but the problem is I can't update vertex color without reference to "DecalMesh"

    It's seems I'am only able to get DecalMesh for projectors created at runtime,
    but how do I get DecalMesh reference for projectors which have been added in the editor without recreating the mesh?
     
  31. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    In general, it is necessary to recreate the DecalMesh at runtime.

    However, in your case, you might store the indices for each projector individually, which would give you the possibility to change the vertex color of the mesh directly. Right now, I don't have the time for a closer look, but will do it within this week.
     
  32. nwsx

    nwsx

    Joined:
    Apr 12, 2013
    Posts:
    11
    Yep, it worked well. Thanks for advice.
     
  33. angelodelvecchio

    angelodelvecchio

    Joined:
    Nov 15, 2012
    Posts:
    170
    Please friends, any possible demo or tutorial on how to make decals working in realtime for simulating blood in skin meshes ?

    Many thanks
     
  34. konsnos

    konsnos

    Joined:
    Feb 13, 2012
    Posts:
    121
    I'm not sure Decal System is optimal for this use, especially if used excessively. Why not have another material with blood spatters on it?
     
  35. angelodelvecchio

    angelodelvecchio

    Joined:
    Nov 15, 2012
    Posts:
    170
    Thank you for answering konsnos!, well, i dont know, do you have a better solution to share?

    I would like to paint the Main Character and a monster with blood once the character hits the monster, or the monster hits the character.

    Many thanks
     
  36. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    The Decal System comes with a demo script for skinned decals. It uses bullet decals for demonstration purposes, but those could easily be replaced with blood. Though there is no support for flow. If you want that, you have to create a custom shader for it.
     
    Last edited: Oct 17, 2014
  37. angelodelvecchio

    angelodelvecchio

    Joined:
    Nov 15, 2012
    Posts:
    170
    Many thanks for your time dantus, i got some red erros on the demo, so I guess i missed that, i will create a new project and try again!
    Many thanks once again!
     
  38. paynechu

    paynechu

    Joined:
    Nov 9, 2009
    Posts:
    10
    Hi, thanks for the nice plugins,
    Could I use this plugins for the Character shadows and Selection indicator?
    That mean the Decal need to base on character's real time location to update the decal projectors.
    Do any one tested with this kind of usage?
    Thanks.
     
  39. paynechu

    paynechu

    Joined:
    Nov 9, 2009
    Posts:
    10
    Hi, Im playing around the Decal System not Pro.
    But I got a lot of error "m_IsStreamMapped[stream]"
    Will it the same in the Pro version ?
     
  40. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    If you have to update a projector in every frame, it is usually better to use a Unity projector. Updating a decal projector is a relatively expensive operation. If it needs to be done in every frame, it is usually too slow.
     
  41. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    What exactly are you doing? How can I reproduce the issue?
     
  42. paynechu

    paynechu

    Joined:
    Nov 9, 2009
    Posts:
    10
    I just created a new project with Decal System 1.5. then try to follow the Reference.pdf.
    But just keep throwing error and nothing projected.
    My Unity is 4.5.5f1
     
  43. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Could you try to open one of the demo scenes and check out whether they work?

    The error message is very confusing and I have never seen it before. Could you tell me what the very first error message is? Is it the same one? Which operating system are you using?
     
  44. paynechu

    paynechu

    Joined:
    Nov 9, 2009
    Posts:
    10
    Im using MacOSX 10.9.5
    Im tried with all demo only the last two (Not Pro) having the same error.
     
  45. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I will try to reproduce it. Could you post the complete error message please.

    Edit: Just for your information. The error message is not directly from the Decal System. I fear it is a Unity bug that only occurs under certain circumstances:
    http://forum.unity3d.com/threads/upgrade-issues.191951/
     
  46. paynechu

    paynechu

    Joined:
    Nov 9, 2009
    Posts:
    10
  47. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
  48. blaher

    blaher

    Joined:
    Oct 21, 2013
    Posts:
    80
    I just tried the simple decal system to see how it works and a couple questions/issues I ran into:

    1. When LCtrl clicking an object for projector placement, the projector moves to center on where I click but the object is not added to effected objects and mesh is set to none. object was a simple cube

    2. I tried using it with a quad as I am doing a mix of 2d/3d and it seems to completely ignore LCtrl click on it.

    Any idea why #1 is happening and if #2 is supported w the pro version?
     
  49. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I am not sure what exactly you are doing, could you make a screenshot?
     
  50. reptilebeats

    reptilebeats

    Joined:
    Apr 28, 2012
    Posts:
    272
    hey i was wandering if there was a way to blend the decal with the targets diffuse channel, possible from using vertex color or from using a mask which would be a lot better.