Search Unity

[RELEASED] Imposter System OPTIMIZATION

Discussion in 'Assets and Asset Store' started by MUGIK, Aug 18, 2016.

?

Are you interested in this project?

  1. Yes.

    111 vote(s)
    92.5%
  2. Maybe.

    9 vote(s)
    7.5%
  3. No.

    0 vote(s)
    0.0%
  1. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    754
    Looks amazing, do you have an updated link to the trial version? Id love to try this before I buy.

    Also "You cant use image effects on 'imposterCamera' otherwise you will have incorrect atlas rendering. " - does that mean unity's own postprocessing effects wont work?
     
  2. JBR-games

    JBR-games

    Joined:
    Sep 26, 2012
    Posts:
    461
    I bought this on the sale and must say it works pretty good. I also bought Amplify Impostors and was much happier with this asset. Hope publisher keeps up Updates :)
     
  3. JBR-games

    JBR-games

    Joined:
    Sep 26, 2012
    Posts:
    461
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEditor;
    5. using ImposterSystem;
    6.  
    7. [ExecuteInEditMode]
    8. //Notes: this will build out a scene while in edit mode as soon as you click on the "setupImposters" or "removeImposters" boxes.
    9. //Notes: MultiSelect all prefabs and add your "tagToUpdate", tag to them all.
    10. //Notes: only the parent Gameobject with a Mesh renderer should have the tagtoUpdate, Child objects that are LODs should not.
    11. //Notes: this can permanently destroy aspects of your scene, always copy your project before testing.  This is ment for simple Setups so complex parenting of objects will like cause unwanted destruction in the scene
    12. //Notes: Create an Empty Gameobject and add the ImposterController to it, Save as a prefab and link that to prefabImposter here. this should have any setups that you perfer already set.
    13. //Notes: Add this to ImpostersHandler in the Scene.
    14. //Notes: Remove or disable this after scene is setup.
    15.  
    16.  
    17. public class JBR_ImposterSetup : MonoBehaviour {
    18.     [Tooltip("Check this button to Setup all imposters in the scene")]
    19.     public bool setupImposters = false;
    20.     [Tooltip("Check this button to Remove all imposters in the scene")]
    21.     public bool removeImposters = false;
    22.  
    23.  
    24.     [Tooltip("The Tag that an object needs, if we add imposters")]
    25.     public string tagtoUpdate = "Building";
    26.     [Tooltip("Array of all Imposter Gameobjects created, reference only")]
    27.     public GameObject[] objectsToAddImposters;
    28.     [Tooltip("A prefab with ImposterController already added, this should already have the individual specs setup")]
    29.     public GameObject prefabImposter;
    30.  
    31.     //The New Imposter Gameobject that is being setup
    32.     private GameObject imposterSetup;
    33.     //ref to ImposterController script
    34.     private ImposterController imposterControl;
    35.     //not currently used, will be for more complex Lods
    36.     private GameObject[] childObjects;
    37.  
    38.  
    39.  
    40.     private void Update()
    41.     {
    42.         if (setupImposters)
    43.         {
    44.             objectsToAddImposters = new GameObject[0];
    45.             setupImposters = false;
    46.             SetupImposters();
    47.         }
    48.  
    49.         if (removeImposters)
    50.         {
    51.             objectsToAddImposters = new GameObject[0];
    52.             removeImposters = false;
    53.             RemoveImposters();
    54.         }
    55.     }
    56.     // Use this for initialization
    57.     void Start()
    58.     {
    59.    
    60.     }
    61.     public void SetupImposters()
    62.     {
    63.         //FInd all objects with tag
    64.         objectsToAddImposters = GameObject.FindGameObjectsWithTag(tagtoUpdate);
    65.         //loop through all objects found
    66.         for (int i = 0; i < objectsToAddImposters.Length; i++)
    67.         {
    68.             Debug.Log("CHecking " + objectsToAddImposters[i] + "For ImposterController");
    69.             //dont do anything is this gameobject has Imposter scripts on them already
    70.             if (!objectsToAddImposters[i].GetComponent<OriginalGOController>() && !objectsToAddImposters[i].GetComponent<ImposterController>())
    71.             {
    72.                 //make sure object has a mesh renderer
    73.                 if (objectsToAddImposters[i].GetComponent<MeshRenderer>())
    74.                 {
    75.                     //TO DO : add child objects with a mesh renderer
    76.  
    77.                     //add prefab to scene, in same position and rotation as object to imposter
    78.                     imposterSetup = Instantiate(prefabImposter, objectsToAddImposters[i].transform.position, objectsToAddImposters[i].transform.rotation) as GameObject;
    79.                     //parent object to ImposterController
    80.                     objectsToAddImposters[i].transform.parent = imposterSetup.transform;
    81.                     //rename imposter parent
    82.                     imposterSetup.name = (objectsToAddImposters[i].name + "_ImposterLOD");
    83.                     //reference imposter Controller
    84.                     imposterControl = imposterSetup.GetComponent<ImposterController>();
    85.                     //add originalGOController to object
    86.                     objectsToAddImposters[i].AddComponent<OriginalGOController>();
    87.  
    88.                     //add object to LOD0, Note this only works for one LOD object currently
    89.                     imposterControl.m_LODs[0].renderers = new OriginalGOController[1];
    90.                     imposterControl.m_LODs[0].renderers[0] = objectsToAddImposters[i].GetComponent<OriginalGOController>();
    91.                     //add object to LOD1, Note this only works for one LOD object currently
    92.                     imposterControl.m_LODs[1].renderers = new OriginalGOController[1];
    93.                     imposterControl.m_LODs[1].renderers[0] = objectsToAddImposters[i].GetComponent<OriginalGOController>();
    94.                     //make this second LOD the imposter
    95.                     imposterControl.m_LODs[1].isImposter = true;
    96.                     Debug.Log("Imposter Setup Finished on -" + objectsToAddImposters[i]);
    97.                 }
    98.                 else
    99.                 {
    100.                     Debug.Log(objectsToAddImposters[i] + " Did not have a mesh renderer so it was skipped");
    101.                 }
    102.             }
    103.             else
    104.             {
    105.                 Debug.Log(objectsToAddImposters[i] + "-has Imposter Controller");
    106.             }
    107.         }
    108.     }
    109.  
    110.     public void RemoveImposters()
    111.     {
    112.         //FInd all objects with tag
    113.         objectsToAddImposters = GameObject.FindGameObjectsWithTag(tagtoUpdate);
    114.         //loop through all objects found
    115.         for (int i = 0; i < objectsToAddImposters.Length; i++)
    116.         {
    117.  
    118.             if (objectsToAddImposters[i].GetComponent<OriginalGOController>())
    119.             {
    120.                 //remove OriginalGOController
    121.                 DestroyImmediate(objectsToAddImposters[i].GetComponent<OriginalGOController>(),true);
    122.  
    123.                 Transform main = objectsToAddImposters[i].transform.parent;
    124.                 objectsToAddImposters[i].transform.parent = null;
    125.                 if (main != null)
    126.                 {
    127.                     if (!main.GetComponent<MeshRenderer>())
    128.                     {
    129.                         DestroyImmediate(main.gameObject, true);
    130.                     }
    131.                
    132.                 }
    133.            
    134.             }
    135.  
    136.             if (objectsToAddImposters[i].GetComponent<ImposterController>())
    137.             {
    138.                 if (objectsToAddImposters[i].GetComponent<MeshRenderer>())
    139.                 {
    140.                     //remove ImposterController
    141.                     DestroyImmediate(objectsToAddImposters[i].GetComponent<ImposterController>(), true);
    142.                 }
    143.                 else
    144.                 {
    145.                     //loop through all childern
    146.                     foreach(Transform child in objectsToAddImposters[i].transform)
    147.                     {
    148.                         //un-child all childern before destroying
    149.                         child.transform.parent = null;
    150.                     }
    151.                     DestroyImmediate(objectsToAddImposters[i], true);
    152.                 }
    153.             }
    154.  
    155.  
    156.         }
    157.     }
    158. }
    159.  
    For anyone that wants a quick way to setup a prebuilt scene. Note it does have a few limitations like only 1 lod level,& only 1 MeshRenderer per group. This could potentially break a scene so always test on a backup first.
     
    Last edited: Dec 8, 2018
    NeatWolf and AthrunVLokiz like this.
  4. NeatWolf

    NeatWolf

    Joined:
    Sep 27, 2013
    Posts:
    776
    Just curious:

    Without asking why I would do that :p, would this work on 2D sprites (quads) and particle systems (shuriken) as well?
    What about VR single pass and custom shaders?
    Does it support custom rendering pipelines or dynamic rendering resolution change?

    I do own the asset, but I'm just asking if they're officially supported. I haven't delved into the details of its implementation.
     
    JBR-games likes this.
  5. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    754
    Just been looking at the amplify one, what was wrong with it ? I wish these people did free trial versions.
     
  6. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    116
    Hi

    I don't have any standalone VR helmet like Oculus, so can't test and proof that Imposter System works for VR.
    I had customers that wanted to use my asset with VR, but with no luck. We faced bugs with rendering to RenderTextures in VR-mode. Maybe in future, when I will have more time, I will buy VR helmet and test Imposter System with it.
     
  7. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    116
    Imposter system would work with 2D sprites (quads).
    With particles it's a bit complicated. First of all particles have dynamic bounds, that's why they may be outside of imposter texture. Also, particle's shaders don't write to z buffer, so ImposterSystem's shader can't draw them.
    Here is color channel of imposter texture with particle system:
    upload_2018-12-13_20-17-52.png
    Alpha channel of the same texture:
    upload_2018-12-13_20-18-13.png
    Final result:
    upload_2018-12-13_20-18-29.png
    But if you have experience in writing shader, you can change ImposterSystem's shader to the way you want.

    Can't say anything about VR:(
    Imposter System using standard forward rendering, so custom shaders must work with forward rendering and write to z-buffer.
     
  8. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    116
    No, now there is no trial version. But you can buy asset, and if it doesn't work I will refund you money.

    Yes, unity's own postprocessing effects won't work on 'imposterCamera'(camera, that used to render imposter textures, it's not your game camera).
    Also, you don't want image effects on this camera:) Imposter texture must look just like original object, without any changes in color or shape, because this breaks the 'effect' of imposter.
     
  9. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    116
    Hope you happier with my asset:D
    Yes, updates will be soon... Or later if I will decide to rewrite the whole system from scratch.

    Hmmm, need to add similar fast scene setup in future updates.
     
    Last edited: Dec 13, 2018
    AthrunVLokiz and JBR-games like this.
  10. JBR-games

    JBR-games

    Joined:
    Sep 26, 2012
    Posts:
    461
  11. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    116
    Can you confirm, that you using forward rendering path?
    Is imposter-texture dark or exactly rendered imposter?
     
    JBR-games likes this.
  12. JBR-games

    JBR-games

    Joined:
    Sep 26, 2012
    Posts:
    461
    The Imposter is several Shades Darker then the actual building, it still looks good but there's an obvious popping of color when it transitions.

    Unfortunately I've been very busy at work getting caught up before the holidays but as soon as I get a chance I will find out if I was in the wrong rendering get back to you .
    thank you
     
    Last edited: Dec 21, 2018
    MUGIK likes this.
  13. SOIL

    SOIL

    Joined:
    Sep 2, 2011
    Posts:
    142
    It seems this project is dead! What a pitty! Such system would revolutionize far-rendering scenarios! :(
     
  14. JBR-games

    JBR-games

    Joined:
    Sep 26, 2012
    Posts:
    461
    Dead why so ? Publisher just replied to a question had a month ago.. It actually works really well..
     
    MUGIK and hopeful like this.
  15. SOIL

    SOIL

    Joined:
    Sep 2, 2011
    Posts:
    142
    Maybe, but did you tested the plugin with the latest Unity 2018.3.x ? Cause, the publisher had his last update on jul 9th, 2018! And a almost seven month old release is nothing I would buy! Sorry, if I have reacted in a prejudicial way. But the publisher could do a simple update, just to confirm that his plugin works on newer versions.
     
    NeatWolf likes this.
  16. JBR-games

    JBR-games

    Joined:
    Sep 26, 2012
    Posts:
    461
    I have not tested in 2018.3, i did test in 2018.2f20. Yes hopefully @MUGIK checks and possibly updates soon..

    Youve been around for a while and should know that unity's newest version always seems to have issues with either breaking assets or issues in unity itself. So I dont like being an early adopter.
     
  17. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    116
    Hi!
    I 100% understand your position.
    Please, don't buy this asset until I make a new version. It will not be just an update.
     
    NeatWolf, JBR-games and AthrunVLokiz like this.
  18. JBR-games

    JBR-games

    Joined:
    Sep 26, 2012
    Posts:
    461
    Do you have a rough eta on the new system ?
     
  19. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    116
    No.
    But I can say that in new version/iteration of my project I would use ECS and multithreading techniques that will heavily reduce load on CPU.
    Main functionality will stay the same.
     
    JBR-games likes this.
  20. LukeDawn

    LukeDawn

    Joined:
    Nov 10, 2016
    Posts:
    289
    Any further news on this, and whether it will work in deferred/forward, and with GI/dynamic lighting/global fog?