Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Decal System

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

  1. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    If I move/copy both DecalSystem.Editor.dll and DecalSystem.Runtime.dll to “Assets/Plugins” and/or “Assets/Plugins/WP8” then build fails with the message:
    Code (csharp):
    1. Error building Player: Exception: Failed to run assembly preprocessor with command line "Temp/StagingArea/Data/Managed\DecalSystem.Editor.dll" -injectCtor -assemblyPath "Temp/StagingArea" -pdb.[Temp/StagingArea/Data/Managed\DecalSystem.Editor.dll]
    2. No symbols for Temp/StagingArea/Data/Managed\DecalSystem.Editor.dll
    3. Injecting ctor
    4. Error while in assembly preprocessor Temp/StagingArea/Data/Managed\DecalSystem.Editor.dll
    5. Failed to resolve assembly: 'UnityEditor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'
    6.    � Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
    7.    � Mono.Cecil.DefaultAssemblyResolver.Resolve(AssemblyNameReference name)
    8.    � Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
    9.    � Mono.Cecil.TypeReference.Resolve()
    10.    � AssemblyPreprocessor.Utils.IsInWhitelist(TypeDefinition definition)
    11.    � AssemblyPreprocessor.Utils.IsInWhitelist(TypeDefinition definition)
    12.    � AssemblyPreprocessor.Utils.IsInWhitelist(TypeDefinition definition)
    13.    � AssemblyPreprocessor.ConstructorInjector.ShouldInject(TypeDefinition typeDefinition)
    14.    � AssemblyPreprocessor.ConstructorInjector.InjectConstructorsForTypesIn(ModuleDefinition moduleDefinition)
    15.    � AssemblyPreprocessor.Program.Main(String[] args)
    16.  
    Not sure if it actually worked (it was designers who import your plugin). Looks as if C# code and managed library was not used, shaders only. Maybe it was ignored by Unity in previous version and rejected in the current.

    As far as I understand you still can try to build xap-file; it's build time issue, so you don't need to run anyting on device.

    Thank you for assistance very much!
     
  2. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    You can't move DecalSystem.Editor.dll to any other place. This one has to stay where it was. This causes the issue you are seeing right now. It is not relevant for WP8 as it contains the Unity editor integration code only.

    Before you proceed, please move the DecalSystem.Editor.dll file back to the place where it belongs and try the two setups I proposed which only involve DecalSystem.Runtime.dll.

    As I have Windows 7, it is not possible to test Windows Store Apps and WP8.
     
  3. sathya

    sathya

    Joined:
    Jul 30, 2012
    Posts:
    298
    Hi Dantus,
    Thanks for the great plugin. i am using decal system on a car model to project stripes. And i would like to Swap them at runtime. Not sure how to do it right. Update Projectors works only in editor if i am not wrong. Few advice would be helpful.
     
  4. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    Yes, of course I've tried only DecalSystem.Runtime.dll relocation at first, (another) compilation errors were still there. (Actually I've got some experience with Unity plugins for different platforms, as well as dealing with .NET assemblies in general.)

    Anyway I have to downgrade Unity to 4.3.2 because of the other problem, alas: http://forum.unity3d.com/threads/223065-Unity-4-3-3-Type-GetMembers(BindingFlags)-crash
     
  5. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    The runtime coding is not easy. As you are always projecting onto the same car mesh(es), the script from this post will make your life a lot easier:
    http://forum.unity3d.com/threads/141792-Decal-System/page28?p=1247584&viewfull=1#post1247584

    Hope this helps
     
  6. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Whenever I asked people whether they tried certain things, it's for myself to be sure that it can't be solved in a conventional way. Getting an idea how experienced someone is in a forum is almost impossible based on a few posts. That's also the reason why I sent you my Skype username.

    It would be awesome if you could tell me whether the issue with the Decal System dll also exists in Unity 4.3.2. I would like to contact Unity and ask for recommendations regarding managed dlls and WP8 (and Metro).
     
  7. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    It runs fine in Editor and compiles successfully for Windows Phone 8 in Unity 4.3.2. However it seems that we have no calls to methods in DecalSystem.Runtime.dll. (Designers just used your package for shaders, I guess, shadows and cracks.) So probably it would fail in runtime on WP8 if we used calls to DecalSystem.Runtime.dll. Looks like Unity developers just fixed it to be compile-time failure instead of run-time.

    Thank you, I appreciate that very much! Unfortunately, my English is not that good to speak fluently via Skype :-` Anyway I'm supposed to do a lot of tasks during working hours, so it can be a little bit hard to spare single piece of time to conversation in real time. Can only post messages to forum from time to time. Sorry for inconvenience.
     
  8. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Thanks for the information!
     
  9. MalboM

    MalboM

    Joined:
    Apr 29, 2013
    Posts:
    66
    Thanks for this awesome plugin!
    I've only a question: I tried to move a decal adding a simple animation to it, but it only works in scene view and not in game view, do you know how to make it work?

    thanks a lot
     
  10. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    What kind of animation do you mean?
     
  11. MalboM

    MalboM

    Joined:
    Apr 29, 2013
    Posts:
    66
    Thanks for the fast reply, I mean a simple translation from point a to point b or a simple rotation on the x axis . Oddly it remains on the same position in game view, while in scene view I see the animation going!
     
  12. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I assume you are moving a projector between two points. At runtime (in the game view) this requires you to do quite some coding in order to update the projector.
    As I don't have the context of your project, that one may help you:
    http://forum.unity3d.com/threads/141...=1#post1247584

    Otherwise it will be necessary for you to code your own solution based on the one from the link or based on a bullet example.

    If you are continuously moving the decal projector, you should seriously consider to use a Unity projector which may be even faster for that. The Decal System is especially fast if the projectors are not moving or just barely.
     
  13. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    Hey there, the last post of yours makes me wonder if your decal system works in the following situation:
    Please consider a vehicle with an attached decal projector that is used to do some customization to the vehicle.
    Since the decal projector wouldn't be moving in relation to the vehicle I 've got high hopes that this should work. Can you confirm this?
     
  14. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Yes, I know of several projects which used the Decal System like that. This video describes the technique in general:
    http://www.youtube.com/watch?v=-Y3rV5t-ynw
     
  15. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    Thx for clarifying. We've tested this scenario already and it works like a charm.
     
  16. Justei

    Justei

    Joined:
    Aug 31, 2012
    Posts:
    133
    Hi there, I have a question.
    How does this decal system handle in terms of performance?

    We are making a quite large open world game, and are considering using this system for our decals (which we will need extensively). What type of performance hit are we talking about if we have for example 250 projectors running?

    Thanks!
     
  17. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    The decals produced with the decal projectors are just meshes. Computing those meshes is relatively expensive. Because of that it is better to use Unity's projectors, if you have projectors that need to be updated in each frame. But if a decal projector doesn't need to be recalculated, it is just a mesh, like any other mesh that has a transparent material.
    E.g. if you place decal projectors in your environment, you are in fact just producing one more mesh that needs to be rendered.
     
  18. Justei

    Justei

    Joined:
    Aug 31, 2012
    Posts:
    133
    Thank you for the response, so if we would to be pre-doing this all, putting objects in the scene beforehand. Then it shouldn't be problematic?

    We will only use this for things such as grafitti, cracks in roads, and similar things. We will not use this at all at runtime, so in that case this should be an ideal solution for us?
     
  19. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Yes, that should not be problematic. In that case it is just a mesh with a transparent material at runtime.
     
  20. VladimirTa

    VladimirTa

    Joined:
    Jul 17, 2013
    Posts:
    40
    Hi Dantus.
    I just updated to Unity 4.3.3 and the decal system does not work on WP8, it was working good in Unity 4.3.1. It also works good for windows and android on Unity 4.3.3.
    I have tried moving DecalSystem.Runtime.dll that you mentioned earlier but this does not work.
    This is the error that unity gives:


    Is there some workaround or fix for this?
     

    Attached Files:

    Last edited: Jan 28, 2014
  21. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    The proposed changes to move the dll files did not work. Please submit a bug report and clearly state that it worked with 4.3.1 and does not anymore with 4.3.3. As I don't have Windows 8, it is almost impossible for me to help. But that error seems to be caused by a change in Unity.
     
  22. jchow

    jchow

    Joined:
    Jun 20, 2013
    Posts:
    28
    Hi, I apologize for not having the time to read though all 42 pages of this thread for an answer to my questions. I'm hoping that they have quick answers. :)

    1) If I wanted to use more than one simultaneous decal atlas in a scene, do/can I just instantiate more than one DS_Decals object?
    2) The DS_Decals editor obscures this but if I wanted to create Decal Projectors dynamically, I just need to set the UV index and it'll use that index to map into the list of UVs in the owning DS_Decals, correct?

    I intend to use decals in this manner:
    Our levels are dynamically generated by instantiating random instances of props. Some of these props may have graffiti, which I want render using decals. I plan on having a small number of DS_Decals instances baked into my scene (one atlas per instance). Props will pick the type of decal they want and create a decal projector in the appropriate DS_Decals object. Then I'll use the Bullet example to regenerate the decals. This happens at level load time. Once the meshes are generated they don't need to be modified any more.
     
  23. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Well, I kind of understand it :)

    Yes, of course.

    Yes.
     
  24. VladimirTa

    VladimirTa

    Joined:
    Jul 17, 2013
    Posts:
    40

    OK, I have sent the bug report to unity.

    I am not sure but I think you don't need Windows 8 to check that, just Switch Platform to Windows Phone 8 in build settings and Unity will start giving these errors.
     
  25. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Thanks a lot for submitting the bug!

    I tried to switch the platform and Unity showed me the message that Windows 8 is required.
     
  26. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I was just informed, that it is possible to build an application for WP8 with Unity 4.3.3 containing the Decal System.

    Move DecalSystem.Runtime.dll to Assets/Plugins
    Move DecalSystem.Editor.dll out of the Plugins folder, e.g. to Assets/Decal System/Editor
     
  27. VladimirTa

    VladimirTa

    Joined:
    Jul 17, 2013
    Posts:
    40
    I just checked that, everything works correctly now.

    Thanks.
     
  28. jchow

    jchow

    Joined:
    Jun 20, 2013
    Posts:
    28

    Thanks very much Dantus, your software is awesome. I have one more question about DS_Decals and the material it uses. Would it be possible to generate a texture at runtime to use in the atlas, assuming that texture is created so that it respects the UV rectangles placed in the Editor? I tried just changing the texture like this:

    Code (csharp):
    1. decalsComponent.CurrentMaterial.SetTexture("_MainTex",myTex)
    2.  
    but it makes all the decals disappear. I'm doing this before I add spawners to the decal mesh.

    I've also tried
    Code (csharp):
    1.  decalsComponent.CurrentMaterial.mainTexture = myTex;
    More notes:
    I am calling decalsComponent.ApplyMaterialToMeshRenderers() after I set CurrentMaterial. I've tried calling it before and after this code to register each projector:
    Code (csharp):
    1.     DecalProjector projector = new DecalProjector (pos, rot, scale, m_CullingAngle, m_MeshOffset, (int)section, (int)section );
    2.  
    3.             Matrix4x4 l_WorldToMeshMatrix = spawner.m_meshForDecal.transform.worldToLocalMatrix;
    4.             Matrix4x4 l_MeshToWorldMatrix = spawner.m_meshForDecal.transform.localToWorldMatrix;
    5.                
    6.             // Add the mesh data to the decals mesh, cut and offset it.
    7.             m_DecalsMesh.AddProjector (projector);
    8.             m_DecalsMesh.Add (spawner.m_meshForDecal.mesh, l_WorldToMeshMatrix, l_MeshToWorldMatrix);                      
    9.             m_DecalsMeshCutter.CutDecalsPlanes (m_DecalsMesh);
    10.             m_DecalsMesh.OffsetActiveProjectorVertices ();
    but results are the same (decal meshes present, nothing visible
     
    Last edited: Jan 30, 2014
  29. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I just tested this at runtime and have no problems to get it working. Did you check in the inspector whether the texture/material is correctly applied?
     
  30. jchow

    jchow

    Joined:
    Jun 20, 2013
    Posts:
    28
    Yes, the inspector shows the texture being updated.
    BUT I didn't realize until much later that the inspector only shows the texture contents and not the final output after the shader has been run. It was a bug in my shader. :)
     
  31. Desktopdaydreams

    Desktopdaydreams

    Joined:
    Nov 20, 2010
    Posts:
    154
    Good Morning Folks,

    First up, a big thumbs up to @Dantus for the Decal System, its a great free tool!

    I've been trying to figure out a small issue we're getting with our decals turning black. I've added two screen shots to show the problem.

    $decal_black_01.jpg $decal_black_02.jpg

    This only seems to happen when the camera is at certain angles. The screen shots show the same decal but from slightly different angles.

    We're using the decal shaders, deferred Rendering and linear color space. Could it be an issue with lighting or shadows?


    Any help would be much appreciated!

    Thanks,
    Tim
     
  32. VladimirTa

    VladimirTa

    Joined:
    Jul 17, 2013
    Posts:
    40
    Have you baked lightmaps?
    If not, try to bake the lightmaps an the problem should be solved.
     
    Last edited: Jan 31, 2014
  33. Desktopdaydreams

    Desktopdaydreams

    Joined:
    Nov 20, 2010
    Posts:
    154
    @vladimirta89

    many thanks, I thought we had tried that, but talking with the team it may be that our light maps have been cleared! Thanks again, I'll get back to it once we've had a look.

    Cheers
     
  34. ounick

    ounick

    Joined:
    Aug 15, 2009
    Posts:
    7
    Hi.

    First of all, I love the decal system. I am making a game for IOS so I am trying to be as efficient as possible. I am using a fog of war system that deactivates GameObjects when the player doesn't have line of sight or are far away. What is the easiest/best way to activate and deactivate decals as needed? I have scoured around but haven't been able to find a solution yet.

    Thanks,
    Nick
     
  35. Dantus

    Dantus

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

    As it is not easily possible to deactivate individual projectors, you can only deactivate the whole decals object at once, by deactivating the actual game object itself.

    Edit: Instead of deactivating, you may think of using special shaders to cover objects.
     
    Last edited: Feb 2, 2014
  36. ounick

    ounick

    Joined:
    Aug 15, 2009
    Posts:
    7
    Thanks for quick reply. I already wrote a shader that shades the decals out to black when moving away, making them invisible. My only concern was possibly optimizing performance.

    Nick
     
  37. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I don't see a trivial optimization for your use case that just works. If you have actual performance issues due to the decals, I am open to help you with that.
     
  38. williamchyr

    williamchyr

    Joined:
    Aug 17, 2012
    Posts:
    2
    Hey Dantus,

    Just wanted to post here a problem I talked about in my devlog. Would love to get to the bottom of it, and better understand what's going on, and what I'm doing wrong. Also, thank you for being pro-active in reaching out to users and providing support. Really appreciate it.

    ----
    I started to notice this very weird bug: the decals around the archway of the door, which show how many keys the player has obtained, and how many are needed to open the door, would fade in and out of visibility.

    The way the decals for the door works is that I have 12 of them responsible for the key lights. 6 of them show how many keys are required, and 6 of them show the number of keys the player has.

    The decals showing the required number of keys are off-set from the mesh by 0.01. This is because if there is not offset, there ends up being a strange flickering effect because there are 2 meshes overlapping and the engine doesn’t know which one to render.

    Then, because the decals showing how many keys the player has need to be shown on top of the decals showing required number of keys, they are off-set by 0.02, show that they are rendered over the other decals.

    However, I was noticing a problem where, if I stood at certain angles, some of the decals showing how many keys the player has would become invisible. I double checked the code, and the logic was all correct. As far as the element was concerned, it was detecting the right number of keys, and had the right requirement number. From this, I determined it was just a problem with the decals.

    I started to play around with the different settings of the decal projectors: size, culling angle, position, affected layers. Eventually, what I found was that the decal for the required keys and the decal for the number of keys the player has, cannot overlap. Despite having the mesh off-set values be different, if the decal projectors overlap, there ends up being some kind of a problem.

    This is what the set up for the decals look like now:

    $decals_setup.jpg

    You can see that the decal projectors (represented by the capital D with three lines next to it), are off set from each other.


    ----

    You mentioned something about using transparent shaders. Definitely using that here. Let me know what's going on.
     
  39. Dantus

    Dantus

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

    Which shader are you using for the decals? And are you using another transparent shader right there?
     
  40. williamchyr

    williamchyr

    Joined:
    Aug 17, 2012
    Posts:
    2
    I'm using the "Transparent/Diffuse" shader for the "off" lights. For the "on" lights, I'm using this shader, AlphaSelfIllum, that I got form Unity community wiki page: http://wiki.unity3d.com/index.php?title=AlphaSelfIllum

    It allows me to have a self-illuminated shader that also has transparency. Perhaps this is the source of my problem?

    Here's the code for the shader:


    Code (csharp):
    1. Shader "My Shaders/AlphaSelfIllum" {
    2.     Properties {
    3.         _Color ("Color Tint", Color) = (1,1,1,1)
    4.         _MainTex ("SelfIllum Color (RGB) Alpha (A)", 2D) = "white"
    5.     }
    6.     Category {
    7.        Lighting On
    8.        ZWrite Off
    9.        Cull Back
    10.        Blend SrcAlpha OneMinusSrcAlpha
    11.        Tags {Queue=Transparent}
    12.        SubShader {
    13.             Material {
    14.                Emission [_Color]
    15.             }
    16.             Pass {
    17.                SetTexture [_MainTex] {
    18.                       Combine Texture * Primary, Texture * Primary
    19.                 }
    20.             }
    21.         }
    22.     }
    23. }
     
  41. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    You need to add
    Code (csharp):
    1. Offset -1, -1
    Code (csharp):
    1. Shader "My Shaders/AlphaSelfIllum" {
    2.     Properties {
    3.         _Color ("Color Tint", Color) = (1,1,1,1)
    4.         _MainTex ("SelfIllum Color (RGB) Alpha (A)", 2D) = "white"
    5.     }
    6.     Category {
    7.        Offset -1, -1
    8.        Lighting On
    9.        ZWrite Off
    10.        Cull Back
    11.        Blend SrcAlpha OneMinusSrcAlpha
    12.        Tags {Queue=Transparent}
    13.        SubShader {
    14.             Material {
    15.                Emission [_Color]
    16.             }
    17.             Pass {
    18.                SetTexture [_MainTex] {
    19.                       Combine Texture * Primary, Texture * Primary
    20.                 }
    21.             }
    22.         }
    23.     }
    24. }
     
  42. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Hi Dantus,
    Sorry if maybe this is already asked, but what is projection mode??
     
  43. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Technically it is there to define how all the mesh data needs to be computed. Would you like to project the uvs, or would you like to take the coordinates of the mesh onto which you perform the projection.

    This video may be helpful for you:
     
  44. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Ah i see, thanks for the answer...
     
  45. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Is something not clear about it? Usually if someone writes ... it is not a good sign :)
     
  46. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    lol.. no no, everything is clear enough actually, i just kinda missunderstood about the projection mode.At first i thought we can projecting normal channel or something. Have you read about how naughty dogs did their footstep decal in uncharted3? when drake was in the desert..
     
  47. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I am not aware of such an article. Do you have any links?
     
  48. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Hmm hold on it's kinda old article....i'll let you know if i can find them, or maybe i just send you the pdf...
     
  49. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Did a quick google search. It seems they were using screen space decals (deferred decals). They are using a different technique.
    I did some experiments in that direction and found out that I suck at shader programming. I didn't give up yet, but there is still no light at the end of the tunnel.
     
  50. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Oh okay at least you find it, yeah the problem is i'm not sure if it's even possible to write into G-Buffer in Unity at the moment, since SSDecals or deferred decals rely on it.