Search Unity

InstantOC - dynamic occlusion culling + LOD

Discussion in 'Assets and Asset Store' started by frenchfaso, Jan 18, 2013.

?

Should I strip out the integrated LOD stuf from InstantOC to make the code more maintainable?

Poll closed Mar 4, 2017.
  1. Yes, I never used it anyway

    50.0%
  2. Yes, I've used it in the past but will only use InstantOC for oc in the future

    50.0%
  3. No, I like it better than the Unity LOD

    0 vote(s)
    0.0%
  1. PolyMad

    PolyMad

    Joined:
    Mar 19, 2009
    Posts:
    2,350
    OK last couple of questions then I'll take it: does it work with TRIGGER COLLIDERS?
    The thing is, this would be great with trees as well, just by placing triggers on the foliage.
    And, putting large trigger colliders under the terrain should work like anything else, right?
     
  2. chillersanim

    chillersanim

    Joined:
    Mar 31, 2013
    Posts:
    219
    Hey frenchfaso

    I recently found a bug (not sure if it is a bug or just a limitation)
    When I have two objects, fully set up with your OC and LOD and also working, and I put one of this objects as child to the other object, then the child object will not be shown. I think this is because unity joins the collision meshes of booth together, so that only the parrent object get informed about the collision with the ray.

    Example:
    • Object1
    • Lod_0​
    • Lod_1​
    • Lod_2​
    • Object2
    • Lod_0​
    • Lod_1​
    • Lod_2​
    When I put Object2 into Object1, it looks so:
    • Object1
    • Lod_0​
    • Lod_1​
    • Lod_2​
    • Object2​
    • Lod_0​
    • Lod_1​
    • Lod_2​
    Now only Object1 get shown, Object2 is always invisible.

    You could possibly avoid that, when you also check, if an object contains another LOD object, and handle his LOD with the parent settings or so.

    Greetings
    Chillersanim
     
  3. chillersanim

    chillersanim

    Joined:
    Mar 31, 2013
    Posts:
    219
    Well 1) it works with triggered colliders and
    2) when you want to have it work on tree's, it will work, but not if those trees were painted on the terrain.

    I would recommend you, to use exact collision objects for your trees, because, if you just use box coliders, the trees behind it, won't be visible, because they don't get hit by the ray ;)
    Remember, the objects only get visible when they were hit by the ray

    Greetings
    Chillersanim
     
  4. PolyMad

    PolyMad

    Joined:
    Mar 19, 2009
    Posts:
    2,350
    Yeah of course it won't work with trees painted on terrain :)
    And of course colliders on trees must be "high fidelity" or they will hide stuff :D

    But the good news is that it works with triggers!

    Thank you!
     
  5. PolyMad

    PolyMad

    Joined:
    Mar 19, 2009
    Posts:
    2,350
    Ummmm this is bad news... as I have vehicles moving around, with wheels as children and stuff...
     
    Last edited: May 1, 2013
  6. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    hmm... I will check this out, in the meantime, could you try something like this: ?

    • Parent GO
      • GO_1
        • Lod_0
        • Lod_1
        • Lod_2
      • GO_2
        • Lod_0
        • Lod_1
        • Lod_2
     
    Last edited: May 1, 2013
  7. ronan-thibaudau

    ronan-thibaudau

    Joined:
    Jun 29, 2012
    Posts:
    1,722
    That and 1 mil poly is nothing for a modern card if running basic shader on static geometry, i've used unity with way more than 1M poly on screen with no problems in basic scenes.
     
  8. chillersanim

    chillersanim

    Joined:
    Mar 31, 2013
    Posts:
    219
    Well I tested it, but the funny thing is, that Unity seem to have a bug when I have a object hierarchy with more than 3 layers...
    When I have the following scenario:
    • Parent GO

      • GO_1
        • Lod_0
          • Some object
    When "Parent Go" has a RiggidBody applied to, it
    The collision box of "some object" doesn't seem to work... :(
    However, the collisions of all upper objects works.

    After a bit of further testing, I found, that the Lod only works, if no rigidBody is applied to the parent object, strange :(

    Greetings
    Chillersanim
     
  9. Zergling103

    Zergling103

    Joined:
    Aug 16, 2011
    Posts:
    392
    Hi there,

    Amazing product. But I had some technical questions about it.

    I presume you are using raycasts with colliders to determine if an object is visible. In doing so you are making an assumption about the relationship between renderers and colliders. How does InstantOC determine what colliders are tied to what renderers? Is this automatic? Can this be termined by the user? Does this require special set up?

    Does InstantOC require any special set up of renders and/or their colliders? Does InstantOC continuously search for all the renderers in the scene and manipulate their enabled state? Or do you need to attach a special component to renders which you want to have occlusion testing for? Does InstantOC interfere with other behaviours which manipulate a renderer's visibility state, and if so, in what ways?

    Thanks. :D
     
  10. PolyMad

    PolyMad

    Joined:
    Mar 19, 2009
    Posts:
    2,350
    Well it depends.
    My laptop is not exactly old and not a low level pc.
    It's a i7 with a 540M, and believe me: the graphic board is the bottleneck here, and a bad one.
    So when I'm in production I wonder on how many people would play my game but they can't because framerate drops to 10 fps or less.
    You better consider people with laptops because there is a huge number around.
     
  11. chillersanim

    chillersanim

    Joined:
    Mar 31, 2013
    Posts:
    219
    @ Zergling103:
    Well, the OC need's a collider. What collider that is, and what shape it has, doesn't matter. As soon as the collider is hit by the ray, the owning object gets updated. You can either add the collider to the parrent object or to a child object, it doesn't matter. You can even use multiple collision meshes and it will work ;)
    The collider just need's to be a part of the object tree, so that OC can work with it.

    @megmaltese
    It depends on many factors.
    I think, that the laptop of yours can handle 1M polys with a framerate much higher than 10. ;)
    But as soon as you add materials, textures etc, or split up the polys to different objects... as soon as you use lights, or even shadows, the framerate will drop.
    Try it. Create an object with 1M polys but without material. Import it to unity, make sure that no other objects (except the Maincamera) are in the scene and the object doesn't have any materials or physic tools on it and start the game. Please tell me the result.

    Greetings
    Chillersanim
     
  12. PolyMad

    PolyMad

    Joined:
    Mar 19, 2009
    Posts:
    2,350
    Yeah shadows have a huge impact... but they MUST be there :rolleyes:

    I didn't consider this, they are missing on the demo and also those houses have no normal maps and specular.
     
  13. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    @megmaltese
    You probably tried the standalone Demo (Mac/Win)
    Please try the WebPlayer Demo, it's updated with latest version of InstantOC and has realtime shadows enabled.

    @chillersanim
    Thank you for your great support here, you are out of doubt the InstantOC Specialist of the thread :)
     
  14. chillersanim

    chillersanim

    Joined:
    Mar 31, 2013
    Posts:
    219
    @chillersanim
    Thank you for your great support here, you are out of doubt the InstantOC Specialist of the thread :)[/QUOTE]

    Yay
    Well, I help wherever I can. ;)
    And as a software developer (and nerd), I like good software and want to support them ;)

    Greetings
    Chillersanim
     
  15. PolyMad

    PolyMad

    Joined:
    Mar 19, 2009
    Posts:
    2,350
    Great, gonna try it now, I'm rendering some lightmaps, so I have some minutes to spend :D

    BTW, I just bought it :)
     
  16. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Thank you megmaltese!
    Glad to hear that :)
     
  17. PolyMad

    PolyMad

    Joined:
    Mar 19, 2009
    Posts:
    2,350
    Just checked the demo with shadows and I have a suggestion: increase the shadow distance to 100 meters!
     
  18. jc_lvngstn

    jc_lvngstn

    Joined:
    Jul 19, 2006
    Posts:
    1,508
    One other suggestion for the demo: Get rid of the fog. It sort of obscures the view in the distance...not really giving a clear picture of what you are getting, imo.
     
  19. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    @megmaltese, @jc_lvngstn

    Thanks! yep, actually I would like to make a new InstantOC Demo, with a "real" game scene, something nice, like you find in benchmarks like BasemarkX / 3DMark and release it (free) as, well a benchmark, on all (almost) platforms :) "InstantMark?!?"
    But I'm currently working hard finishing a new Asset Store related project, which I will hopefully release very soon!
     
    Last edited: May 2, 2013
  20. chillersanim

    chillersanim

    Joined:
    Mar 31, 2013
    Posts:
    219
    May I ask you on what you work?
    Is it that EazyiAd?

    Greetings
    Chillersanim
     
  21. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    It's not :) EazyiAd is in standby, it's almost there, but currently in standby.
    The project I'm currently working on is AssetStore "related", but will not be "in" the AssetStore :p
    I will start a dedicated thread really soon!
     
  22. chillersanim

    chillersanim

    Joined:
    Mar 31, 2013
    Posts:
    219
    Oh, is it an asset store hacking tool for bad people like me?
    Taking over the control over the asset store and rule the world. Muhahaha

    Greetings
    Chillersanim
     
  23. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    lol !!!
    sort of ;-)
     
  24. chjacobsen

    chjacobsen

    Joined:
    Oct 8, 2012
    Posts:
    58
    I love this. Works like a charm.

    One suggestion: I'm making a top-down game and increasing the view distance didn't help with pop-in. I made a slight modification to the script: Just adding a ray origin offset parameter and moving the origin of the ray upwards. Now everything works perfectly and i have no pop-in. Perhaps this is something to consider for the main release? Should make the script a bit more flexible.
     
  25. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Hello chjacobsen,
    glad to hear that!
    It's a great idea, thanks for sharing it!
    I will surely integrate it in the upcoming update.
     
  26. chillersanim

    chillersanim

    Joined:
    Mar 31, 2013
    Posts:
    219
    Do you know already a release date?
    I'm curious for the new functions :D

    Edti:
    I need to ask you, if I may use your logo in my game.
    I want to include something of each developer, from which I use code.
    It's meant as a small advertising. ;)

    Greetings
    Chillersanim
     
    Last edited: May 5, 2013
  27. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Sure you can! It would be awesome! (Thanks a lot!)
    I still would like to make a "Powered by InstantOC" Gallery on the InstantOC webpage, if you like the idea I will be glad to add your project to it!
    It will be the first :)

    Every project will need to provide:
    1. title
    2. screenshot
    3. youtube video link (trailer/in-game footage)
    4. link to a website/webpage
    5. brief description of the project

    PS: next release of InstantOC should be live in 10-15 days, with a couple of little optimizations and some cleanup of the code. And the hint of chJacobsen.
     
  28. chillersanim

    chillersanim

    Joined:
    Mar 31, 2013
    Posts:
    219
    Well, my game will not be finished so fast, so you need to wait about a year, before we will be (not for sure!) in beta phase. ;)
    But when we have something to show, I would be proud to see it on your webpage to!

    As far as I understand, you are not going to include the following functions into your script:
    - Hide objects after a predefined distance
    - Allowing [n] LOD levels
    ?

    $Bottle_InstantOC.jpg
    Here a models with your texture ;) (For some reason, unity forum doesn't allow me to upload my bottle model...)
    Would be glad, if you could give me some higher resolution pictures though...

    Greetings
    Chillersanim
     

    Attached Files:

    Last edited: May 5, 2013
  29. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    The next update is a "maintenance release", and it prepares the path for future updates
    [n] LODs and LOD hide > dist. needs some more work :p

    PS: I'll send you an SVG version of the InstantOC logo, made with Inkscape (great open source alternative to Illustrator!).

    PS2: looking forward to your beta!
     
    Last edited: May 5, 2013
  30. chillersanim

    chillersanim

    Joined:
    Mar 31, 2013
    Posts:
    219
    I had an idea.
    To prevent flickering of objects who are far away, you could add a function, which checks an amount of objects, if they are possibly visible.
    For that, you create a list of objects which recently got occluded. Those objects get their own ray, with a calculated angle. So you can make sure, that the object is hidden.
    The user should be able to define, how many objects get "remembered", and only the last [n] occluded objects get "remembered". If an object get visible again, it gets deleted from the list.

    Just a small thought from me ;)

    Greetings
    Chillersanim
     
  31. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    That's a good idea, the current version of InstantOC does indeed something very similar :):
    every time an objects gets hit by a ray, the hit position is stored, and before the object hides itself again, it will cast a ray from this "last-hit-position" to the camera; if it hits the camera (is still visible), it will wait another round to hide itself.
     
  32. chillersanim

    chillersanim

    Joined:
    Mar 31, 2013
    Posts:
    219
    Hmmm, do you store the hit position relative to the object or global?
    I ask because of dynamic objects.

    Well, I will see how it works. :D

    Greetings
    Chillersanim
     
  33. jim3D

    jim3D

    Joined:
    Apr 29, 2013
    Posts:
    23
    From 3 to 20 FPS on a 500 € laptop
    Good Work!
     
  34. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Gotcha! that's a bug! ( or a feature ;-) )
    I was storing the hit-point in worldspace..

    here is the correctly updated code in IOClod.cs:

    please change line 134 from this:
    Code (csharp):
    1.  
    2. r = new Ray(hitPoint, iocCam.transform.position - hitPoint);
    3.  
    to this:
    Code (csharp):
    1.  
    2. var p = transform.localToWorldMatrix.MultiplyPoint(hitPoint);
    3. r = new Ray(p, iocCam.transform.position - p);
    4.  

    and line 244 from this:
    Code (csharp):
    1.  
    2. hitPoint = h.point;
    3.  
    to this:
    Code (csharp):
    1.  
    2. hitPoint = transform.worldToLocalMatrix.MultiplyPoint(h.point);
    3.  
    @chillersanim Thanks a lot for finding this bug!
     
  35. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Well, thank you jim3D :)
     
  36. chillersanim

    chillersanim

    Joined:
    Mar 31, 2013
    Posts:
    219
    And I did not even look in your code...

    But now I looked a bit in your code and found some other... well lets call it "features". ;)
    First of all, you presuppose, that the camera has a collision object, because you simply send a ray to it.
    Additionally, you don't check if it is actually the main camera, but only check his tag... I would recommend you to use the gameObject and the equal() method or at least if the gameObject contains a IOCcam.
    Also you presuppose that the flickering starts at a distance of 100 unity units, I would make that number changeable through the user (for big and smal objects...)

    I do not understand the following code:
    Code (csharp):
    1. switch(currentLod)
    2. {
    3.     case 0:
    4.         visible = rs0[0].isVisible;
    5.         break;
    6.     case 1:
    7.         visible = rs1[0].isVisible;
    8.         break;
    9.     case 2:
    10.         visible = rs2[0].isVisible;
    11.         break;
    12.     default:
    13.         visible = rs[0].isVisible;
    14.         break;
    15. }
    16. if(visible  hitDistance > 100f)
    17. ...
    As far as I understand it, you check if the renderer of the current LOD is visible. Why do you test that?
    I thought, that you only send a ray when it is invisible, currently you test it when it is visible... (When I understood your code correctly...)

    My last recommend... Make use of local variables. Actually you save everything global, even if it is only used as local variable. You should save everything local when possible, so you can free unused ram.

    I know, this is a lot of criticism, but I hope, that I was able to help a bit. ;)

    Greetings
    Chillersanim
     
  37. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    @chillersanim
    no problem! I want InstantOC to become nearly perfect! so every help/suggestion is welcome!

    • yep, InstantOC knows the camera has a sphere collider, because the IOCcam component creates it at startup
    • the iocCam variable is the IOCcam component of the main camera (also automatically setup at startup) so InstantOC does not need any other checks,
    • if it reaches it, there are no occluding objects in between, thus the current game object is still visible.
    • the "switch" block is an optimization check, it checks if the game object that is going to hide itself is in the view frustum, if not it should hide straightway, without casting the ray
    • the variables.. it's a tradeoff, between speed and memory consumption, InstantOC has to be as fast as possible, so it allocates variables only once, at startup; re-allocating local variables every frame is not so fast and the memory consumption should be ok anyway (few vars)
     
  38. chillersanim

    chillersanim

    Joined:
    Mar 31, 2013
    Posts:
    219
    Hmm, how does the distance have an effect to the visibility of the object? Or do I understand something wrong?

    So this visible is only to determine, if it is inside the viewport? In this case, it's clear.

    The rest is now clear, thanks for telling me. :)

    What I forgot to ask... Do you also wait with the feature, to use the quality settings from unity for the IOC?
    Would be great, if this feature would a) scale the distance for the LOD and b) the number of ray's used.

    Greetings
    Chillersanim
     
  39. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    @chillersanim
    You are right, the 100 unity units value is chosen arbitrarily, but that's not optimal for every object (depends on object size)
    So in the upcoming update it will be settable through the inspector, something like "Check for visibility before hiding if farther than: "

    Exactly, the renderer.isVisible checks if the object is in the view frustum (but it returns true also if occluded by some other object and thus actually not visible)

    Not sure with that, but it's really a good idea, it's high on the todo list :)
     
  40. Mustafa Adil

    Mustafa Adil

    Joined:
    Dec 6, 2012
    Posts:
    21
    im getting two errors when i attach IOClod script to one of my buidling:

    NullReferenceException
    UnityEngine.Component.GetComponent[IOCcam] () (at C:/BuildAgent/work/812c4f5049264fad/Runtime/ExportGenerated/Editor/UnityEngineComponent.cs:132)
    IOClod.Start () (at Assets/InstantOC/IOClod.cs:32)

    and the second one is :

    NullReferenceException: Object reference not set to an instance of an object
    IOClod.Hide () (at Assets/InstantOC/IOClod.cs:251)
    IOClod.Update () (at Assets/InstantOC/IOClod.cs:106)


    im enable to find the solution so please guide me
     
  41. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Hello Mustafa,
    for the first error please check the TAG of your camera, it should be the default TAG "MainCamera".
    for the second error, it's probably a hierarchy problem, how does the hierarchy of your buildings look?
     
    Last edited: May 7, 2013
  42. Mustafa Adil

    Mustafa Adil

    Joined:
    Dec 6, 2012
    Posts:
    21
    Thanks mate for quick reply. The first error is removed now !
    But the problem is my building does not disappear when the camera is not looking at that building. Maybe im lacking somewhere....
    Kindly can you tell me your email id so that i can mail you my building , its kinda difficult to explain the hierarchy of the building.
     
    Last edited: May 8, 2013
  43. trooper

    trooper

    Joined:
    Aug 21, 2009
    Posts:
    748
    is there an option to use distance of object + look vector instead of an actual raycast?
     
  44. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Sent you a pm :)
     
  45. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    hy trooper,
    do you mean for occlusion culling or for lod?
     
  46. xadhoom

    xadhoom

    Joined:
    Sep 2, 2010
    Posts:
    91
    Hi frenchfaso,

    The demo looks quiet impressive. But it seems hard to compare how big the benefit of instantOC really is since it is compared with Unity´s standard (full detail) rendering. What I would like to see in the demo is what the performance improvement is between instantOC and standard Unity LOD rendering with similar LOD distance settings.
    Its obvious that a proper LOD management based on distance is important in huge scenes. Thats something Unity already offers. It would be nice to learn what the actual occlusion approach of instantOC puts on top of that.

    Thanks,
    xad
     
  47. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Hello xadhoom,
    thank you for your interest in InstantOC!
    The performance boost offered by InstantOC is based on 2 optimizations:

    - Occlusion Culling (fully dynamic in case of InstantOC)
    - LOD management

    both this optimization techniques are available only with Unity Pro (if you don't use plugins like InstantOC)

    The InstantOC demo scene takes advantage of both and in addition the houses are placed randomly at startup.
    So you would have to compare it with Unity Pro LOD AND Unity Pro Umbra occlusion culling, BUT:
    Umbra oc in Unity Pro is NOT dynamic, so it would be useless in the demo scene :)
    Thus, the performance boost of InstantOC would be much better, but it is unfair, to compare OC + LOD versus LOD only.

    Please take a look at the InstantOC faq and the User Guide, to gain a deeper insight of InstantOC and determine if it suits your needs.
    Also take a look at the video tutorials to see the InstantOC workflow.
     
    Last edited: May 8, 2013
  48. xadhoom

    xadhoom

    Joined:
    Sep 2, 2010
    Posts:
    91
    Hi frenchfaso,

    Thank you for the detailed answer. I intentionally left out Umbra here for the reasons you mentiond. I agree that these systems are not comparable.

    I couldn´t parse this sentence ;-) I understand that instantOC offers functionality which is not available in Unity Free. I´d like to better understand what the benefits are when using Unity Pro. We currently use Unitys integrated LOD system and I would like to know what performance gain can be expected when switching to the instantOC LOD/OC solution.

    Thanks,
    xad
     
  49. ronan-thibaudau

    ronan-thibaudau

    Joined:
    Jun 29, 2012
    Posts:
    1,722
    I don't think it's meant to outperform unity's baked solution, just to provide a baking free alternative if you're a pro user. At least that's how i see it, anything with baking is a huge thorn while designing so a good use case if you're pro is to design with this switch to baked before final release i guess?
     
  50. Olafson

    Olafson

    Joined:
    Aug 7, 2012
    Posts:
    255
    Well.. Use it together with Umbra, and you have a perfect solution for anything. Use instant OC for dynamic objects and umbra for all the static objects.