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
    I am pretty sure that I saw examples where this is done. Unfortunately, I can't find any links right now.
     
  2. Myzd

    Myzd

    Joined:
    Mar 5, 2013
    Posts:
    2
    Is ProjectWrapped a pro feature or am I doing something wrong :confused:

    Manual makes it look like it isn't but trying to use it results in "InvalidOperationException: This operation is only supported in Decal System Pro."
     
  3. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    You did nothing wrong! ProjectWrapped is not a pro feature. It was planned to become one, but then I changed my mind. I obviously didn't test it with the non pro version. I just resolved the issue in the internal code. I'll have to make some tests to be sure it works always, before I can upload it to the asset store.
    If you would like to test it already now, write me a PM with your email address.
     
  4. Myzd

    Myzd

    Joined:
    Mar 5, 2013
    Posts:
    2
    I'm just messing around with it for fun and got a bit confused, I'll just wait for it to be updated. Anyway, thanks for having a free version.
     
  5. lomaikabini

    lomaikabini

    Joined:
    Feb 28, 2014
    Posts:
    16
    hi all, i have a problem with decal system,when I shoot from gun - I have to leave a trail of bullets, i dont understand how i can get ProjectorRotation.....
    When i shoot at an angle (90%) - i see trail, but in other case - no(( you can see the problem in the picture $??????????.jpg
    Code (csharp):
    1. public void setTrail(Vector3 pos ,Vector3 normal, Collider coll)
    2.         {
    3.             // Collider hit.
    4.            
    5.             // Make sure there are not too many projectors.
    6.             if (m_DecalProjectors.Count >= m_MaximumNumberOfProjectors) {
    7.                
    8.                 // If there are more than the maximum number of projectors, we delete
    9.                 // the oldest one.
    10.                 DecalProjector l_DecalProjector = m_DecalProjectors [0];
    11.                 m_DecalProjectors.RemoveAt (0);
    12.                 m_DecalsMesh.RemoveProjector (l_DecalProjector);
    13.             }
    14.            
    15.             // Calculate the position and rotation for the new decal projector.
    16.             Vector3 l_ProjectorPosition = pos;
    17.             Quaternion l_ProjectorRotation = ProjectorRotationUtility.ProjectorRotation (coll.transform.forward,Vector3.up);//Quaternion.Euler (pos);//
    18.  
    19.             Debug.Log("l_ProjectorRotation = "+l_ProjectorRotation);
    20.            
    21.             TerrainCollider l_TerrainCollider = coll as TerrainCollider;
    22.             if (l_TerrainCollider != null) {
    23.                
    24.                 // Terrain collider hit.
    25.                
    26.                 Terrain l_Terrain = l_TerrainCollider.GetComponent <Terrain> ();
    27.                 if (l_Terrain != null) {
    28.                    
    29.                     // Create the decal projector with all the required information.
    30.                     DecalProjector l_DecalProjector = new DecalProjector (l_ProjectorPosition, l_ProjectorRotation, m_DecalProjectorScale, m_CullingAngle, m_MeshOffset, m_UVRectangleIndex, m_UVRectangleIndex);
    31.                    
    32.                     // Add the projector to our list and the decals mesh, such that both are
    33.                     // synchronized. All the mesh data that is now added to the decals mesh
    34.                     // will belong to this projector.
    35.                     m_DecalProjectors.Add (l_DecalProjector);
    36.                     m_DecalsMesh.AddProjector (l_DecalProjector);
    37.                    
    38.                     // The terrain data has to be converted to the decals instance's space.
    39.                     Matrix4x4 l_TerrainToDecalsMatrix = m_WorldToDecalsMatrix * Matrix4x4.TRS (l_Terrain.transform.position, Quaternion.identity, Vector3.one);
    40.                    
    41.                     // Pass the terrain data with the corresponding conversion to the decals mesh.
    42.                     m_DecalsMesh.Add (l_Terrain, l_TerrainToDecalsMatrix);
    43.                    
    44.                     // Cut and offset the decals mesh.
    45.                     m_DecalsMeshCutter.CutDecalsPlanes (m_DecalsMesh);
    46.                     m_DecalsMesh.OffsetActiveProjectorVertices ();
    47.                    
    48.                     // The changes are only present in the decals mesh at the moment. We have
    49.                     // to pass them to the decals instance to visualize them.
    50.                     m_DecalsInstance.UpdateDecalsMeshes (m_DecalsMesh);
    51.                    
    52.                     // For the next hit, use a new uv rectangle. Usually, you would select the uv rectangle
    53.                     // based on the surface you have hit.
    54.                     NextUVRectangleIndex ();
    55.                 } else {
    56.                     Debug.LogError ("Terrain is null!");
    57.                 }
    58.                
    59.             } else {
    60.                
    61.                 // We hit a collider. Next we have to find the mesh that belongs to the collider.
    62.                 // That step depends on how you set up your mesh filters and collider relative to
    63.                 // each other in the game objects. It is important to have a consistent way in order
    64.                 // to have a simpler implementation.
    65.                 MeshCollider l_MeshCollider = coll.GetComponent <MeshCollider> ();
    66.                 MeshFilter l_MeshFilter = coll.GetComponent <MeshFilter> ();
    67.                
    68.                 if (l_MeshCollider != null || l_MeshFilter != null) {
    69.                     Mesh l_Mesh = null;
    70.                     if (l_MeshCollider != null) {
    71.                        
    72.                         // Mesh collider was hit. Just use the mesh data from that one.
    73.                         l_Mesh = l_MeshCollider.sharedMesh;
    74.                     } else if (l_MeshFilter != null) {
    75.                        
    76.                         // Otherwise take the data from the shared mesh.
    77.                         l_Mesh = l_MeshFilter.sharedMesh;
    78.                     }
    79.                    
    80.                     if (l_Mesh != null) {
    81.                        
    82.                         // Create the decal projector.
    83.                         DecalProjector l_DecalProjector = new DecalProjector (l_ProjectorPosition, l_ProjectorRotation, m_DecalProjectorScale, m_CullingAngle, m_MeshOffset, m_UVRectangleIndex, m_UVRectangleIndex);
    84.                        
    85.                         // Add the projector to our list and the decals mesh, such that both are
    86.                         // synchronized. All the mesh data that is now added to the decals mesh
    87.                         // will belong to this projector.
    88.                         m_DecalProjectors.Add (l_DecalProjector);
    89.                         m_DecalsMesh.AddProjector (l_DecalProjector);
    90.                        
    91.                         // Get the required matrices.
    92.                         Matrix4x4 l_WorldToMeshMatrix = coll.renderer.transform.worldToLocalMatrix;
    93.                         Matrix4x4 l_MeshToWorldMatrix = coll.renderer.transform.localToWorldMatrix;
    94.  
    95.                         // Add the mesh data to the decals mesh, cut and offset it.
    96.                         m_DecalsMesh.Add (l_Mesh, l_WorldToMeshMatrix, l_MeshToWorldMatrix);                       
    97.                         m_DecalsMeshCutter.CutDecalsPlanes (m_DecalsMesh);
    98.                         m_DecalsMesh.OffsetActiveProjectorVertices ();
    99.                        
    100.                         // The changes are only present in the decals mesh at the moment. We have
    101.                         // to pass them to the decals instance to visualize them.
    102.                         m_DecalsInstance.UpdateDecalsMeshes (m_DecalsMesh);
    103.                        
    104.                         // For the next hit, use a new uv rectangle. Usually, you would select the uv rectangle
    105.                         // based on the surface you have hit.
    106.                         NextUVRectangleIndex ();
    107.                     }
    108.                 }
    109.             }
    110.         }
     
  6. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    If you want to compute the rotation, you need to know the impact direction. I assume this is either normal, or (-normal). In that case line 17 would be:
    Code (csharp):
    1. Quaternion l_ProjectorRotation = ProjectorRotationUtility.ProjectorRotation (normal, Vector3.up)
    or
    Code (csharp):
    1. Quaternion l_ProjectorRotation = ProjectorRotationUtility.ProjectorRotation (-normal, Vector3.up)
     
  7. lomaikabini

    lomaikabini

    Joined:
    Feb 28, 2014
    Posts:
    16
    it's dosn't work(
     
  8. lomaikabini

    lomaikabini

    Joined:
    Feb 28, 2014
    Posts:
    16
    Work's well when i use
    Code (csharp):
    1. Quaternion.LookRotation (pos, normal);
    But i have some problem with trail view $aaaa.jpg
    if i use
    Code (csharp):
    1. ProjectorRotationUtility.ProjectorRotation
    instead
    Code (csharp):
    1. Quaternion.LookRotation
    i don't see nothing
     
  9. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    As you are already using the bullet example code, you can see that it actually works. That code assumes that normal is the surface normal at with the impact takes place. It is not visible whether that is the case in your code, as I don't know what the normal direction is.

    If you use ProjectorRotationUtility.ProjectorRotation and you can't see the projected decals, it means that the parameters you are passing are wrong.

    Edit: Something else came to my mind. Could you tell me what the following values are:
    m_DecalProjectorScale
    m_CullingAngle
    m_MeshOffset

    What's essential is the value in the inspector. If those values are messed up, you may also get ugly results.
     
    Last edited: Mar 3, 2014
  10. lomaikabini

    lomaikabini

    Joined:
    Feb 28, 2014
    Posts:
    16
    m_DecalProjectorScale : 0.2 , 2 , 0.2
    m_CullingAngle : 80
    m_MeshOffset : 0
    I edit this parameters and it's dosn't help me)
     
    Last edited: Mar 3, 2014
  11. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I wrote the wrong one. Instead of the mesh offset, I need to know the decal projector offset. The other values are good.
     
  12. lomaikabini

    lomaikabini

    Joined:
    Feb 28, 2014
    Posts:
    16
    [SerializeField] private float m_DecalProjectorOffset = 0.5f;
     
  13. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    If you have also 0.5 in the inspector, you are simply passing wrong values to ProjectorRotationUtility.ProjectorRotation. What is the normal, how do you compute that value? Did you make sure it is computed in the same way as it happens in the bullet example code?
     
  14. lomaikabini

    lomaikabini

    Joined:
    Feb 28, 2014
    Posts:
    16
    hit i get from raycast
    Code (csharp):
    1. trailBullet.GetComponent<TrailBullet>().setTrail(hit.point,hit.normal, hit.collider);
    In bullet example code we used always Vector3.up, but it's do not suitable for me.
     
    Last edited: Mar 3, 2014
  15. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Did you try that one? I posted it two days ago.

    Code (csharp):
    1. Quaternion l_ProjectorRotation = ProjectorRotationUtility.ProjectorRotation (-normal, Vector3.up);
     
  16. lomaikabini

    lomaikabini

    Joined:
    Feb 28, 2014
    Posts:
    16
    I try it but it's dosn't always work, you can see this on the image
    $image.jpg
     
    Last edited: Mar 3, 2014
  17. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Could you explain what the red and blue lines are?
     
  18. lomaikabini

    lomaikabini

    Joined:
    Feb 28, 2014
    Posts:
    16
    red - normal , blue- shooting direction
     
  19. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    It is not directly visible from the screen shot how the mesh actually looks. Intuitively the normals on the left look wrong. Do you have Skype? I think we could pretty easily resolve it like that. My username is edelweissinteractive.
     
  20. lomaikabini

    lomaikabini

    Joined:
    Feb 28, 2014
    Posts:
    16
    thanks for the help)
     
  21. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    You're welcome!

    Just in case that anyone else is curious about what the issue was:
    Code (csharp):
    1. Vector3 l_ProjectorPosition = pos;
    This line caused the problem, because it didn't use the projector offset anymore.
     
  22. ounick

    ounick

    Joined:
    Aug 15, 2009
    Posts:
    7
    Hi,

    I need some help please.

    I am using your system with lightmapping. I am trying to use a single DecalsMesh and create a new DS_Decals instance for each new object I shoot. I am storing what instance each projector created is associated with.

    My problem is when I try to remove projectors from the mesh, I get:
    InvalidOperationException: Unable to remove a projector that is not part of this instance.
    Edelweiss.DecalSystem.GenericDecalsMesh`3[D,P,DM].RemoveProjector (.P a_Projector)


    I have tried re- initializing(DecalsMesh.Initialize) the DS_Decals instance that was initialized when the projector I want to remove was added, and then removing the projector but failed again.

    Please help. My goal is to not instantiate a new DS_Decals prefab every time I create a bullet decal like shown in the BulletLightmapExample. I am trying to create a instance for each object using separate lightmap coordinates while using the single DecalsMesh object. Is this possible?


    Thanks,
    Nick
     
    Last edited: Mar 4, 2014
  23. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Could you show me the code? It is just impossible to help without actual code in such a case.
     
  24. ounick

    ounick

    Joined:
    Aug 15, 2009
    Posts:
    7
    Here is basic code.. I tried to rip out all unrelated stuff so probably syntax errors. And sorry, couldn't figure out indention. :(

    Sorry, I know this is hard to read.


    Code (csharp):
    1.  
    2. //Simple Object to store projector and DecalTarget
    3. //We can get the DS_Decals instance from the target
    4. public class Decal{
    5.  
    6.     public DecalProjector projector;
    7.     public DecalTarget target;
    8.    
    9.     public void Clear()
    10.     {
    11.         projector = null;
    12.         target = null;
    13.     }
    14. }
    15.  
    16. //====================================================================//
    17.  
    18. //Component will be on target's Transform
    19. public class DecalTarget : MonoBehaviour{
    20.  
    21.     public Mesh mesh;
    22.     public int lightmapIndex;
    23.     public int lightmapOffset;
    24.  
    25.     private DS_Decals _instance;
    26.     private List<DecalProjector> pList;
    27.  
    28.     public DS_Decals decalsInstance()
    29.     {
    30.         get{
    31.         if(!_instance)
    32.             _instance = Instantiate (decalsPrefab) as DS_Decals;
    33.        
    34.            
    35.         return _instance;
    36.         }
    37.     }
    38.  
    39.     //Add projector to be added to List
    40.     public void AddProjector(DecalProjector dp){}
    41.  
    42.      //remove all projectors from this DS_Decals instance
    43.      void ClearDecals(){}
    44.  
    45.         void OnDestroy(){
    46.             ClearDecals();
    47.         }
    48.  
    49. }
    50.  
    51. //=====================================================================================//
    52.  
    53. //Manages decal adding/removing
    54. public class DecalManager{
    55.  
    56. private DS_Decals decalsInstance;
    57. //List for storing active Decal Objects
    58. private List<Decal> decalList = new List<Decal>();
    59. //List for recycling Decal Objects
    60. private List<Decal> _decalBin = new List<Decal>();
    61.  
    62. public void InitializeDecals(DS_Decals i)
    63. {
    64.     if(i == decalsInstance)return;
    65.    
    66.     _decalsMesh.Initialize (i);
    67.     decalsInstance = i;
    68. }
    69.  
    70. public void CreateDecal(Transform t, Vector3 pos, Quaternion rot)
    71. {
    72.     DecalTarget dTarget = t.GetComponent <GameDecalTarget> ();
    73.  
    74.     Mesh mesh = dTarget.mesh;
    75.    
    76.     if (mesh != null) {
    77.            
    78.    // Calculate the position and rotation for the new decal projector.
    79.     Vector3 pPosition = pos - (_decalProjectorOffset * -rot.eulerAngles.normalized);
    80.     Quaternion pRotation = rot;
    81.    
    82.     // Randomize the rotation.
    83.     Quaternion randomRotation = Quaternion.Euler (0.0f, Random.Range (0.0f, 360.0f), 0.0f);
    84.     pRotation = pRotation * randomRotation;
    85.  
    86.     Matrix4x4 worldToMeshMatrix = t.worldToLocalMatrix;
    87.     Matrix4x4 meshToWorldMatrix = t.localToWorldMatrix;
    88.  
    89.     Decal d;
    90.     //if we have unused Decal Object use it, else create one
    91.     if(_decalBin.Count > 0){
    92.         d = _decalBin[0];
    93.         _decalBin.RemoveAt(0);
    94.     }
    95.     else
    96.         d = new GameDecal();
    97.    
    98.     DS_Decals dInstance = dTarget.decalsInstance;
    99.    
    100.  
    101.     //store reference to current DS_Decals instance and initialize it
    102.     InitializeDecals(dInstance);
    103.  
    104.     //create new projector
    105.     DecalProjector dProjector = new DecalProjector(pPosition, pRotation, scale, cullAngle, meshOffset, decalIndex1, decalIndex2);
    106.    
    107.       //store reference to projector and DecalTarget on Decal
    108.         d.projector = dProjector;
    109.         d.target = dTarget;
    110.  
    111.    //add projector to DecalsMesh
    112.     _decalsMesh.AddProjector (dProjector);
    113.  
    114.     //store List of Decal objects
    115.     decalList.Add(d);
    116.  
    117.     // Add the mesh data to the decals mesh, cut and offset it.
    118.     _decalsMesh.Add (mesh, worldToMeshMatrix, meshToWorldMatrix);                        
    119.     _decalsMeshCutter.CutDecalsPlanes (_decalsMesh);
    120.     _decalsMesh.OffsetActiveProjectorVertices ();
    121.  
    122.     //check number of decals to see if oldest needs to be removed
    123.     CheckAndRemoveDecals();
    124.  
    125.     // The changes are only present in the decals mesh at the moment. We have
    126.     // to pass them to the decals instance to visualize them.
    127.     dInstance.UpdateDecalsMeshes(_decalsMesh);
    128.  
    129.     // Lightmapping
    130.     dInstance .DecalsMeshRenderers [0].MeshRenderer.lightmapIndex =  dTarget.lightmapIndex;
    131.     dInstance .DecalsMeshRenderers [0].MeshRenderer.lightmapTilingOffset =  dTarget.lightmapOffset;
    132. }
    133.  
    134. private void CheckAndRemoveDecals()
    135. {
    136.     if (_decalList.Count >= maxDecals) {
    137.            
    138.         GameDecal decal = decalList[0];
    139.         DS_Decals dInstance = decal.target.decalsInstance;
    140.                 DecalProjector removeMe = decal.projector;
    141.            
    142.         bool isActiveInstance = (decalsInstance == dInstance);
    143.        
    144.         //if not the active instance, initialize
    145.         if(!activeInstance){
    146.             InitializeDecals(dInstance);
    147.            
    148.                       //HERE LIES THE ERROR!!!
    149.             _decalsMesh.RemoveProjector (removeMe);
    150.                
    151.             dInstance.UpdateDecalsMeshes(_decalsMesh);
    152.        
    153.         }
    154.            //else, just remove the projector
    155.             //since the projector is removed from active DS_Decals instance
    156.             //the active DS_Decals instance will UpdateDecalsMeshes
    157.                 else
    158.                    _decalsMesh.RemoveProjector (removeMe);
    159.  
    160.            
    161.         //clear the Decal's references and store it to be re-used
    162.         decal.Clear();
    163.         _decalBin.Add(decal );
    164.  
    165.         //remove Decal from active Decals List
    166.         _decalList.RemoveAt (0);
    167.        
    168.     }
    169.  
    170. }
     
    Last edited: Mar 4, 2014
  25. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
  26. ounick

    ounick

    Joined:
    Aug 15, 2009
    Posts:
    7
    Just letting you know I put the tags in.

    Sorry about the spacing. I wrote it really quick in MS Notepad and then cut and pasted.
     
  27. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    There seems to be a misunderstanding about DecalsMesh. Whenever you initialize it, you start without any content. If you only have one projector in an existing DS_Decals instance and you want to remove it, you can initialize a your DecalsMesh object with the DS_Decals instance and then simply call UpdateDecalsMesh.
     
  28. ounick

    ounick

    Joined:
    Aug 15, 2009
    Posts:
    7
    Thanks for reply.

    OK. Since I do not have the source code version, could you clear up how a few things work. I have been reading but cant seem to get a clear understanding of possible scenarios.

    a) Can a single DS_Decals instance use multiple lightmaps for different projectors?
    b) Can you use multiple DS_Decal instances with the same DecalMesh (at the same time)
    c) if (b) is possible, are you able to remove projectors that belong to either one?

    I guess I know (b) is true from the BulletLightmapExample; but instead of creating a DS_Decal instance everytime you create a projector, can you use multiple projectors for each instance? (while using a single mesh)
     
    Last edited: Mar 4, 2014
  29. ounick

    ounick

    Joined:
    Aug 15, 2009
    Posts:
    7
    Nevermind.

    I guess I found a solution....Stop trying to share the ONE DecalsMesh. ie. Use a separate DecalsMesh for each DS_Decals created.

    Thanks though
     
  30. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Even if you found a solution, I still reply the questions:

    a) Each DS_Decals instance generates one mesh and each mesh can only use one lightmap.
    b) The DecalsMesh can keep the data of the projectors for one DS_Decals instance. If you want to keep that data, you can't use the DecalMesh for any other DS_Decals instance. On the other hand, if you don't need to keep the data, you can reuse the DecalsMesh object for any other DS_Decals instance.
     
  31. LeoTS

    LeoTS

    Joined:
    Jan 1, 2013
    Posts:
    18
    Hey Dantus,
    I was using your decal system a while ago, but stopped using it due to performance issues, it was dropping the fps a lot when calculating the decals on more complex meshes. My idea was to make it run asynchronously. Would it be possible to make it run in an other CPU Thread? It wouldn't be a problem if the decals needed a few seconds to appear.

    Thanks for taking your time :)
     
  32. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I am going to have a look at this over the weekend. That's a tough question :)
     
  33. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    I made several tests and it turns out that there are too many Unity specific function calls within the Decal System core that are not thread safe. If you could share a little more information, we may still find a solution and besides that, I will also have a closer look at what it needed to make the Decal System thread safe.
     
  34. Alex_Kun90

    Alex_Kun90

    Joined:
    Mar 19, 2014
    Posts:
    10
    Hello Unity community

    I'm a game developer who try to understand the implementation of Decals System's Script. My intention is find a way to execute "Update all Projectors" of game object with Decals by script. How I made it?

    Sorry for my bad english T_T , I'm Italian

    $Immagine.JPG

    I attached a Image on post for help you to understand the situation
     

    Attached Files:

    Last edited: Mar 19, 2014
  35. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    @Alex_Kun90

    Welcome to the forum!

    The "Update All Projectors" functionality is not available at runtime, because it is far too slow. That's why you have to handle updates on your own.
     
  36. Alex_Kun90

    Alex_Kun90

    Joined:
    Mar 19, 2014
    Posts:
    10
    How i made it? Can you explain me or post a simple and easy script that update my decals ?

    The my intention is istance a game Object that contain a DS_decals and have as childrens : a Decals mesh renderer , and two DS_Decals Projector.
    After the creation of this game object on scene , I want update all projectors of my main game object(that which is the DS_Decals). Thank you for the later answer ;D
     
  37. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Did you check the bullet example scripts? You can see there, how decals can be added, removed and modified at runtime.
     
  38. Alex_Kun90

    Alex_Kun90

    Joined:
    Mar 19, 2014
    Posts:
    10
    Yes, i see it , but It's a little bit complicated to understand. But if I have The projectors , can i update it immediatly instead to remove at start , after add and then update?
     
  39. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    That's not possible at runtime. As I wrote, you need to code it on your own (which will likely be comparable to the bullet example scripts), because the functionality you have in the editor would be far too slow at runtime.
     
  40. x_ming_x

    x_ming_x

    Joined:
    Jan 1, 2013
    Posts:
    46
    Hi Dantus
    thanks for making your decal system im using the free version at the mo and its umm sweet :)

    but im having a little problem maybe you could give me some pointers, ive modded the bullet example script so that i can pass in the collider and projector object (the muzzle gameobject a child of the gun which does the rotating ), ive got it working ok except the rotation when i rotate the gun the decals arent aligned right,

    where you use
    Quaternion l_ProjectorRotation = ProjectorRotationUtility.ProjectorRotation (Camera.main.transform.forward, Vector3.up);

    ive got
    Quaternion l_ProjectorRotation = ProjectorRotationUtility.ProjectorRotation (ProjectorObject.transform.forward, Vector3.up);

    any help much appreciated

    thanks
     
  41. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    You may try:

    Code (csharp):
    1. Quaternion l_ProjectorRotation = ProjectorRotationUtility.ProjectorRotation (ProjectorObject.transform.down, Vector3.up);
     
  42. x_ming_x

    x_ming_x

    Joined:
    Jan 1, 2013
    Posts:
    46
    Hi Dantus thanks for the help

    im afraid it didnt like "down"
    error CS1061: Type `UnityEngine.Transform' does not contain a definition for `down' and no extension method `down' of type

    let me explain more, i have the gun mounted facing forward (z axis), when it shoots straight down the z axis it works ok, if i rotate the gun to the right the decal only shows the right half of the image, if i rotate left it shows the left half of the decal, they appear in the correct location.. i will be mounting the gun on players or ai and even mounting them on vehicles so i need to get the rotation from the muzzle object directly
    i need to work out what to send the ProjectorRotationUtility, i tried to go round it but it didnt like that, im guessing it should be the "world" rotation of the muzzle but it when i give it that it doesnt show any decal.

    thanks
     
  43. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Sorry about the transform. It would probably be -up. However, this seems wrong anyway for you.
    If you are using the Decal System for bullets, you can think of the the first argument of ProjectorRotationUtility.ProjectorRotation as being the forward direction of the bullet.

    In the bullet example scripts, this line
    Code (csharp):
    1. Quaternion l_ProjectorRotation = ProjectorRotationUtility.ProjectorRotation (Camera.main.transform.forward, Vector3.up);
    will always produce the same result as that one
    Code (csharp):
    1. Quaternion l_ProjectorRotation = ProjectorRotationUtility.ProjectorRotation (l_Ray.direction, Vector3.up);
    The first argument is needed for the decal projection direction, while the second one is the up direction for the projection. Just using Vector3.up is usually sufficient as the second parameter. I hope this helps you to understand how the rotation can be computed.

    As a side note:
    I just added a ProjectorRotationUtility.ProjectorRotation method, that only requires the first parameter and the bullet examples were updated are are now using l_Ray.direction instead of the forward camera transform, because it is more understandable. Those modifications will be in the next version of the Decal System (Pro).
     
  44. atsakir

    atsakir

    Joined:
    Sep 28, 2012
    Posts:
    8
    Hi,

    I just started trying out your Decal System and I've been unsuccessful in projecting a Decal on a wall without z order fighting and consequent texture shearing.

    This is an example of the problem:
    $iU5lR9S.jpg

    This happens when the camera gets close to the decal. The shader for the decal is Decal->Mobile->Transparent Diffuse
    and the wall is Mobile->Bumped Diffuse. Only one directional light, no shadows, no lightmaps. Any ideas?
     
  45. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    Even if the shader was made to work around the z fighting as much as possible, it is still not possible to avoid it under all circumstances. One cause for z fighting can be that the underlying mesh has a shader that also uses the offset, like the decal shader. This should not be the case as you are using one of Unity's default shaders.
    Another cause can be the clipping planes of the camera. If the near clipping plane is very small and/or the far clipping is very high, it is more likely that you encounter z fighting. What are those values on your main camera?
    As there are not always workarounds, there is also the possibility to offset each decal projector separately to further reduce the flickering.

    Hope this helps
     
    Last edited: Mar 24, 2014
  46. atsakir

    atsakir

    Joined:
    Sep 28, 2012
    Posts:
    8
    Thank you for your quick response.

    The camera had the default 0.3-1000 near-far clip planes. I tried making the near plane smaller to 0.01 but that didn't fix it and I need the far to be 1000+ since this is for an open space project. The strange thing is that the problem appears to happen only when I run the project in the editor (and through Unity remote on the android device, but the built apk does not present it (at least as much, after the few tests I made). I guess I need to read up on offsetting the projectors, 'cause I haven't looked at that possibility yet.
     
  47. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    You turned the camera clipping in the wrong direction. Instead of 0.3-1000, you would need to set it to e.g. 0.5-500 to reduce the flickering. Though, that is likely too restrictive.
    Be aware, that the z fighting usually varies from device to device. As you have written about differences between the editor and Android devices, I remembered a discussion I have seen:
    http://forum.unity3d.com/threads/104133-Crazy-Z-Fighting-in-Editor

    The projector offset will move the generated mesh away from the underlying surface. It is just one value in the inspector you need to tweak.
     
  48. Alex_Kun90

    Alex_Kun90

    Joined:
    Mar 19, 2014
    Posts:
    10
    Hello Unity community , I'm also here , for varius problem abut decals.

    I'm making my code , lead the way of decals bullets example of the forum , and i'm reached to make this effect on the wall

    $BloodEpic.JPG

    But , now , my goal is to print my decals on the ground when I kill the enemys(How you see , my decals is a blood blatch)
    For this reasion I did a code that made a raycast shoot down vertically but there is a problem , and effect is this

    $Blood Fail.JPG

    and sometime when i kill certain enemy the decals istance always in the same position , that is this

    $blood srange.JPG

    My goal is to print the correct blood of firts immage in the ground in the same position when there was first the enemy that is kill next.



    The code of decals is this

    P.S:I want print the decals one time XD
    the variable posit is the position of enemy killed


     
    Last edited: Mar 27, 2014
  49. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    @Alex_Kun90, which version of the Decal System are you using? The computation for the projector rotation is wrong. In the most recent versions it is straight forward.
     
  50. Alex_Kun90

    Alex_Kun90

    Joined:
    Mar 19, 2014
    Posts:
    10
    My grapich member say it a few later , but how can i modify the projector rotation , can you say me the right way to rotate right the decal?