Search Unity

pmjo's Fast Decals and Fast Spawn for Unity3d

Discussion in 'Works In Progress - Archive' started by pmjo, Sep 17, 2013.

  1. pmjo

    pmjo

    Unity Technologies

    Joined:
    Sep 17, 2013
    Posts:
    245
    Hi

    I really love Unity3d and I have been creating a lot of extensions to it, mainly for my new zombie game. Since the game release date still seems to be unknown I am planning to share a couple of them on the Asset Store. Both extensions are created mobile devices in mind so they should perform really well. The development of my game is a bit stuck at the moment, mainly for the reason that I don't have enough room to do motion capture, even I have the Ipisoft equipment for it. I have a lot code ready but really can't continue without decent animations..

    Here is a small description of the extensions:

    Fast Decals

    $big.png

    Fast Decals allows the game to render a large amount of decals - such as blood splatters and blob shadows - at a blazing fast speed, with a single OpenGL draw call. It also provides an automatic aging mechanism, which slowly fades away old decals when new ones are created. Fast Decals is best suited to games with a small world, such as tower defense games etc. Eventhough Fast Decals was created for rendering decals nothing stops you from using it for tile based game rendering or sprite rendering. Click here for more about Fast Decals!

    Fast Spawn

    $big.png

    Fast Spawn allows the game to spawn game objects without any significant loss in performance. It also gives you an easy way to manage and access your prefabs. The high performance spawning is based on keeping a user selected amount of pre-instantiated/deactivated game objects in memory. The spawn objects may be easily divided into groups and the groups can be selectively loaded and unloaded during level/scene changes or even during the gameplay. Click here for more about Fast Spawn!

    I would be happy to hear what you think about them! There is a lot of more info on the provided links!

    Thanks!

    Cheers,
    Pauli aka pmjo
     
    Last edited: Sep 17, 2013
  2. pmjo

    pmjo

    Unity Technologies

    Joined:
    Sep 17, 2013
    Posts:
    245
    More about Fast Decals:

    $screenshot2.png

    More about Fast Spawn

    $screenshot1.png

    $screenshot2.png
     
  3. Lypheus

    Lypheus

    Joined:
    Apr 16, 2010
    Posts:
    664
    Looks great - definitely interested in the Fast Decals solution :).
     
  4. pmjo

    pmjo

    Unity Technologies

    Joined:
    Sep 17, 2013
    Posts:
    245
    Happy to hear that! :)
     
  5. FlaxSycle

    FlaxSycle

    Joined:
    Oct 6, 2012
    Posts:
    232
    Fast Decals looks really interesting! Does it handle arbitrary rotated quads?

    I've been relying on the Legacy Particle system to do something similar, but it has a number of limitations. I'm not working on a mobile title, but I'm very performance conscious so this is something I'll keep an eye on.
     
  6. pmjo

    pmjo

    Unity Technologies

    Joined:
    Sep 17, 2013
    Posts:
    245
    Yeah, you can specify the rotation with a normal or a rotation quaternion.

    DrawDecal offers the following overloads so you can even use a custom texture atlas incase you have one:

    public void DrawDecal(Vector3 pos, float size, int tileIndex)
    public void DrawDecal(Vector3 pos, float size, int tileIndex, Quaternion rotation)
    public void DrawDecal(Vector3 pos, float size, int tileIndex, Vector3 normal)

    public void DrawDecal(Vector3 pos, float size, int tileIndex, Color32 color)
    public void DrawDecal(Vector3 pos, float size, int tileIndex, Color32 color, Quaternion rotation)
    public void DrawDecal(Vector3 pos, float size, int tileIndex, Color32 color, Vector3 normal)

    public void DrawDecal(Vector3 pos, float size, Vector2 textureOffset, Vector2 textureTiling)
    public void DrawDecal(Vector3 pos, float size, Vector2 textureOffset, Vector2 textureTiling, Quaternion rotation)
    public void DrawDecal(Vector3 pos, float size, Vector2 textureOffset, Vector2 textureTiling, Vector3 normal)

    public void DrawDecal(Vector3 pos, float size, Vector2 textureOffset, Vector2 textureTiling, Color32 color)
    public void DrawDecal(Vector3 pos, float size, Vector2 textureOffset, Vector2 textureTiling, Color32 color, Quaternion rotation)
    public void DrawDecal(Vector3 pos, float size, Vector2 textureOffset, Vector2 textureTiling, Color32 color, Vector3 normal)

    public void DrawDecal(Vector3 pos, Vector2 size, int tileIndex)
    public void DrawDecal(Vector3 pos, Vector2 size, int tileIndex, Quaternion rotation)
    public void DrawDecal(Vector3 pos, Vector2 size, int tileIndex, Vector3 normal)

    public void DrawDecal(Vector3 pos, Vector2 size, int tileIndex, Color32 color)
    public void DrawDecal(Vector3 pos, Vector2 size, int tileIndex, Color32 color, Quaternion rotation)
    public void DrawDecal(Vector3 pos, Vector2 size, int tileIndex, Color32 color, Vector3 normal)

    public void DrawDecal(Vector3 pos, Vector2 size, Vector2 textureOffset, Vector2 textureTiling)
    public void DrawDecal(Vector3 pos, Vector2 size, Vector2 textureOffset, Vector2 textureTiling, Quaternion rotation)
    public void DrawDecal(Vector3 pos, Vector2 size, Vector2 textureOffset, Vector2 textureTiling, Vector3 normal)

    public void DrawDecal(Vector3 pos, Vector2 size, Vector2 textureOffset, Vector2 textureTiling, Color32 color)
    public void DrawDecal(Vector3 pos, Vector2 size, Vector2 textureOffset, Vector2 textureTiling, Color32 color, Quaternion rotation)
    public void DrawDecal(Vector3 pos, Vector2 size, Vector2 textureOffset, Vector2 textureTiling, Color32 color, Vector3 normal)
     
  7. pmjo

    pmjo

    Unity Technologies

    Joined:
    Sep 17, 2013
    Posts:
    245
    Hi!

    Good news! Both extensions are now accepted on the Unity Asset Store!

    Fast Spawn

    Fast Decals

    - pmjo
     
  8. im

    im

    Joined:
    Jan 17, 2013
    Posts:
    1,408
  9. guru20

    guru20

    Joined:
    Jul 30, 2013
    Posts:
    239
    I decided to go ahead and give the Fast Decals a buy. There were a lot of options, but yours seemed to have best price vs. features.

    However, I'm having trouble getting it to work. Right now I have chosen "Aging" decals, because what I really want (which is not what your package is designed for), is to apply a "decal" onto a surface that the camera is facing to act as an interaction icon. Maybe decals aren't the best way to do this, but I'm working in VR and it seemed like applying an icon directly onto the surface of an object would be less confusing than just showing one flowing as a GUI item

    In any case, this means that I need the decal to automatically disappear instantly as soon as a new update/raycast is done in a new location (ie. the decals are constantly updating -- appearing and disappearing -- depending on where you are looking)

    However, I can't get the decal to even appear in the first place. (I'm a little unclear as to which Material I should create and apply to the Fast Decals Atlas Renderer)

    Here's my code I am using (placed on my Camera)'s script:
    Code (CSharp):
    1. if (Physics.Raycast(transform.position, fwd, out objectHit, 10))
    2.         {
    3.             Transform hitTransform = objectHit.transform;
    4.             // When looking around, change the decal icon if a new type of location is viewed; ie. if you can walk, show footsteps, etc.
    5.             // Upon decal change, store the new selection as the "current choice" and reset timer.
    6.             // If timer reaches 2.5 seconds without changing decal/selection, trigger action based on that choice
    7.             if (hitTransform.parent.tag == "floor")
    8.             { // trigger footsteps decal
    9.                 atlasRenderer.DrawDecal(hitTransform.position, 1.0f, walkIndex);
    10.                 Debug.Log("Hit floor"); // check to see if raycast is working
    11.             }
    12.  
    13.             else if (hitTransform.parent.tag == "use")
    14.             { // trigger hand decal
    15.                 atlasRenderer.DrawDecal(hitTransform.position, 1.0f, handIndex);
    16.             }
    17.  
    18.         }
    EDIT: Doh! I don't have a collider on the floor. Let me see what happens when I add that...

    Also... is there a variable that I can change to make the "aging" decals disappear right away?
     
  10. guru20

    guru20

    Joined:
    Jul 30, 2013
    Posts:
    239
    I modified the code to use "hitTransform.tag" instead of hitTransform.parent (I always get confused as to how the Transform relates to the GameObject... they often seem interchangeable?) and this seems to go into the if statement, but I run into a problem withe the atlasRenderer.DrawDecal:

    NullReferenceException: Object reference not set to an instance of an object
    LookAndSelect.Update () (at Assets/LookAndSelect.cs:30)

    I'm assuming this is referring to the objectHit / hitTransform? But not sure if it could have something to do with the walkIndex

    Here's the complete script:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class LookAndSelect : MonoBehaviour {
    5.  
    6.     public FastDecalsAtlasRenderer atlasRenderer;
    7.     private int walkIndex = 0;
    8.     private int handIndex = 1;
    9.     private string currChoice = "";
    10.  
    11.     // Use this for initialization
    12.     void Start () {
    13.         // walkIndex = atlasRenderer.atlas.GetIndexByName("footsteps");
    14.         // handIndex = atlasRenderer.atlas.GetIndexByName("hand");
    15.     }
    16.  
    17.     // Update is called once per frame
    18.     void Update () {
    19.         RaycastHit objectHit;
    20.         Vector3 fwd = transform.TransformDirection (Vector3.forward);
    21.  
    22.         if (Physics.Raycast(transform.position, fwd, out objectHit, 10))
    23.         {
    24.             Transform hitTransform = objectHit.transform;
    25.             // When looking around, change the decal icon if a new type of location is viewed; ie. if you can walk, show footsteps, etc.
    26.             // Upon decal change, store the new selection as the "current choice" and reset timer.
    27.             // If timer reaches 2.5 seconds without changing decal/selection, trigger action based on that choice
    28.             if (hitTransform.tag == "floor")
    29.             { // trigger footsteps decal
    30.                 atlasRenderer.DrawDecal(hitTransform.position, 1.0f, walkIndex);
    31.                 Debug.Log("Hit floor"); // check to see if raycast is working
    32.             }
    33.  
    34.             else if (hitTransform.tag == "use")
    35.             { // trigger hand decal
    36.                 atlasRenderer.DrawDecal(hitTransform.position, 1.0f, handIndex);
    37.             }
    38.  
    39.         }
    40.  
    41.     }
    42. }
    43.  
    NOTE: I had to cancel out getting the atlas indexes by name, because I was getting an error with that, as well, so I decided to try with just directly referencing the index (I only have 2 icons right now, so shouldn't be hard)
     
  11. pmjo

    pmjo

    Unity Technologies

    Joined:
    Sep 17, 2013
    Posts:
    245
    The public FastDecalsAtlasRenderer atlasRenderer reference is not set and that will give you null pointer error on line 30 and also on 13 and 14.
     
  12. guru20

    guru20

    Joined:
    Jul 30, 2013
    Posts:
    239
    Thanks. Yeah, as I was looking at the code again, I realized I hadn't linked it. Let me try again. I'm still not sure if decals are the way to go for what I am trying to do (I might instead create Quadobjects textured with the icon, and then place these at the position/normal-angle of whatever collider the raytracer is hitting. Might be more processing-efficient than decals, if anything.

    But I figured the decals might come in handy for other purposes, so I bought it anyway
     
    Last edited: Jul 30, 2015
  13. zenGarden

    zenGarden

    Joined:
    Mar 30, 2013
    Posts:
    4,538
    I didn't know Unity would create and sell asset store items o_O
     
  14. pmjo

    pmjo

    Unity Technologies

    Joined:
    Sep 17, 2013
    Posts:
    245
    I just work at Unity, all my stuff are private projects and started before I joined :)
     
  15. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Normal members of the public often demonstrate their skill and value via assets and are then hired. As far as I know there's no bias which is obviously what you're implying. So just stop.

    Edit: snap, pmjo posted the same time. In any case I'm in the market for a decent decal solution...
     
  16. Ramsdal

    Ramsdal

    Joined:
    Oct 18, 2013
    Posts:
    251
    @pmjo i cannot seem to find anything about the projection on non flat surfaces. If I want decals on nonflat meshes does that work with Fast Decals - if so could you please post some example picture? (I am thinking of for example blood splatter on a round ball or something along those lines) :)
     
  17. pmjo

    pmjo

    Unity Technologies

    Joined:
    Sep 17, 2013
    Posts:
    245
    Like most of the decal solutions, Fast Decals only supports planar decals so you cannot project it on to non flat surfaces. Fast Decals is not a projector, it is more like a fast quad renderer. I think there is at least one decal solution on the Asset Store that can do decals even on top of skinnedmeshrenderer but unfortunately I cannot remember it's name.
     
    Ramsdal likes this.
  18. zenGarden

    zenGarden

    Joined:
    Mar 30, 2013
    Posts:
    4,538
    It is strange Unity not having a good decal solution out of the box in 2015 :eek:
     
    Ramsdal likes this.
  19. nxtboyIII

    nxtboyIII

    Joined:
    Jun 4, 2015
    Posts:
    281
    What about decals on a curved surface, like a sphere?
     
  20. pmjo

    pmjo

    Unity Technologies

    Joined:
    Sep 17, 2013
    Posts:
    245
    No, just flat surfaces. You could use raycasting to determine which polygons you hit on a sphere and then create a decal of multiple surface normal aligned clipped decals however that is a bigger task and probably waste of time :)