Search Unity

Easy Decal - Decals everywhere

Discussion in 'Assets and Asset Store' started by Sycoforge, Oct 28, 2014.

  1. yc960

    yc960

    Joined:
    Apr 30, 2015
    Posts:
    228
    Could you elborate on how the defer decal works? Can I just use any material? Let's say I want emissive property on my bullet wounds on realtime, would that be supported?
     
  2. Sycoforge

    Sycoforge

    Joined:
    Oct 6, 2013
    Posts:
    751
    The deferred decals basically behave like any other 3D object rendered using the deferred path: they write their maps into the different buffers. With the difference that the decals are projected in screen space.

    Not when using the screen space technique. With mesh decals this is of course possible. The (deferred) screen space decals need a very specialized shader.

    Currently, the deferred shader only writes to the normal and albedo buffer. Emission, roughness etc will be implemented in a future version.
     
    yc960 likes this.
  3. yc960

    yc960

    Joined:
    Apr 30, 2015
    Posts:
    228
    Is there an ETA on when that will become availible? And will there be support for custom materials, like ones made in shaderforge, etc?
     
  4. Sycoforge

    Sycoforge

    Joined:
    Oct 6, 2013
    Posts:
    751
    Hard to estimate... maybe 3-6 weeks. :)

    With screen space decals this will never be possible (technically) as the shader itself enables the screen space rendering.
    But you can use custom materials/shaders (e.g. shader forge shaders) using mesh decals (Box or Plane projection).
     
  5. TipsonMacGyver

    TipsonMacGyver

    Joined:
    Nov 3, 2016
    Posts:
    2
    Hello,
    I am instantiating "Bullet Hole" prefab that comes with the asset during run time from a script like so: EasyDecal.Project( prefab, transform.position, Quaternion.identity ). I've set Fade Out to true, Lifetime to 4, Fadeout Time to 20 and left the default Alpha Curve (keys (0,1) and (1,0)). The decal stays visible for the first 4 seconds and then fades out in about 1 sec even tho I have the fade out time set to 20. Is there something I'm doing wrong?
    I'm using Easy Decal version 1.6.2 with unity 5.4.1f1. I've tried it with different decals, different fade out timers, with and without pooling system, different alpha curves, and setting everything from a script. But the decal always seems to disappear in about 1 second when the fade out starts, if instantiated from a script.
     
  6. Sycoforge

    Sycoforge

    Joined:
    Oct 6, 2013
    Posts:
    751
    Thank you for reporting this issue. We successfully reproduced it. This will be fixed with Patch 3 for version 1.6.2.

    As a workaround you could scale the value range to about 10% of the original range using the curve.

    ed_fade_curve.jpg

    Please let me know if this works for you.
     
  7. sburgoon

    sburgoon

    Joined:
    Jan 29, 2012
    Posts:
    38
    Can anyone confirm this decal system works with Xbox One/Windows Store? I don't mind having to fix up some code as long as its not locked behind a dll I can't fix ;)
     
  8. Sycoforge

    Sycoforge

    Joined:
    Oct 6, 2013
    Posts:
    751
    Unfortunately we have no reliable data for the platforms our plugins get actually used. We have reliable data for the following plaforms: MacOS, iOS, Windows, PS3/PS4 and WiiU. So I don't see any reasons that it shouldn't work on the XBOX :)
     
  9. calebc01

    calebc01

    Joined:
    Jul 21, 2015
    Posts:
    62
    I'm using my own object pool, and I don't want to instantiate anything at runtime. Is there an alternative ProjectAt function that uses a pre-existing decal and simply changes its parameters? Also, I don't want it to auto destroy itself after it fades out - I'll need to receive an event indicating it is faded out so I can put it back in the object pool.
     
  10. Sycoforge

    Sycoforge

    Joined:
    Oct 6, 2013
    Posts:
    751
    Yes sure! A possible procedure could be the following:
    1. [On the recycled decal]
    2. Set the new transform values (position, rotation, scale)
    3. Call the Reset() method on the decal instance -> decal.Reset(true); // Passing true will unbake the decal geometry
    4. Call the LateBake() method to bake the geometry after one projection cycle.
    Point 4 of the above procedure only applies to mesh decals. When working deferred decals you can skip the baking parts.

    The EasyDecal component exposes the following events which can be used for syncing and/or custom pooling method hooking:

    Code (CSharp):
    1.  
    2. EasyDecal.OnFadedIn // Gets called when the decal has completely faded out.
    3. EasyDecal.OnFadeOutStarted // Gets called when the decal has started to fade out.
    4. EasyDecal.OnFadedOut // Gets called when the decal has completely faded out.
    5.  
    You probably want to hook to the OnFadedOut event to initiate the recycle process of the current decal instance. You could also delegate the event handling to a controller class as the event's argument is always the decal producing the event (sender).

    Also make sure to enable the Don't Destroy option in the Constraints tab.

    Please let me know if that was what you were looking for. :)
     
  11. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Hi.

    I just upgraded to Unity 5.5 RC1 and got 2 shader compile errors.

    Shader error in 'Easy Decal/ED Standard': 'MainLight': no matching 1 parameter function at line 96 (on d3d11)

    Compiling Vertex program with DIRECTIONAL VERTEXLIGHT_ON
    Platform defines: UNITY_ENABLE_REFLECTION_BUFFERS UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BOX_PROJECTION UNITY_SPECCUBE_BLENDING SHADER_API_DESKTOP

    and the same error for directx 9

    Anyone else seen this?
     
  12. Sycoforge

    Sycoforge

    Joined:
    Oct 6, 2013
    Posts:
    751
    The shaders causing this error are Unity Standard shader ports from the early Unity 5 days. These shaders will be removed from the package in the near future. They may resist in the package for backward compatibility reasons, but sooner or later they will be unsupported (see Unity 5.5 :)).

    Patch 1 (downloadable from our website) for version 1.6.2 comes with replacement shaders making the old ones obsolete and ready for Unity 5.5.

    How to upgrade


    Delete the following shaders from your project:

    • "Easy Decal/ED Standard (Specular setup)" -> File: "nu Assets\Easy Decal\Shader\StandardSpecular.shader"
    • "Easy Decal/ED Standard" -> File: "nu Assets\Easy Decal\Shader\EDStandard.shader"
    And use one of the new shaders:

    • "Easy Decal/ED Standard (Specular, Vertex Alpha)"
    • "Easy Decal/ED Standard (Specular, Vertex Alpha, Cutoff)"
    • "Easy Decal/ED Standard (Metallic, Vertex Alpha)"
    • "Easy Decal/ED Standard (Metallic, Vertex Alpha, Cutoff)"
    Please let us know if this worked for you!
     
    DonLoquacious likes this.
  13. Rob21894

    Rob21894

    Joined:
    Nov 21, 2013
    Posts:
    309
    Bought your Easy Decal pack...

    It's not letting me set it so it's not baked at run time,
    Not letting me change the material at runtime (probably because automatically going to baked)
    Code (CSharp):
    1.                 decalPrefab.GetComponent<EasyDecal>().DecalMaterial = bloodSplats[randomnum];
    2.                 decalPrefab.GetComponent<EasyDecal>().LateBake();
    3.                 EasyDecal.ProjectAt(decalPrefab,hit.collider.gameObject, hit.point, hit.normal);
    Why can't i change the material at runtime? doing blood, I need variations...
     
  14. Sycoforge

    Sycoforge

    Joined:
    Oct 6, 2013
    Posts:
    751
    Materials can only be changed when the decal has its Source Mode property set to Material. When the Source Mode is set to Atlas, the material used to render the decal's geometry is determined by the current atlas object.

    I strongly recommend to use an atlas to give the decal some variations. It's more convenient to maintain and better for the overall performance.

    When in Material mode:
    Code (CSharp):
    1. using ch.sycoforge.Decal;
    2. using UnityEngine;
    3.  
    4. public class MaterialChange : MonoBehaviour
    5. {
    6.     public Material[] materials;
    7.  
    8.     EasyDecal decal;
    9.  
    10.     private void Start()
    11.     {
    12.         decal = GetComponent<EasyDecal>();
    13.  
    14.         InvokeRepeating("ChangeMaterialIndex", 1, 3);
    15.     }
    16.  
    17.     private void ChangeMaterialIndex()
    18.     {
    19.         if (materials.Length == 0) { return; }
    20.  
    21.         int i = Random.Range(0, materials.Length - 1);
    22.         Material randomMat = materials[i];
    23.  
    24.         decal.DecalMaterial = randomMat;
    25.     }
    26. }
    27.  
    When in Atlas mode:

    Code (CSharp):
    1. using ch.sycoforge.Decal;
    2. using UnityEngine;
    3.  
    4. public class AtlasIndexChange : MonoBehaviour
    5. {
    6.     EasyDecal decal;
    7.  
    8.     private void Start()
    9.     {
    10.         decal = GetComponent<EasyDecal>();
    11.  
    12.         InvokeRepeating("ChangeAtlasIndex", 1, 3);
    13.     }
    14.  
    15.     private void ChangeAtlasIndex()
    16.     {
    17.         decal.SelectRandom();
    18.     }
    19.  
    20. }
    Please let me know if the problem's solved now.
     
  15. Rob21894

    Rob21894

    Joined:
    Nov 21, 2013
    Posts:
    309
    The Source mode is set to Material, It is changing the material but it's still showing "None" so a Pink box, appears.

    Although in editor, when i click on the Prefab it changes to the blood???

    Here's a gif of it happening
    https://gyazo.com/d7be525d10b02fc9a4d44cfa697c4ff6

    Why is this happening?
     
  16. Sycoforge

    Sycoforge

    Joined:
    Oct 6, 2013
    Posts:
    751
    I missed that you tried to change the material on your prefab. You have to change the material on the instance (clone) of the prefab that gets returned by the API method (ProjectAt(...)).

    Something like the following:

    Code (CSharp):
    1. using ch.sycoforge.Decal;
    2. using UnityEngine;
    3.  
    4. public class MaterialChange : MonoBehaviour
    5. {
    6.     public Material[] Materials;
    7.     public EasyDecal DecalPrefab;
    8.  
    9.     private EasyDecal decalInstance;
    10.  
    11.     void Update()
    12.     {
    13.         if (Input.GetMouseButtonUp(0))
    14.         {
    15.             Instantiate();
    16.         }
    17.     }
    18.  
    19.     private void Instantiate()
    20.     {
    21.         // Shoot a ray thru the camera starting at the mouse's current screen space position
    22.         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    23.         RaycastHit hit;
    24.  
    25.         // Check if ray hit something
    26.         if (Physics.Raycast(ray, out hit, 200))
    27.         {
    28.             // Instantiate the decal prefab according the hit normal.
    29.             // The returned decal is a clone of the specified decal prefab
    30.             EasyDecal instance = EasyDecal.ProjectAt(DecalPrefab.gameObject, hit.collider.gameObject, hit.point, hit.normal);
    31.  
    32.             // Hook to OnFadedOut event to recycle
    33.             instance.OnFadedOut += instance_OnFadedOut;
    34.         }
    35.     }
    36.  
    37.     private void instance_OnFadedOut(EasyDecal instance)
    38.     {
    39.         ChangeMaterialIndex(instance);
    40.     }
    41.  
    42.     private void ChangeMaterialIndex(EasyDecal decal)
    43.     {
    44.         if (Materials.Length == 0) { return; }
    45.  
    46.         int i = Random.Range(0, Materials.Length - 1);
    47.         Material randomMat = Materials[i];
    48.  
    49.         decal.DecalMaterial = randomMat;
    50.     }
    51. }
    The script above changes the material after the decal dies. Meaning that when the decal gets recycled (e.g. pooling system) it will have a random material applied.

    You could also change the material right after instantiation like this:

    Code (CSharp):
    1. using ch.sycoforge.Decal;
    2. using UnityEngine;
    3.  
    4. public class MaterialChange : MonoBehaviour
    5. {
    6.     public Material[] Materials;
    7.     public EasyDecal DecalPrefab;
    8.  
    9.     private EasyDecal decalInstance;
    10.  
    11.     void Update()
    12.     {
    13.         if (Input.GetMouseButtonUp(0))
    14.         {
    15.             Instantiate();
    16.         }
    17.     }
    18.  
    19.     private void Instantiate()
    20.     {
    21.         // Shoot a ray thru the camera starting at the mouse's current screen space position
    22.         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    23.         RaycastHit hit;
    24.  
    25.         // Check if ray hit something
    26.         if (Physics.Raycast(ray, out hit, 200))
    27.         {
    28.             // Instantiate the decal prefab according the hit normal.
    29.             // The returned decal is a clone of the specified decal prefab
    30.             EasyDecal instance = EasyDecal.ProjectAt(DecalPrefab.gameObject, hit.collider.gameObject, hit.point, hit.normal);
    31.  
    32.             ChangeMaterialIndex(instance);
    33.         }
    34.     }
    35.  
    36.     private void ChangeMaterialIndex(EasyDecal decal)
    37.     {
    38.         if (Materials.Length == 0) { return; }
    39.  
    40.         int i = Random.Range(0, Materials.Length - 1);
    41.         Material randomMat = Materials[i];
    42.  
    43.         decal.DecalMaterial = randomMat;
    44.     }
    45. }
    46.  
     
  17. tom_bb

    tom_bb

    Joined:
    Sep 21, 2016
    Posts:
    8
    I'm looking into decal systems for our current project, we have a set of specific requirements and I was wondering if you could confirm if this system could fulfill them?

    1) Can place decals at runtime
    2) Can place them in a permanent line on an object (think a table saw cutting some wood, leaving a thin line behind)
    3) Can stay placed if the object is changed dynamically (the mesh updates)
    4) Doesn't require the mesh to be unwrapped (the mesh is created procedurally)

    Thanks, this system does look promising! :)
     
  18. Sycoforge

    Sycoforge

    Joined:
    Oct 6, 2013
    Posts:
    751
    Yes.

    Technically yes. But the plugin comes not with native support for this use case. Even tough Patick from Vertigames has built an awesome road system on top of Easy Decal. We have plans to integrate support for projected line decals, but there's no ETA for this.

    Yes. But the system has no way to observe the surrounding geometry. So you have to keep track of geometry changes and once you have detected one unbake and project the decal again.

    The other way would be to use deferred decals, those dont care about the underlying geometry. :)

    There's no need for UVs. The decals handle their UV independently.

    I hope this was helpful. :)
     
  19. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    700
    @nu-assets
    Hi,

    Whats the performance like on iOS?

    Also I'd like to use it for blood splatter effects on the wall behind the enemy, as I use UVPaint for the effects on the skinned mesh but would like to raycast through the enemy to the wall then use Easy Decal to project the blood splatter on the wall.

    Also can the decal be animated, blood flowing down the wall before fading it out?

    Thanks.
     
    Last edited: Dec 5, 2016
  20. Sycoforge

    Sycoforge

    Joined:
    Oct 6, 2013
    Posts:
    751
    The performance mainly depends on the complexity of the geometry that actually receive the decal. The performance of the deferred decals however is constant. That means when using the deferred screen space projection the performance is very predictable, while with mesh decals it can vary.

    Basically you have two supported ways to animate the decal
    1. animate using texture sheets. (see here)
    2. animate the transform itself. (see here)
     
  21. tolosaoldfan

    tolosaoldfan

    Joined:
    Sep 14, 2012
    Posts:
    92
    Hello,
    When the 1.6.5 with support of skinnedmeshes will be available ? We need it within 2 weeks..
    Thanks,
     
  22. Sycoforge

    Sycoforge

    Joined:
    Oct 6, 2013
    Posts:
    751
    We'll maybe can include an experimental skinned mesh projector version in 1.6.4. But it's not recommended to ship an early version with a final product build.
     
    tolosaoldfan likes this.
  23. Sycoforge

    Sycoforge

    Joined:
    Oct 6, 2013
    Posts:
    751
    Version 1.6.3 available for download.

    Changelog

    Features

    • Shaders: Added two SSD masking shaders (Unity 5.3+).

    Fixes
    • Shaders: Fixed issue with AO map reading.
    • SSD: Fixed null-ref when the decal owner gets destroyed and the decal itself not.
    • Editor: Fixed thumbnail clipping issue in Unity Personal.
    • Editor: Fixed too dark UI background when working in linear color space.

    Changes
    • Shader: Changed FragmentInputDSSD struct.
     
  24. tolosaoldfan

    tolosaoldfan

    Joined:
    Sep 14, 2012
    Posts:
    92
    Thanks for your quick reponse.
    It's Ok, it will be a beta version on our side also. When do you think you can provide a 1.6.4 ?
     
  25. Sycoforge

    Sycoforge

    Joined:
    Oct 6, 2013
    Posts:
    751
    We are trying to meet the deadline on 23th December. But as you probably know, deadlines and devs are not known for being best friends. :)

    We are working hard to meet the date!
     
    Stormy102 and ZJP like this.
  26. Marked

    Marked

    Joined:
    Feb 24, 2015
    Posts:
    32
    Hey!

    I get the following error with the latest version from the Asset store. Using Unity 5.5
    Failed setting triangles. Some indices are referencing out of bounds vertices. IndexCount: 49551, VertexCount: 46
    UnityEngine.Mesh:set_triangles(Int32[])
    ch.sycoforge.Decal.Projectors.Geometry.DynamicMesh:ConvertToMesh(Mesh)
    ch.sycoforge.Decal.EasyDecal:AddDynamicMesh(DynamicMesh)
    ch.sycoforge.Decal.Projectors.BoxProjector:project()
    ch.sycoforge.Decal.EasyDecal:Update()

    I only get in my scene while using the box projection, the plane projection works fine. Any idea what may cause it ?

    Thanks !
     
  27. Sycoforge

    Sycoforge

    Joined:
    Oct 6, 2013
    Posts:
    751
    The Box projector uses an optimization for small and medium sized decals. But the said optimization breaks with large scale factors. The upcoming projection system will automatically switch the internal projection mode when a certain scale factor has been reached. The new projection system will most likely be part of the version 1.6.5.
     
    Marked likes this.
  28. GlitchedPolygons

    GlitchedPolygons

    Joined:
    Jun 18, 2013
    Posts:
    210
    The performance is basically horrible with runtime placed decals... look at that messed up GC! 97.5kb of garbage produced every frame...
    Screen space decals seem to be okay if you spawn (from a pool) not more than ~20 decals. And mesh based decals (box projection) are even worse, depending on the complexity of their underlying geometry (since, according to profiler, the entire mesh data arrays are being copied into the EasyDecal methods).
    Do you have any ETA on when this is going to be optimized for actual real runtime usage? The GC running every 2 seconds with 10ms of CPU overhead is kind of... yeah... :/

    [EDIT] Just noticed that you were among the selected Swiss Indie Game-Dev studios at the GameZ Festival in Zürich last month! That's so cool! :) Grüessech, fellow Swiss developer! :>
     
    Last edited: Dec 19, 2016
    hakankaraduman likes this.
  29. Sycoforge

    Sycoforge

    Joined:
    Oct 6, 2013
    Posts:
    751
    The screen space decals and deferred decals are still in their beta cycle. But we are working on continuous improvement. When adding a new feature to the framework we basically follow the steps below:

    First Iteration
    Include the feature in its first stable state (and officially mark as beta). This is basically the proof of concept and allows the user to get used to it.

    Second Iteration
    Functional freeze. Improve performance and stability and fix minor bugs.

    Third Iteration
    Add missing functionality based on user feedback. Functional design decisions, data structures and workflow directives could be changed here.

    The 2nd and 3rd iterations could be passed several times.

    The meshless decal system is currently in the third iteration and one of the major improvements will be an observer system that will track decals and only refresh buffers when needed. This will boost the performace for screenspace decals around 50%.

    The Box Projector needs the geometry information of its surrounding objects to cut the geometry along six planes. Each call to Mesh.vertices (normals, tangents, etc) will actually copy said array (and of course let your heap grow). The solution here would be a direct access to the unmanaged address pointer holding the geometry data in the native universe. But unfortunately these pointers are not exposed by Unity.

    But once the mesh decals are created/spawned/projected (and baked) they should only produce a small overhead for managing its life cycles (fading etc).

    23 bullet hole decals shot to a wall (at creating time the frame time looks similar to yours).
    ed_profiler.jpg

    But as you said mesh decals are not for free performance-wise. And setting up a game environment is always a balancing act between:

    combining to mega meshes to reduce draw calls
    and
    craeting spatial mesh groups to enhance prebaked occlusion culling and reduced projection time for mesh decals.

    Hard to guess an arrival time here. Next big change will be the skinned mesh projector. But of course we always try our best to keep times as short as possible.

    Beste Grüsse aus Zürich :)
     
    GlitchedPolygons likes this.
  30. GlitchedPolygons

    GlitchedPolygons

    Joined:
    Jun 18, 2013
    Posts:
    210
    Heyy! Thank you SO much for the extensive and detailed reply :D
    I really appreciate this high level of quality in customer support.
    And yeah... I know... it would be so much better if Unity granted access to the raw geometry data :\
    I've been there before too. Unity in general doesn't like to expose much stuff to the user API. And user is really the keyword here: UT still thinks that all of us are just end-users... but in reality, most of us who take this seriously are developers... we develop stuff, so we sometimes need access to more exotic stuff than others (or artists, for that matter). But yeah, I'm talking to a wall I guess.

    You make sure to keep up the good work, your product is of high quality! I also wrote a review on the store page :> U we dr mau hiuff bruuchet bim programmyere, just tell me ;) I always like to help :)
     
  31. cubedparadox

    cubedparadox

    Joined:
    Sep 16, 2014
    Posts:
    16
    Your asset is listed as being 'vr ready', does this mean that you have forward rendered decals working? All the decal solutions I've tried have relied on deferred rendering passes to function. Also, does this plugin support normal map only decals? Thanks!
     
  32. Sycoforge

    Sycoforge

    Joined:
    Oct 6, 2013
    Posts:
    751
    Please excuse the late reply! For some reason our hoster changed its spam weighting policy and all forum notifications have now a spam score of 7.5 and thus disappeared somewhere in the spam-folder-nirvana.

    Thank you very much for your nice words and your review! We very much appreciate your support. :)

    Merci! :)
     
  33. Sycoforge

    Sycoforge

    Joined:
    Oct 6, 2013
    Posts:
    751
    Please excuse the late reply!

    Yes. The mesh based decals are working in both forward and deferred rendering path.

    Normal-only decals (aka Deferred Spreen Space Decals) need the deferred rendering path as the implementation heavily relies on Unity's G-buffer.

    I hope this was helpful! :)
     
  34. Sycoforge

    Sycoforge

    Joined:
    Oct 6, 2013
    Posts:
    751
    Version 1.6.4b available for download.

    Please note that this is a beta release.

    Changelog

    Features

    • Projector: Added added basic support for skinned meshes (Pre-alpha).
    • Content: Added new texture atlas (sci-fi icon decals).

    Fixes
    • Editor: Duplicated decal now properly inherits the parent transform of the original.

    Changes
    • Core: Exposed shared mesh property.
    • Core: Unsealed DynamicMesh class.
    • Shader: Added additional color tint input to Multiply shader.
    • Shader: Removed early Unity 5 shader ports from package (for proper Unity 5.5 support).
    • Box Projector: Improved potential candidate selection for Box Projector.
    • Box Projector: Reduced GC allocation for small and medium scaled decals.
    • Box Projector: Changed space conversion to speed up projection (Performance gain: ~15%).
     
    hopeful likes this.
  35. Sycoforge

    Sycoforge

    Joined:
    Oct 6, 2013
    Posts:
    751
  36. doq

    doq

    Joined:
    Aug 17, 2015
    Posts:
    121
    Hi,
    I'm having trouble with the random option when the Source Mode is set to Atlas. I've checked the Random option, but when I instantiate my prefab it always selects the 0 index for AtlasRegionIndex, setting it directly has no effect and RandomIndexEnabled is true.

    I'm trying to display a random bullet hole from my decal atlas at runtime, and I'm using the Instantiation method.

    Also, is there a way to adjust the rendering order of the decals? Since I'm pooling bullet holes, I'd like them to stack on top of each other when activated.

    Thanks!
     
    Last edited: Jan 1, 2017
  37. wilco3d

    wilco3d

    Joined:
    Feb 15, 2015
    Posts:
    6
    Hello,

    Would it be possible for the decal when fading out / destroying, to check to see if their parent gameObject is active?

    I'm using it for blood splatters, which is working great - but if the player/ai dies and goes inactive, when the decal tries to fadeout/destroy it errors.


    Thanks!
     
  38. Sycoforge

    Sycoforge

    Joined:
    Oct 6, 2013
    Posts:
    751
    Hi,

    Basically you have two different ways of doing this. Either you configure the behaviour directly on your prefab (inspector UI) and then just use your custom instantiation method to create a clone. This way you don't have to worry about calling any additional methods.

    Or just by calling the SelectRandom() method on the actual instance returned by your custom instantiation method.

    Code (CSharp):
    1.        
    2.            if (Input.GetMouseButtonUp(0))
    3.             {
    4.                 // Shoot a mouseRay thru the camera starting at the mouse's current screen space position
    5.                 Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    6.                 RaycastHit hit;
    7.  
    8.                 // Check if mouseRay hit something
    9.                 if (Physics.Raycast(ray, out hit, 200))
    10.                 {
    11.                     EasyDecal decal = CustomInstantiator.Project(DecalPrefab.gameObject, hit.collider.gameObject, hit.point, hit.normal, Vector3.zero);
    12.                     decal.SelectRandom();
    13.                 }
    14.             }
    15.  
    Your custom instantiator code could look like the following:

    Code (CSharp):
    1. using ch.sycoforge.Decal;
    2. using System;
    3. using UnityEngine;
    4.  
    5. public static class CustomInstantiator
    6. {
    7.     public static EasyDecal Project(GameObject decalPrefab, GameObject parent, Vector3 position, Vector3 normal, Vector3 scale)
    8.     {
    9.         Quaternion rotation = Quaternion.FromToRotation(Vector3.up, normal);
    10.  
    11.         EasyDecal decal = decalPrefab.GetComponent<EasyDecal>();
    12.  
    13.         if (decal == null)
    14.         {
    15.             throw new Exception("The prefab you want to instantiate has no 'EasyDecal' script appended.");
    16.         }
    17.  
    18.         EasyDecal clone = ((GameObject)GameObject.Instantiate(decalPrefab, position, rotation)).GetComponent<EasyDecal>();  
    19.         clone.LateBake();
    20.  
    21.         if (parent != null)
    22.         {
    23.             clone.gameObject.transform.SetParent(parent.transform);
    24.         }
    25.  
    26.         return clone;
    27.     }
    28. }
    Please don't forget to call LateBake() in your custom code.


    As the decals become just normal meshes after projection the same sorting rules get applied to them as to every other Unity mesh object. Basically you have (again) two different ways to choose from: Offset the rendering order in the shader or offset the decal using the Distance property of the specific (unbaked) decal instance.

    Offsetting the decal in the shader will prevent the decal from being auto-batched by Unity.

    The public API reference can be found here.

    I hope this was helpful! :)
     
    Last edited: Jan 2, 2017
  39. Sycoforge

    Sycoforge

    Joined:
    Oct 6, 2013
    Posts:
    751
    Hi,
    Thank you for the report. :)
    The active check will be changed to activeInHierarchy before fading out. This fix will be part of the next patch release.
     
  40. doq

    doq

    Joined:
    Aug 17, 2015
    Posts:
    121
    The custom instantiator code is basically doing what I'm already doing. I did try calling SelectRandom() and I did try setting the Random option in the prefab. I have two bullet impacts that I what to select between, but it's not working. Can I send you my sample project?
     
  41. Sycoforge

    Sycoforge

    Joined:
    Oct 6, 2013
    Posts:
    751
    Yes sure. Could you please send it to our support mail or attach it in a PM?
     
  42. doq

    doq

    Joined:
    Aug 17, 2015
    Posts:
    121
    Ok thanks I tried sending a request through your website, but I just sent the project via the support email as well. Thanks!
     
  43. Sycoforge

    Sycoforge

    Joined:
    Oct 6, 2013
    Posts:
    751
    We'll take a good look at it and come back to you as soon as possible.
     
  44. Sycoforge

    Sycoforge

    Joined:
    Oct 6, 2013
    Posts:
    751
    Thank you for providing the test project. There was an issue with the random index generation when the atlas has only two elements.

    This issue has been fixed in the latest patch of version 1.6.4 which is downloadable from our website.

    Thank you very much for your report! :)
     
  45. doq

    doq

    Joined:
    Aug 17, 2015
    Posts:
    121
    Looks good. Thanks!
     
  46. doq

    doq

    Joined:
    Aug 17, 2015
    Posts:
    121
    I forgot to mention. It looks like the new dll is throwing a warning about using obsolete Unity APIs. I don't recall this happening before.
     
  47. Sycoforge

    Sycoforge

    Joined:
    Oct 6, 2013
    Posts:
    751
    You can safely ignore this message. That's just because the library provided on our website is a generic Unity 5.3+ version. It's fully functional and supported on Unity 5.4 and 5.5.

    The only change is that some of the new features introduced in version 1.6.4 are not supported in Unity 5.2 and below.
     
  48. LunaTrap

    LunaTrap

    Joined:
    Apr 10, 2015
    Posts:
    120
    Why are you using SSD projection for bullet holes? im using the plane projector with resolution set to 0, since bullet holes are so small it does not matters if in corners it does not gets projected.



    I get only 1 to 2kb of GC when the decal is spawned, and after baking it, it wont take much at all, are you baking the decals?
     
  49. SimonsCat

    SimonsCat

    Joined:
    Mar 11, 2015
    Posts:
    49
    Hi,

    in connection with raphu604 and LunaTrap I have a thing to say too:

    We are using Box projection and spawn many decals (RTS game). It works fine, but we had to adjust the shaders in order to prevent clipping with the Unity terrain. We use the stencil in combination with modified ED shaders in order to achieve the results. But the problems we have now are the memory allocations.

    It is somehow logic that there are some allocations when spawning a new decal, or even when using a decal from the pool. As far as we know getting the decal data (vtx, ...) always allocates memory.
    However, I would like to know how do you perform fading. After the decal gets baked the alloc are 0 but once it starts to fade the allocations go crazy again. Spawning 10-20 decals in cycles and fading them out gives a bad performance because of that.
    So, what do you exactly fade when fading out the decal? Vertex color? Material _Color alpha? Is it possible to do the fade without allocations?

    The test case with around 37 decals, all Box proj, creates around 1,1MB of allocations per frame when fading out...

    Thanks.
     
  50. Sycoforge

    Sycoforge

    Joined:
    Oct 6, 2013
    Posts:
    751
    Unfortunately, we have no access to the LOD changes in the highlevel terrain API, thus we are not able to detect geometry changes and not at least because this is also view-depended. Unity is sometimes a little bit stingy when it comes to exposing some more API functionality. :)

    Unfortunately, this is true. The mesh data properties return an arry copy of the native data.

    Currently, the fading information gets passed using the vertex colors of the current instance. We decided to encode the opacity state in the geometry to allow Unity to automatically collect suitable** decals for dynamic batching.

    We are working on a complete redesign of the projection core. The new design will allow better runtime performance and less runtime allocations, at the expense of an overall slightly bigger memory footprint.