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. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Oh, now I understand what you mean. No, this does not work and it is also not planned to be implementation in the near future.
    The Decal System is mesh based, the projectors do not actually project anything. In fact the decal mesh is just extended by the required mesh data to give you the impression of a projection.
    Your proposal is - from a technical point of view - very different, as it does not operate on the mesh level, but on the textures directly.
     
  2. chrisall76

    chrisall76

    Joined:
    May 19, 2012
    Posts:
    667
    I'm doing that in the editor.
     
  3. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    That's easier to explain :)

    I assume you have watched the decal system introduction. The decals instance has to be created in the same way for moving objects as for static ones (Game Object -> Create Other -> Decals). Now, take the created game object and make it a child of your moving object. Go on as described in the introdution, but keep in mind the the projectors should only affect that moving object.

    Hope this helps!
     
  4. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    New video: Decal System projection modes

     
    Last edited: Jul 22, 2012
  5. SuIXo3

    SuIXo3

    Joined:
    Jul 22, 2012
    Posts:
    2
    Hi!
    This is awesome. It's just what I wanted.

    Works perfectly but I have a problem, it does not affect one of my meshes (and so I guess some others wont work either). What could it be? It has the same material as adjacent meshes (with which it works), same everything but it has a collider, which I switched off but still don't work.

    Also sometimes the decal flickers on terrain, mostly when the terrain inclination is very vertical, like mountains and things. By moving the camera the flickering changes and eventually the decal gets set up. But still sometimes it stays hidden, or parts of it.

    Anyways thanks for this, it really is what unity needed, and me xD.
    Between this and the clouds, the next system will have to be awesome ;)
     
  6. Dantus

    Dantus

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

    Are you using Decal System 1.1? The first version had a bug and produced wrong results for negatively scaled meshes. Something else that may produce this result is if the bounding box of the mesh does not match the actual mesh. If you are sure that none of those things causes the issue, it would be awesome if you could send me a reproduction of the issue.

    The flickering on the terrain is due to the built-in LOD switching of the terrain. So far I wasn't able to find a reliable workaround for that, though it has been discussed with a few people.

    Thanks for the feedback!
     
  7. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    One more video: Decal System with dynamic objects

     
  8. sjm-tech

    sjm-tech

    Joined:
    Sep 23, 2010
    Posts:
    733
    Awesome and seem so simple yet so powerful ...I will give a look..thanks!
    Max
     
  9. SuIXo3

    SuIXo3

    Joined:
    Jul 22, 2012
    Posts:
    2
    Well I don't know what version it is. I downloded it from the store in the program. There was just one, and it was yesterday. It should be the latest version.
    And now you say it, I remember scaling down that model, the import was too big. Maybe it's that. Does it has to be updated manually?
     
  10. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    @sjm tech: :)

    @SulXo3: Yes. If you change the meshes or terrain onto which you are projecting decals, you need to update the decals manually. It is very simple though. Select the decals instance or one of the projectors and click "Update All Projectors".
     
  11. seventyfive

    seventyfive

    Joined:
    Jul 20, 2007
    Posts:
    34
    hey dantus –
    some more questions:

    1 how/can i assign a different material instead of a different uv index during runtime?
    2 would it make sense to e.g. mesh combine if a have a certain amount of decals using the same material or does the plugin take care of this already?
    3 would i create different layers by adding new projection groups during runtime?

    hope my questions are clear :)

    thanks in advance!
     
  12. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    You can change the material with the 'CurrentMaterial' property. Under the assumption that m_Decals is your decals instance, you just need to perform:
    Code (csharp):
    1. m_Decals.CurrentMaterial = yourNewMaterial;
    But that certainly changes the material for all the projectors and only makes sense if the new material has the same uv layout.

    This is already made. Instead of creating numerous decals (DS_Decals) with the same material, just create one or a few and each of them with lots of projectors.

    Projector groups have no effect at runtime. They only exist to move a bunch of projectors in the editor to improve the usability.

    Not sure if I understood everything correctly, just ask again if I got you wrong :)
     
  13. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Another video. This one is about lightmapping with decals.

     
  14. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Decal System 1.1.1 is now in the Asset Store.

     
  15. chrisall76

    chrisall76

    Joined:
    May 19, 2012
    Posts:
    667
    I think I'm doing something wrong, just don't know what(ignore the gun, this is a bit of a old test scene with the interactive objects I needed). I could be missing something.
     
  16. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    @chrisall76: Can't watch the video. It is private... :)
     
  17. STARS

    STARS

    Joined:
    Jun 28, 2012
    Posts:
    8
    I watched the video and ur plugin looks awesome but unfortunately I can't download it coz there's no link.

    I can't even open the Asset Store... I get a strange firefox error.
    Could you please provide a direct download link somewhere in your website maybe ? thx
     
    Last edited: Jul 25, 2012
  18. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    @STARS: Welcome to the forum :)

    You need to open the Asset Store in Unity (Window -> Asset Store). In there you need to search for Decal System. Let me know if this does not work for you!
     
  19. STARS

    STARS

    Joined:
    Jun 28, 2012
    Posts:
    8
    Thx Dantus...

    I did it but I failed again.
    the version, size and other stuffs are shown there but no download link..


     
    Last edited: Jul 25, 2012
  20. seventyfive

    seventyfive

    Joined:
    Jul 20, 2007
    Posts:
    34
    hey dantus,
    thanks again for your support! again, two more questions i couldnt resolve:

    if i remove a projector (like in your example with removing the oldest decal if the maximum number is reached) all projectors are only updated if i create a new decal. how can i manually trigger an update so the removed ones disappear?

    when i try to rotate the projector, i fail. maybe i am wrong but i had the assumption, that the projector is facing towards the surface, therefore i would be able to rotate the projector, before generating the decals projector's mesh, around the forward axis of it. e.g. to make decals look more random.
    this one is solved...
     
    Last edited: Jul 25, 2012
  21. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I will pm you a download link. Hopefully you understand that I can not offer support for older Unity versions. So if it does not work, I won't be able to help you.
     
  22. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Yes, that works. Remove the projectors and then update the decals meshes. In the example this is done with:
    Code (csharp):
    1. m_Decals.UpdateDecalsMeshes (m_DecalsMesh);
    It is not the forward axis, but the downward axis! So in the case that you are creating the rotation using euler, it is the y value that needs to be randomized.
     
  23. seventyfive

    seventyfive

    Joined:
    Jul 20, 2007
    Posts:
    34
    perfect! that helped, the euler i just misused ;) now it works perfectly..
     
  24. STARS

    STARS

    Joined:
    Jun 28, 2012
    Posts:
    8
    I understand and I appreciate that.. my Unity version is 3.5 and I'm sure it works. But could u plz tell me where that download button was supposed to be in that given shot ? The download link might be there and the Asset Store page might not have been refreshed well.
    thx

    Edit: and I forgot to mention that I wasn't the only one having the same issue. 10polarbears seems to have the same problem so I recommend you put that link somewhere in ur webpage and also update ur first post for the people who run into the same issue..

    thx again
     
    Last edited: Jul 25, 2012
  25. jgodfrey

    jgodfrey

    Joined:
    Nov 14, 2009
    Posts:
    564
    In your screenshot, do you see the "Needs Unity upgrade to version 3.5.3" message? If you were running the required version, that's right where the download link would be. The asset store has detected that you're not running the minimum required version of Unity, and therefore tells you to upgrade instead of giving you the download link. If you upgrade Unity and open the Asset store page again, you should see the link.

    Jeff
     
  26. STARS

    STARS

    Joined:
    Jun 28, 2012
    Posts:
    8
    Oh yeah. Thank you so much Jeff..

    I'll upgrade my unity and let you know Dantus...
     
  27. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I expected you were using Unity 3.4 or even an older version :) .
     
  28. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Dantus. How difficult would it be for a decal, instead of lightmapping it, to get the uv coords + lightmap of the mesh and use this data so it can adopt to the mesh's lightmap.
     
  29. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    In the editor, it would require a major refactoring. At runtime, it should be doable without too much trouble. You need to make sure that each lightmap has its own decals instance. That will increase the drawcalls, but you get the baked shadows. I never tried that so far, but it sounds really interesting :) . Let me know if you need more details.
     
  30. Receptor

    Receptor

    Joined:
    Mar 24, 2012
    Posts:
    8
    Great work :) Can i instantiate the decal at runtime in game (for bulletmarks or other)? Thanks.
     
  31. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Yes. You can run the demo scenes. It already contains an example.
     
  32. elias_t

    elias_t

    Joined:
    Sep 17, 2010
    Posts:
    1,367
    Thanks Dantus. I don't need this feature right now but I will try to implement it.
     
  33. chrisall76

    chrisall76

    Joined:
    May 19, 2012
    Posts:
    667
    sorry, had the wrong video type
     
  34. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Would be awesome if you keep me updated! I am curious to hear how it worked out. :)
     
  35. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    You answered the question on your own :) . It doesn't matter if you are working with decals in the editor or at runtime. They only work if the decals instances are children of them. You need to change the bullet script to handle rigidbodies differently. The modification of the algorithm would look as follows:

    Dynamic object is hit:
    - Make sure it has its own DS_Decals and a DecalsMesh (maybe with a projectors list) -> (Custom script placed in dynamic objects)
    - Perform all the steps like in BulletExample, but use the decal objects from the dynamic object.
    - ...
     
  36. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    I just downloaded this last night and had a question. Is it possible to place decals on trees? I got it to place on terrain and on meshes, but it didn't seem to work on trees. Trees use the Terrain Collider but I don't think they're part of the terrain mesh, so the example in BulletExample.cs doesn't seem to work, because when it hits the Terrain Collider it tries to create the decal by passing the terrain mesh rather than the tree's. I'm not sure how to access the tree's mesh itself since it's not an actual Mesh Filter object.
     
  37. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    If there's not a way to do it currently, a cheap way to do it might be to have an option to pass in the TerrainCollider instead of the TerrainMesh (like you can pass a MeshCollider instead of a Mesh), then stick the decal on the tree collider. It would be floating in front of the tree and might require some manual tweaking by the user, but that's better than nothing.
     
  38. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Placing decals on trees is not possible for the simple reason that trees can be bended. I am sure there are ways to nearly get it right, but it is unlikely that there is a good and generally usable solution. That's why I haven't included anything in that direction. With the Decal System, I am trying to provide a framework that works in general and without very special cases that may work sometimes and sometimes not (with the exception of skinned meshes :) ). I would love it to have decals on trees, but that is not possible with the current terrain implementation.
     
  39. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    That makes sense. Though personally, I would rather have a way to do it that looks mediocre with a warning in the docs than no way at all. Especially since in many people's cases (including mine), decals will mostly be placed at runtime for things like bullet holes and scorch marks, and won't remain on the screen for that long, so they don't have to be perfect. Unity's trees have been giving me headaches for other reasons though, and I've been thinking about turning off the builtin colliders and using impostor colliders instead, so in that case I could just project a decal onto the impostor collider as if there were a mesh there.
     
  40. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Forgot to mention that I added a note in the documentation, that decals do not work with terrain details, such as grass and trees, thanks to your input!

    The Decal System always performs precise computations. It works based on meshes or terrain data (height map). As such, it is not possible to create a mesh based on colliders, because they have no mesh data, with the exception of mesh colliders. So you may try to use a simple mesh collider as tree collider. Not sure if that is supported by the terrain implementation, but it is worth a try.
     
  41. Emericanized

    Emericanized

    Joined:
    Apr 30, 2010
    Posts:
    23
    Thank you for the redirect from Youtube, this thread has solved most of my problems! I will give the light-mapping video another walkthrough to see if I just made a mistake.
     
  42. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Great you found some answers. If it comes to lightmapping, I personally tend to forget to set the static lightmap flag and make sure that the children also get this setting. Maybe :)
     
  43. Emericanized

    Emericanized

    Joined:
    Apr 30, 2010
    Posts:
    23
    That was my first guess, as i tend to forget stuff like that too! :) My original problem was: even when setting the material type to lightmappedDiffuse, they would not retain unique lighting information. I followed the video againand it works now, so I must have made a user error somewhere along the line!

    When you were demonstrating how cutout shaders interact with realtime lighting, I noticed that in my scene none of the mesh objects (bridge "floor", metal, buildings or terrain) are casting realtime shadows.
    I do have unity pro, and i have toggled off the lightmap. I also made sure my quality settings are max'd.

    When I create a sphere or other primitive it casts a shadow onto the bridge or any other mesh, but none of the existing assets seem to be acting the same way. This is probably unrelated to the decal system, but for the heck of it:
     
  44. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Does toggled off the lightmap mean you have clicked the Clear button in the lightmap window? That' is required.
     
  45. Emericanized

    Emericanized

    Joined:
    Apr 30, 2010
    Posts:
    23
    Bingo, you've just solved months of my avoiding the use of lightmaps! You've certainly earned a donation from this fellow, and as luck would have it I just got paid.

    Thank you for your time,

    You'll probably hear from me again (apologies in advance! :p)
     
  46. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    :)
     
  47. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    Hey, Dantus!
    Is it possible to mimic Unity Projectors using decals projectors in realtime? I mean use decals projectors to imitate some simple shadow, like rect shadow from moving but not rotating cube?
    And would it be less expensive comparing to the Unity Projectors?

    Thanks!
     
  48. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    That's an interesting idea. It may indeed work.
    I expect, it is more expensive than Unity's projectors in general for such a case. But it may pay off if the projected shadow and the objects that are affected by it are not moved in every frame. You need to try it out.
    If you have trouble with the implementaiton, just ask!
     
  49. codestage

    codestage

    Joined:
    Jul 27, 2012
    Posts:
    1,931
    Thanks for your fast answer!
    I've already tried to implement this, but I'm not sure how to update the projectors and re-project textures. Could be nice to know how to scrip something similar to the Update All Projector button does.
     
  50. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    The BulletExample script is a good basis for such a script. Instead of only performing a projection only on mouse click, the computation has to be performed in every frame. At the beginning of every update, you need to clear all the projectors. Create the projector with the needed position, rotation, scale, perform the raycast - you probably need a sphere raycast to get all the affected objects. It is very identical, but certainly needs those adjustements.

    Hope this helps.