Search Unity

Decal System

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

  1. kurylo3d

    kurylo3d

    Joined:
    Nov 7, 2009
    Posts:
    1,123
    Awesome thanks, I will probably be purchasing this within the next week or 2. When u say the automatic updater is needed, what does that mean? If I were to buy it today, can i make decals using the standard shader yet (and i mean unity 5 standard)?
     
  2. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    You could start today, yes. You would most likely need to use a small mesh offset to avoid z-fighting, but other than than, I am not aware of issues.
    Just to make it clear. I opened the Decal System in Unity 5 and did some basic tests with it that were all successful. But I didn't test it in depth yet!
     
    kurylo3d likes this.
  3. punk

    punk

    Joined:
    Jun 28, 2013
    Posts:
    408
    Do you have an estimate for when that may be ready?

    Taz
     
  4. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    My goal is to have an update within one or two weeks. As there were a lot of updates on the asset store side, I expect some issues there as well, which are hopefully resolved within one week. Hope this helps.
    But as usual, this is about software development and don't take this as a promise.
     
    punk likes this.
  5. jalapen0

    jalapen0

    Joined:
    Feb 20, 2013
    Posts:
    136
    Do you have a free version I can test with before dropping 95 bucks? Specifically, I want to see how this works on terrains and can you apply shaders to them to do cool things like glow?
     
  6. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Sent you a pm.
     
  7. punk

    punk

    Joined:
    Jun 28, 2013
    Posts:
    408
    Hi Dantus,

    I've been having a problems with my runtime decals, I'm using Unity 5 RC4 and in the editor it works perfectly. When I create a build (windows) none of the decals show up, they are there, because if I hide the floor mesh I can see them, have you come accross this behaviour before?

    Thanks Taz
     
  8. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I have seen this before. It happened when the Decal System game object was far away from the projectors which then lead to precision issues. Other than that, the shader can have an impact as well of course.

    The easiest way to help you would certainly be, if you could send me a reproduction of the issue.
     
  9. punk

    punk

    Joined:
    Jun 28, 2013
    Posts:
    408
    Thanks, that gives me something to go on ;)

    Taz
     
  10. punk

    punk

    Joined:
    Jun 28, 2013
    Posts:
    408
    Hey Dantus,

    I figured it out!, it's only a problem when static batching is on, if I turn it off it works like a charm, have you ever had that? I'd post you the project, but it's big(30GB+)
     
  11. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    This is new to me. It should give me enough information to investigate the issue. Thanks!
     
    punk likes this.
  12. boddole

    boddole

    Joined:
    Sep 18, 2013
    Posts:
    35
    Hello everyone, I've been using a free version of Decal System for a few days now, and I've got a few questions on the asset (any thoughts are appreciated, and your patience is also appreciated for reading this wall....):

    1) In terms of performance, does it make any appreciable difference if I have 1 Decals instance with 1 Projector per dynamic object (so the decal orientation is handled for me) vs. having every Projector under 1 Decals instance, and then putting some additional script on the Projector so that it behaves like it had a parent?


    2) Have you found a good way to deal with a decal placed on / overlapping 2 dynamic objects? Is it possible to have the projector "split" or create a new projector to cover where the mesh splits (and give 1 mesh to each projector)?

    Ex.) 2 cubes are placed close together then "hit with a large explosion" (which applies a decal over both cubes). Then the cubes move away from each other, meaning that only the cube that has the Decal instance attached as a child will render correctly (and still have some of the decal going off into space), while the other cube will have nothing.

    The only compromise I can think of right now would be to use Affect to only allow the decal projector to project on 1 object hierarchy at a time (so when the decal comes in, get the hit object's parent, and only allow projection on those mesh renderers under that parent). You would lose decal accuracy, but at least you wouldn't have phantom decals floating around.


    3) For using decals during runtime, is some sort of "conditional Culling Angle" possible? This one is a bit hard to explain so I'm relying on the picture, but essentially: if I had a impact point, is it possible to set angle constraints based on if that vertices' location is in front of or behind the impact point (perhaps using some combo of local forward vectors and global positions)?


    4) The script "BulletExampleDynamicObject" does not seem to work at all, no decal instances / projectors / decals are created. Am I not using the script correctly (as a replacement for the default "BulletExample" script)?
     

    Attached Files:

    Last edited: Mar 19, 2015
  13. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Both questions can be answered at once. Whenever you are dealing with dynamic objects, each dynamic object is supposed to have its own decal instance. Otherwise if the decals instance does not move with the dynamic object, you would need to modify the projector's position and rotation in each frame when the object is moved and that means the projector would need to be recalculated in each of those frame, which makes no sense from a performance point of view.

    When you place decal projectors in the editor to dynamic objects, meaning the decals instance is a child of the game object that moves/is dynamic, you need to make sure that the projector only affects mesh renderers that move with the dynamic object. This functionality is only available in the Decal System Pro at the moment.


    This is not possible at the moment. I will add this to my TODO list. I can't promise anything, because first of all, I need to check whether and how this is doable.

    Did you check the scene for dynamic decals. In there you should see how the objects are supposed to be set up.
     
  14. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    In the market for a decent decals system. There's too many pages to go through so forgive me if things can be answered here :)

    1. need to put blood splats on skinned animated meshes like players. Not essential but would be nice (realtime update?)

    2. need the shader to work in linear deferred, and support normals and / or transparency (alpha). Since unity won't shade alpha blended objects, I wondered if it would just affect albedo and normals? this way the decal blends with the shadow applied by whatever it is resting on, completing the illusion.

    3. what kind of occlusion or technique do you use, ie command buffers and so on - just wanting a larger picture of the performance with this question.

    Can your system do these things? thank you for your time :)
     
  15. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    The Decal System supports skinned decals. A new skinned mesh is automatically created that uses the same bones as the original mesh and as such it is 100% synchronized with the original mesh. The best results are achieved if the quality of the skinned decals are twice high as the quality of the skinned mesh onto which the projection is made.

    The Decal System creates a new mesh for which you can use whatever material you want. In the current Decal System, there is an experimental shader for Unity 4 that supports shadows. For Unity 5, there is still some work to be done on the shader side.

    The Decal System creates a new mesh for which you can use any material you want. As the Decal System always takes the underlying mesh onto which you project the decal, some interesting effects are possible. You may e.g. take the vertex color of the underlying mesh or use those vertex colors for the decal or modify them. The same is possible for everything that is stored in the mesh (uvs, normals, tangents, ...).

    Let me know if you have further questions or if you would like to discuss it on Skype.
     
  16. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Thanks a lot. I'm just casting out feelers as the creative director brandished his wacom pen at me demanding decals n stuff.
     
  17. boddole

    boddole

    Joined:
    Sep 18, 2013
    Posts:
    35
    Thank you for answering my initial questions, and yes, I managed to miss the 'dynamic example'. Things are moving along well now, I just have a few more questions if you don't mind giving them a look over:

    1) Is Adding then Removing projectors causing any meaningful work for the garbage collector to do? I'm working on iOS and GC on that platform can be very touchy. And I would like to avoid as much garbage creation as possible.

    2) From what I've seen, your runtime examples of decal creation do not deal with hitting multiple meshes/colliders, have you observed that this is just too expensive during runtime? I imagine it would involve some sort of volume check inside the project's area for all meshes / colliders that you want to hit (and to get the various needed matrixes), then add all of them to the decals mesh with the needed arguments? Something like that?

    3) Have you considered exposing more of the "Affect" options through script? Or perhaps you have I just haven't figured out how/where to access them? I suppose that it is possible that any option from Affect can be achieved through script before creating the decal, is that the same conclusion you came to?

    By the way, could you give a decal script I wrote a look over, just to make sure I haven't done anything obviously wrong? It is a script that deals with your asset as part of a larger object pooling setup.

    As always, any thoughts are appreciated, thank you for reading.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using Edelweiss.DecalSystem;
    5.  
    6. public class zTest_MyDecalSetup2 : MonoBehaviour {
    7.     //handle the creation of each needed prefab as well has when and how they appear.
    8.     //goes on the "head" obj. on the decal prefab.
    9.    
    10.     private DS_Decals decalsInstance;
    11.  
    12.     private DecalsMesh decalsMesh;
    13.     private DecalsMeshCutter decalsMeshCutter;
    14.     private DecalProjector decalProjector;
    15.  
    16.     public float decalProjectorOffset = 0.1f;
    17.     public float cullingAngle = 80.0f;
    18.     public float meshOffset = 0.0f;
    19.  
    20.     private Transform defaultParent;
    21.  
    22.  
    23.     void OnEnable()
    24.     {
    25.         zTest_DestructionWarning.parentDestructionImmenent += SwitchParent;
    26.     }
    27.  
    28.     void OnDisable()
    29.     {
    30.         zTest_DestructionWarning.parentDestructionImmenent -= SwitchParent;
    31.     }
    32.  
    33.  
    34.     //called by pooled obj. manager during scene start:
    35.     public void Create()
    36.     {
    37.         decalsInstance = GetComponentInChildren<DS_Decals>();
    38.        
    39.         if (decalsInstance != null)
    40.         {
    41.             decalsMesh = new DecalsMesh(decalsInstance);
    42.             decalsMeshCutter = new DecalsMeshCutter();
    43.            
    44.             decalProjector = new DecalProjector(Vector3.zero, Quaternion.identity, Vector3.zero, 0f, 0f, 0, 0);
    45.             decalsMesh.AddProjector(decalProjector);
    46.  
    47.             defaultParent = transform.parent;
    48.             gameObject.SetActive(false);
    49.         }
    50.         else
    51.         {
    52.             Debug.LogError ("The decals prefab does not contain a DS_Decals instance!");
    53.         }
    54.     }
    55.  
    56.     //called by impacting shell:
    57.     public void ApplyDecal(RaycastHit hitInfo, Vector3 scale, int uvIndex, Mesh hitMesh, Matrix4x4 worldToMesh, Matrix4x4 meshToWorld)
    58.     {
    59.         decalsMesh.RemoveProjector(decalProjector);
    60.         decalsMesh.AddProjector(decalProjector);
    61.  
    62.         decalsInstance.transform.parent = hitInfo.transform;
    63.         Debug.Log("decalsInstance.transform.parent is: " + hitInfo.transform.GetInstanceID() );
    64.  
    65.         decalProjector.position = hitInfo.point + (decalProjectorOffset * hitInfo.normal);
    66.         Debug.Log("decalProjector.position is: " + decalProjector.position);
    67.  
    68.         decalProjector.rotation = ProjectorRotationUtility.ProjectorRotation(-hitInfo.normal, Vector3.up);
    69.         Debug.Log("decalProjector.rotation.eulerangles is: " + decalProjector.rotation.eulerAngles);
    70.  
    71.         decalProjector.scale = scale;
    72.  
    73.         decalProjector.uv1RectangleIndex = uvIndex;
    74.         decalProjector.uv2RectangleIndex = uvIndex;
    75.  
    76.         decalProjector.cullingAngle = cullingAngle;
    77.         decalProjector.meshOffset = meshOffset;
    78.  
    79.         decalsMesh.Add(hitMesh, worldToMesh, meshToWorld);                      
    80.         decalsMeshCutter.CutDecalsPlanes(decalsMesh);
    81.         decalsMesh.OffsetActiveProjectorVertices();
    82.  
    83.         decalsInstance.UpdateDecalsMeshes(decalsMesh);
    84.     }
    85.  
    86.     //prevent decals from being destroyed on a sunk ship:
    87.     private void SwitchParent(int gObjID)
    88.     {
    89.         Debug.Log("incoming gObjID is: " + gObjID);
    90.         Debug.Log("transform.parent.GetInstanceID() is: " + transform.parent.GetInstanceID() );
    91.  
    92.         if(gObjID == transform.parent.GetInstanceID() )
    93.         {
    94.             transform.parent = defaultParent;
    95.             gameObject.SetActive(false);
    96.         }
    97.     }
    98. }
     
  18. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    No, that has no impact on the garbage collector. Performance and meaningful memory management were a central aspect during the development. If you have trouble because of that, we can have a look at it. Internally, vertices, normals, triangle indices, ... are removed and added to a list. Of course, if the lists are too small, there will be some allocation.

    The reason why it is not there is, because those are just examples. As you mentioned, it shouldn't be too complicated to replace the raycast with something like a sphere cast and then to handle the various hit targets appropriately, exactly as mentioned by you. Instead of adding one mesh, it would just be a collection of meshes along with their matrices.

    You should already have access to all those options. What exactly is missing?
    There are two kinds of projectors. There are the component projectors (DS_DecalProjector) that can be added to game objects and the ones that don't have the "overhead" of having a game object (DecalProjector). Both of them have the same base class which is used to compute the projection and as such both have the same functionality.

    I couldn't find any glitches in the script that could have a negative impact on the performance. One possible optimization would be to cache the mesh data and pass the actual arrays. Of course, I don't know whether this is feasible in your project. Whenever you pass a mesh, the Decal System need to get the vertices, normals, ... . It is not possible to just query that data, but Unity always return a copy:
    https://docs.unity3d.com/ScriptReference/Mesh-vertices.html
     
  19. boddole

    boddole

    Joined:
    Sep 18, 2013
    Posts:
    35
    Thank you again for the feedback, this is a great asset!
     
  20. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I am glad you like it. If you have questions or feedback, don't hesitate to ask.
     
  21. Nake47

    Nake47

    Joined:
    May 4, 2014
    Posts:
    6
    Oh,now it isn`t free...Why?
     
  22. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    The asset store is not a good place for free asset in my opinion. At the end of the day, it is a lot of work to maintain such a package, while there was almost no return from the community, e.g. by giving valuable feedback. There were more and more trolls who gave one star ratings and reviews. It is not a big deal to remove the review, however the rating will stay there. All in all, it isn't worth the effort anymore for me.
    I tried to improve the situation by getting in touch with the community and I also tried to get in touch with Unity. Both without any success.
    http://forum.unity3d.com/threads/support-publishers-of-free-assets.253685/
     
  23. piacentini

    piacentini

    Joined:
    May 27, 2014
    Posts:
    28
    Quick post to help those trying to build for WP8 or WSA with the current version (from August 2014).

    When you build for the reduced .Net subset available on these platforms Unity will throw out the following errors in the processor:

    Reference Rewriter: Error: method `System.String System.String::Copy(System.
    String)` doesn't exist in target framework. It is referenced from DecalSystem.Runtime.dll at System.Void Edelweiss.DecalSystem.UVRectangle::.ctor(Edelweiss.DecalSystem.UVRectangle).

    UnityEngine.Debug:LogError(Object)
    PostProcessMetroPlayer:RunReferenceRewriter(WSASDK, String, String, String, String) (at C:/buildslave/unity/build/PlatformDependent/MetroPlayer/Extensions/Managed/PostProcessMetroPlayer.cs:334)
    PostProcessMetroPlayer:postProcessSDKSpecific(WSASDK, BuildTarget, BuildOptions, String, String, ProjectImages, LibraryCollection) (at C:/buildslave/unity/build/PlatformDependent/MetroPlayer/Extensions/Managed/PostProcessMetroPlayer.cs:883)
    PostProcessMetroPlayer:postProcess(BuildTarget, BuildOptions, String, String, String, String) (at C:/buildslave/unity/build/PlatformDependent/MetroPlayer/Extensions/Managed/PostProcessMetroPlayer.cs:583)
    UnityEditor.HostView:OnGUI()

    This happens because there is a single usage of an unavailable String.Copy method in a class that is compiled inside the runtime dll. The workaround is to delete the DecalSystem.Runtime.dll, and unpack the source code package supplied with the asset, so Unity will use it. Then you need to edit the source file UVRectangle.cs

    public UVRectangle (UVRectangle a_Other) {
    //Copy is not available in the subset of String exposed to Metro apps
    //name = string.Copy (a_Other.name);
    //Use a workaround with the Concat function
    name = string.Concat(a_Other.name, "");
    lowerLeftUV = a_Other.lowerLeftUV;
    upperRightUV = a_Other.upperRightUV;
    }

    Save it, and you should now be able to compile and deploy on WSA.
     
    Dantus likes this.
  24. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    @piacentini, thanks a lot for the feedback. I am going to integrate this change into the next version to avoid this issue in the future.
     
  25. Kanibel

    Kanibel

    Joined:
    Sep 18, 2014
    Posts:
    5
    Does this system support unlit decals? Or alternatively is there away for these decals to not receive shadows?

    Tried using the new unity deferred decal system and as it modifies the G-Buffer after lighting is done the shadows are always applied. Quite annoying :(
     
  26. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    It should be straight forward as you can use any shader you want. Just use an unlit shader and additionally make sure to have the correct offset defined as in all the other provided decal shaders to avoid unnecessary z fighting.
     
  27. FG_dev1

    FG_dev1

    Joined:
    Nov 3, 2014
    Posts:
    44
    Hi,

    How effective is the system at creating dynamic geo decals at runtime using a projection box? (assuming it can)

    I want blood that is able to wrap around (potentially) multiple meshes when created.

    Assets looks great but I really need to be sure it does what I want before I shell out $95 on decals. I'm sure you've answered this somewhere so sorry to ask again.
     
  28. Kanibel

    Kanibel

    Joined:
    Sep 18, 2014
    Posts:
    5
    Thanks Dantus!
     
  29. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    There is an example scene provided with the Decal System which uses a raycast to project a decal. Out of the box, it only performs a projection onto one mesh, but you can relatively easy adjust it for your needs. Instead of using a raycast, you need to use a sphere cast and than apply it to multiple meshes.

    Edit: Using the Decal System at runtime, requires advanced programming skills. Let me know if you need further details.
     
  30. FG_dev1

    FG_dev1

    Joined:
    Nov 3, 2014
    Posts:
    44
    Hi

    I just bought this asset last night

    I'm trying to create a decal once an object hits something. When I use the same ray in the example (from my own scene):

    Code (CSharp):
    1. Ray l_Ray = Camera.main.ViewportPointToRay (new Vector3 (0.5f, 0.5f, 0.0f));
    2.             RaycastHit l_RaycastHit;
    3.  
    4.             //Check for collision from previous position to current position
    5.             if (Physics.Raycast (l_Ray, out l_RaycastHit, Mathf.Infinity, layersToHit) &&
    6.                 l_RaycastHit.collider as TerrainCollider == null)
    It works fine, creates a decal on the object it collided with.

    But when when I try to use a line cast based on the previous and current positions it creates the decal but it has no verts in the mesh. Here is how I'm doing it:

    Code (CSharp):
    1. // Update is called once per frame
    2.     void Update ()
    3.     {
    4.         //Store previous position for collision check
    5.         previousPos = transform.position;      
    6.        
    7.         //Move object forward
    8.         transform.position += transform.forward * (50.0f * Time.deltaTime);
    9.        
    10.         //Calculate the length of the ray
    11.         float distanceTravelled = Vector3.Distance (transform.position, previousPos) + 0.0001f;
    12.        
    13.         //Create the ray
    14.         Ray l_Ray = new Ray (previousPos, transform.position - previousPos);
    15.         RaycastHit l_RaycastHit;
    16.        
    17.        
    18.         //Check for collision from previous position to current position
    19.         if (Physics.Raycast (l_Ray, out l_RaycastHit, distanceTravelled, layersToHit) &&
    20.             l_RaycastHit.collider as TerrainCollider == null)
    21.         {
    22.            
    23.             // Collider hit.
    24.             lastRayHitPos = l_RaycastHit.point;
    25.            
    26.             // Instantiate the prefab and get its decals instance.
    27.             DS_Decals l_DecalsInstance = Instantiate (m_DecalsPrefab) as DS_Decals;
    28.            
    29.             // Reuse the decals mesh, but be sure to initialize it always for the current
    30.             // decals instance.
    31.             m_DecalsMesh.Initialize (l_DecalsInstance);
    32.            
    33.             // Calculate the position and rotation for the new decal projector.
    34.             Vector3 l_ProjectorPosition = l_RaycastHit.point - (m_DecalProjectorOffset * l_Ray.direction.normalized);
    35.             Quaternion l_ProjectorRotation = ProjectorRotationUtility.ProjectorRotation (player.MainCamera.forward, Vector3.up);
    36.            
    37.             // Randomize the rotation.
    38.             Quaternion l_RandomRotation = Quaternion.Euler (0.0f, Random.Range (0.0f, 360.0f), 0.0f);
    39.             l_ProjectorRotation = l_ProjectorRotation * l_RandomRotation;
    40.            
    41.             l_DecalsInstance.transform.position = l_ProjectorPosition;
    42.            
    43.             // We hit a collider. Next we have to find the mesh that belongs to the collider.
    44.             // That step depends on how you set up your mesh filters and collider relative to
    45.             // each other in the game objects. It is important to have a consistent way in order
    46.             // to have a simpler implementation.
    47.            
    48.             MeshCollider l_MeshCollider = l_RaycastHit.collider.GetComponent <MeshCollider> ();
    49.             MeshFilter l_MeshFilter = l_RaycastHit.collider.GetComponent <MeshFilter> ();
    50.             MeshRenderer l_MeshRenderer = l_RaycastHit.collider.GetComponent <MeshRenderer> ();
    51.            
    52.             if (l_MeshCollider != null || l_MeshFilter != null)
    53.             {
    54.                 Mesh l_Mesh = null;
    55.                 if (l_MeshCollider != null)
    56.                 {
    57.                    
    58.                     // Mesh collider was hit. Just use the mesh data from that one.
    59.                     l_Mesh = l_MeshCollider.sharedMesh;
    60.                 }
    61.                 else if (l_MeshFilter != null)
    62.                 {
    63.                    
    64.                     // Otherwise take the data from the shared mesh.
    65.                     l_Mesh = l_MeshFilter.sharedMesh;
    66.                 }
    67.                
    68.                 if (l_Mesh != null)
    69.                 {
    70.                    
    71.                     // Create the decal projector.
    72.                     DecalProjector l_DecalProjector = new DecalProjector (l_ProjectorPosition, l_ProjectorRotation, m_DecalProjectorScale, m_CullingAngle, m_MeshOffset, m_UVRectangleIndex, m_UVRectangleIndex);
    73.                    
    74.                     // Add the decals instance to our list and the projector
    75.                     // to the decals mesh.
    76.                     // All the mesh data that is now added to the decals mesh
    77.                     // will belong to this projector.
    78.                     //m_DecalsInstances.Add (l_DecalsInstance);
    79.                     m_DecalsMesh.AddProjector (l_DecalProjector);
    80.                    
    81.                     // Get the required matrices.
    82.                     Matrix4x4 l_WorldToMeshMatrix = l_RaycastHit.collider.renderer.transform.worldToLocalMatrix;
    83.                     Matrix4x4 l_MeshToWorldMatrix = l_RaycastHit.collider.renderer.transform.localToWorldMatrix;
    84.                    
    85.                     // Add the mesh data to the decals mesh, cut and offset it.
    86.                     m_DecalsMesh.Add (l_Mesh, l_WorldToMeshMatrix, l_MeshToWorldMatrix);                      
    87.                     m_DecalsMeshCutter.CutDecalsPlanes (m_DecalsMesh);
    88.                     m_DecalsMesh.OffsetActiveProjectorVertices ();
    89.                    
    90.                     // The changes are only present in the decals mesh at the moment. We have
    91.                     // to pass them to the decals instance to visualize them.
    92.                     l_DecalsInstance.UpdateDecalsMeshes (m_DecalsMesh);
    93.                 }
    94.             }
    95.         }
    96.     }
    Any idea why this mesh doesn't get verts but one using a ray from the camera does?

    Thanks
     
  31. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I don't have the time right now to have a close look at the code. I am going to do that later today and will hopefully be able to answer your question.
     
  32. xaeroxx

    xaeroxx

    Joined:
    Dec 2, 2012
    Posts:
    17
    Hi, I'm trying to add decals (vinyl) to my car model, which is a single mesh. I want the decal is drawn only to the body (painted) part but not to the glass parts. How can I prevent it to be drawn on glass? Glass parts are not separate meshes but have different material ids.
     
  33. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    It looks like the projector's rotation computation is off:
    Code (csharp):
    1. Quaternion l_ProjectorRotation = ProjectorRotationUtility.ProjectorRotation (player.MainCamera.forward, Vector3.up);
    You may try to use something like that instead:
    Code (csharp):
    1. Quaternion l_ProjectorRotation = ProjectorRotationUtility.ProjectorRotation (l_Ray.direction, Vector3.up);
    You most likely want the projection to be along the movement direction. As such, the projector needs to point there. I certainly don't have a lot of context and as such something else could be an issue here. However, this is the most obvious cause I was able to find.
     
  34. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    In the Decal System, you can pass any kind of mesh data onto which a projection needs to be calculated. That means you have the possibility to only send a selection of triangles. When you are dealing with a mesh in Unity that has multiple materials, Unity will automatically create submeshes as described here:
    http://docs.unity3d.com/Manual/class-MeshRenderer.html

    You only need to know which submesh is relevant for you and then pass all the car mesh data, except that you are only using the triangles you want from specified submesh(es).
     
  35. xaeroxx

    xaeroxx

    Joined:
    Dec 2, 2012
    Posts:
    17
    Thanks, I have bought the asset. Now, I have another question. I see that you use an atlas of decals (decals_package_a for example) prepared for the examples. Do you create the atlas manually in photoshop or is there a way to build the atlas automatically from individual decals?
     
  36. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    You can't do it using the Decal System at the moment. I have made a bunch of experiments in that direction, unfortunately I couldn't find a good solution so far that can handle multiple maps at once (e.g. diffuse, bump, ...).
     
  37. FG_dev1

    FG_dev1

    Joined:
    Nov 3, 2014
    Posts:
    44
    Hi,

    What's the best way to avoid stretched decals when creating them at runtime based on a movement direction?

    I'll explain:

    So I'm making blood decals as I said above by using the movement direction for the projector rotation. But the problem is this only looks as desired if the angle is similar to the normal of the surface it hit.

    For example:



    The one on the left is created from directly above the surface it hit but the right one is done from a 45(ish) degree angle making it stretched.

    How can I have it so the decals created at runtime are always nice and even like the one one the left and not stretched? Do you have any solutions for this Dantus (or anyone else)?

    Thanks
     
  38. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    There are many things you can try out. You can use the negative surface normal or you can use the ray direction, or you may try to find a compromise between them. You might use Vector3.Lerp (-surfaceNormal, rayDirection, 0.5f) to take 50% influence from both of them. Instead of using 0.5, you may use any value between 0 and 1. You may even find cases in your game where you know which kind of values works best.

    Hope this helps!
     
  39. xaeroxx

    xaeroxx

    Joined:
    Dec 2, 2012
    Posts:
    17
    Hi Dantus, I'm struggling with implementing this feature. I couldn't find a way to pass a submesh data to the decal system. As far as I understand, this should be done via scripting right? Is there any simple example that I can follow? Thanks
     
  40. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    At first, try to project onto the whole car to be sure your code is actually working. After that, you can "filter" the unnecessary parts.

    For the projection via script, you may either use the provided bullet example scripts as a basis or the script provided here:
    http://forum.unity3d.com/threads/decal-system.141792/page-23#post-1914276

    If you don't have any script for this yet, I suggest you to use the posted script. When you have a working setup, I can help you to filter out everything that is not needed.
     
  41. dblincoeii

    dblincoeii

    Joined:
    Mar 4, 2015
    Posts:
    19
    Hello everyone. A couple of questions does this decal system allow you to project on meshes that are curved? I've seen some other systems but they are only for planar surfaces.
    Can you project holes? I.e. the part of the decal actually alpha's the underlying texture away?

    Also, is there a demo? I really want to make sure my $$ is going in the right direction.

    Thanks all.
     
  42. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I already replied you via pm, but I will still answer here in the case that someone else is interested.
    The Decal System allows projections on arbitrary shapes, both meshes and terrains. Additionally, there is support for skinned meshes, though that can be time consuming to tweak.
    There is no support to project holes. If you have a shader that allows you to create a hole in the underlying mesh, you may use it in combination with the Decal System.

    There was a free version of the Decal System, but it is not anymore available.
     
    dblincoeii likes this.
  43. dzkdes

    dzkdes

    Joined:
    Apr 18, 2015
    Posts:
    18
    Hi,

    I need to dynamically enable/disable projectors at runtime. However, the changes are not applied until I press the "Update All Projectors" button. So, what's the proper way to enable/disable projectors at runtime? Is there a corresponding api call to that button? If there is, isn't it an expensive call? (My decals (projectors) are defined once and their transform will never change). I expect the projectors to be finalised and I should be able to deal with them as if they are simple gameObjects (meshes). Isn't it possible? Thanks.
     
    Last edited: Apr 19, 2015
  44. dblincoeii

    dblincoeii

    Joined:
    Mar 4, 2015
    Posts:
    19
    Yes, thank you Dantus. Your answers are very helpful.
     
  45. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    All changes that take place at runtime need special attention and can't be achieved easily due to performance considerations. It would be a no brainer for me to provide such an API, but the performance would not be acceptable in many cases.
    If you modify projectors at runtime, you need to generate them at runtime. After that, you have a few possibilities. You may either remove to projector from the decals mesh, which means the computations you have made will be lost and will need to be performed again as soon as you want to activate the projector. Or you may use vertex colors to make the projector invisible without loosing the previously made computation.

    You may have a look at this script, which may give you a starting point at least:
    http://forum.unity3d.com/threads/decal-system.141792/page-23#post-1914276
     
  46. Exeneva

    Exeneva

    Joined:
    Dec 7, 2013
    Posts:
    432
    I'm trying to wrap my head around what happens here: http://tinyurl.com/oeh4c9u

    The rain is just a particle effect, but would decals be a viable way to create the puddles? They start out small and grow over time, and slowly recede over several turns also.
     
  47. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Decals might be used for that. The simplest approach from my point of view would be to make a relatively big projector and then swap the texture over time to animate the size change.
     
  48. Aurecon_Unity

    Aurecon_Unity

    Joined:
    Jul 6, 2011
    Posts:
    241
    Hi Dantus, just thought I'd let you know that you'll have another customer once you've sorted out the Unity 5 standard shader stuff - this plugin looks fantastic.
     
  49. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Thanks!
    Besides the obvious changes, there were some logical follow ups, that I missed upfront and will need to be handled as well.
     
  50. gn.gametorque

    gn.gametorque

    Joined:
    Feb 13, 2015
    Posts:
    26
    Dantus

    I need to use Decal System in my mobile game cars to attach vinyls? Or any other best suggestion for it.
    Is there any free version of this? I need to test it first if it works for my mobile game.