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. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    @gecko
    I've sent you a PM with an updated IOChud script, now with the possibility to edit options also on mobile :)

    Regarding the "LOD only" option, it depends, but if you have mainly "LOD only" game objects in your scene, then you can use significantly less Ray Samples, which in turn weighs less on the CPU.
    Raycasting in InstantOC is already very optimized, of course there is always some room for improvements, but it's a Unity API method that ultimately fires rays.
    Regarding grouping LODs, (grouping in general) I'm evaluating different ways to make it more flexible.
     
  2. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    countdown update

    8 days until full price (25$)
    get your InstantOC today at only 15$

     
  3. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,241
    Thanks! It's fantastic to be able to tweak the settings on the iPad and watch the profiler.

    Couple questions about the settings:
    -If View Distance is larger than the camera's far clip, then those are wasted rays, right? It should always be set to be the same or smaller than the far clip to avoid wasting CPU?
    -If View Distance is 500, and Lod_2 (lowest LOD) is set to 300... then IOC is still casting rays out to 500m, but only rendering trees out to 300m -- again, that's wasted CPU?

    Looking forward to hearing options for LOD grouping.
     
  4. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Glad to hear this :)

    No need to do this, at startup InstantOC set's automatically the Camera's far clip plane to be equal to the IOCcam "View Distance" value.

    Nope, if you have a "Lod 2 distance" of 300, InstantOC will render the LOD_2 model if the distance from the camera is greater than 300.
    Lod distances work like this:

    Lod_0 if distance from camera >= 0 AND < Lod 1 distance
    Lod_1 if distance from camera >= Lod 1 distance AND < Lod 2 distance
    Lod_2 if distance from camera >= Lod 2 distance
     
  5. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,241
    Ah. But if I then change View Distance in the HUD, it doesn't change it on the camera, and seems to have no effect. Is that true?

    Also, if I wanted the camera to retain it's present far clip, and set the IOC View Distance at something shorter, is there a way to do that?
     
  6. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    yep, if you update it in the HUD while testing, it does not change the camera far clip plane.

    Just comment out line 35 in the IOCcam script:

    Code (csharp):
    1. //cam.farClipPlane = viewDistance;
    this way, you can set the 2 values independently.
     
  7. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    countdown update

    7 days until full price (25$)
    get your InstantOC today at only 15$

     
  8. morbidcamel

    morbidcamel

    Joined:
    Dec 23, 2013
    Posts:
    8
    Hi frenchfaso - first off I love your component it works great. I did however change some of the code and it runs at least 40% more efficiently. Let me know if you want to see what I've done.
     
  9. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Hello morbidcamel,
    thank you for your purchase and your appreciation!
    That would be awesome! I would really like to take a look at your mods.
     
  10. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    countdown update

    6 days until full price (25$)
    get your InstantOC today at only 15$

     
  11. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Yeah, tell us what your idea was! Tell us Tell us Tell us ! :D

    BTW, Fren.. any planned date for occludee only support update?
     
  12. makotech222

    makotech222

    Joined:
    Oct 20, 2013
    Posts:
    9
    Quick question, does this work with orthographic cameras? I tried using it, but i'm just getting a black screen :p

    Nevermind, figured out why. The script seems to change my far plane to 468, when by default, it should be 3000. Unfortunately, i'm not getting any performance improvements from it :(
     
    Last edited: Jan 27, 2014
  13. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Hello makotech222,
    InstantOC is an occlusion culling and LOD system, if there is no occlusion going on, and/or camera is always at a fixed distance from the scene (e.g. top-down views) this two optimization techniques will not help.
    Best candidates for occlusion culling and/or LOD are FPS, TPS, etc.. with big scenes and a lot of game objects (see InstantOC FAQ).
    For top-down view games and alike, I would suggest some geometry/material batching and texture atlasing utilities.
    Something like Unity Pro static batching or Mesh Baker 2 will certainly help reduce draw-calls in such cases. Good materials with highly optimized shaders will also help improove performance.
     
  14. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    countdown update

    5 days until full price (25$)
    get your InstantOC today at only 15$

     
  15. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Hello castor76,
    should be a couple of weeks.
     
  16. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    countdown update

    4 days until full price (25$)
    get your InstantOC today at only 15$

     
  17. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    countdown update

    3 days until full price (25$)
    get your InstantOC today at only 15$

     
  18. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    countdown update

    2 days until full price (25$)
    get your InstantOC today at only 15$

     
  19. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Lol... if I haven't bought this , I would be really anixous. :D

    BTW Fren , did morbidcamel sent you his improved version?
     
  20. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    lol :-D

    Not yet, however I've made some little improvements to the main raycasting loop, will push it in the next update.
    It would be so nice to have a thread-safe Unity API, and do parallel raycasting :)
     
  21. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    I just saw 'does terrains' and bought it, my scene is 70+ terrains (it was 500+ at one point) and they're killing the performance. I'm hoping this could, when the terrain bit is in there if not already, be incredibly useful to me, or actually anyone using eagle555's Terrain/World Composer as you start to get ambitions very quickly
     
  22. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Hello lazygunn,
    thank you for your purchase, I'll be glad to help you getting the most out of InstantOC, so if I get it right, you are using "World Composer" in your project, and have a scene with multiple terrains, that you would like to be managed by InstantOC, right?
     
  23. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    Hello! Well in terms of OC i dont know how much of its origin is relevant haha, world composer is a tool to grab real elevation data for an area along with satellite imagery to get real life geography into a Unity scene, this tends to lend itself to generating a lot of terrains to get all the detail out of a location

    I think you can get a vague idea from this video I did earlier today



    And the shape of the grid can be seen here

    $Grid.jpg

    The sides are divided up too, its about 10000km2 of land, lots of terrains, and impossible it seems thus far to cull unseen terrains and making a gigantic dent in the programs performance

    Do you think your product can be suitable for this? Its a bargain anyways so a happy purchase either way but the terrain stuff could be so useful if it actually it removed from the Culling process that haunts me in the profiler. Also being able to have a lot of control over terrain pixel error depending on circumstances could be great
     
  24. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    @lazygunn
    looks really cool! Can't wait to see more about your project!
    The stuff I'm currently working on for the next update (10-15 days) is:
    - bug fixing
    - main raycast loop optimizations
    - occludee support
    - add "PreCull Ceck" support to lights occlusion culling
    - terrain occlusion culling (specific for unity terrains, initially you will need to split one terrain in more pieces with some utility, or already have more terrains)
    - bug fixing (is never enough!!!)
     
  25. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,241
    Do you think you'll come up with a way to allow LODs in nested folders, like this?

    Tree Group
    -Tree1
    ---Lod_0
    ---Lod_1
    -Tree2
    ---Lod_0
    ---Lod_1
     
  26. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Hello gecko,
    I haven't yet found a "general enough" solution to push in the update, if it takes longer I'll send you a custom script for your specific setup.
     
  27. lazygunn

    lazygunn

    Joined:
    Jul 24, 2011
    Posts:
    2,749
    Making and splitting terrains is quite trivial in Terrain Composer, a great tool, but world composer tends to press upon the need for many terrains as such large areas of terrain can be grabbed. I've gone down the route of try to get as much into as few terrains as possible for now but i'll follow the thread and test to see if some decent perrformance gain can be had
     
  28. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    countdown update

    1 day left until full price (25$)
    get your InstantOC today at only 15$

     
  29. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    New price submitted to the Asset Store

    Few hours left until full price (25$)
    get your InstantOC now at only 15$

     
  30. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    New price submitted to the Asset Store

    Few hours left until full price (25$)
    get your InstantOC now at only 15$

     
  31. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    New price submitted to the Asset Store

    Few hours left until full price (25$)
    get your InstantOC now at only 15$

     
  32. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Lol Fren...

    stop it lol... I am getting spammed with subscribed emails :D

    But then seriously! Get Instant OC! It really works well if your camera view is FP or TP, especially if your env is very controlled! (ie grid based etc)
     
  33. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    I have also thought about optimizing inner loop a bit.. my idea was to precalculate the ray creation calculation, but I found out that the ray is calculated in world space so it didn't work as easy as I have hoped. But I still think it is worth while idea as it still may be faster to precalculate the ray based on it's default position, and then just do multiply with the transform matrix. This will make IOC not be able to change FOV or some other parameters but you rarely do that anyway in games so it could be something! Not sure if it is going to be faster than calling ViewportPointToRay per ray per frame. (But I think it will be)

    Another one is Getcomponent stuff... maybe with clever caching and pooling we may be able to get rid of getcomponent call.. not sure...

    instead of getting the components maybe it can use ontriggerenter like :

    hitInfo.collider.gameObject.SendMessage("OnRayHit", hitInfo.point);

    and then just handle the message events in ioclod script to call UnHide. Ofcourse you would first cache the IOClod script so you don't call "getcomponent" everytime.
     
    Last edited: Feb 4, 2014
  34. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    lol !!!
    thank you :)
     
  35. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Ive played around with the profiler (Unity Pro trial for the Global Game Jam 2014) and it seems to me, that the majority of the work resides in the physics routines, so there is little space for optimization on our side of the game (scripting) without compromising some of the current features/flexibility.
    The "sendMessage" route sounds good to me, I'll give it a try, but as a quick test, even commenting all the stuff inside the main ray-casting loop (if(getComponent() etc..)) seems to change nil.
    Of course, any suggestions are really welcome!
    Doing a custom C# multi-threaded ray-cast could perhaps help, but the overhead of copying and managing the scene-graph in a custom structure (Unity API is not thread-safe) could nil the benefits.
     
  36. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    The new price is still pending..

    Few hours left until full price (25$)
    get your InstantOC now at only 15$


    PS: @castor76 I swear, this reminder is the last one ;-)
     
  37. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    I agree that optimizing the main loop won't give much benefit when it comes to PC or similar better CPU powered platforms as the percentage is pretty good there. However, on mobile I think it is still worth while to get it as fast as it can go. Every little bit helps on those platforms.

    I also agree that physics is the heaviest load of all, so if that is the case, I am thinking there "could" be better ways than firing Physix rays all the time.
    Maybe we can come up with custom optimised raycast detection just made for this purpose. Firing Unity ray is generic function to let user to do anything with it. There is always room for improvement when you narrow down any function to specific needs only. I maybe going overboard here, but maybe custom native plugin function written in C++ or in Assembly with multi-core use will help. I have done this kind of optimization to the custom blendshape script and the result were really good. Both in Android and PC.
     
  38. JBR-games

    JBR-games

    Joined:
    Sep 26, 2012
    Posts:
    708
    First off let me say that I bought this Package a few months back and it worked great.

    I was wondering if you could give me some scripting ideas to adapt to the current package. To Lower over head on Android platform I want to turn off certain objects using code or physics. Instead of turning the renderer on or off I would like to also/or > enable/ disable scripts, > enable / disable other components. Currently not using the LOD portion just using the OC. I have some scripting experience if you could point me in the right direction, thank you
     
  39. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Hello JBR games,
    thank you for your purchase and your appreciation!
    Sure, I'll be glad to help.
    To be able to turn on/off specific components (in addition to the renderer) you could do something like this:
    grab a reference to the desired component/script in the Awake method, turn it off in the Hide() method and back on in the UnHide() method:

    Code (csharp):
    1.  
    2. public class IOClod : MonoBehaviour {
    3.  
    4. private MyComponentClass myComp;
    5.  
    6. public void Awake() {
    7. myComp = GetComponent<MyComponentClass>();
    8. }
    9.  
    10. public void Hide() {
    11. myComp.enabled = false;
    12. }
    13.  
    14. public void UnHide() {
    15. if(hidden)
    16. {
    17. hidden = false;
    18. ShowLod(h.distance);
    19. myComp.enabled = true;
    20. }
    21. }
    22. }
    23.  
    You can't disable colliders and/or whole gameobject, as it could no more re-enable itself.
    Let me know if this helps!
     
    Last edited: Feb 9, 2014
  40. ValrikRobot

    ValrikRobot

    Joined:
    Jun 26, 2013
    Posts:
    206
    This looks perfect for my own needs. I too am using TerrainCOmposer and worldcomposer and could really do with a system like this one.

    $MyReliefDemoB.jpg
     
  41. ValrikRobot

    ValrikRobot

    Joined:
    Jun 26, 2013
    Posts:
    206
    Does this system manage LOD's by enabling / disabling mesh renderers, of loading and unloading prefabs?

    Loading and unloading prefabs would have the benefit of being able to only have colliders when close by. This would be very useful to me personally.

    I have PMed you on my intent for this product
     
  42. ValrikRobot

    ValrikRobot

    Joined:
    Jun 26, 2013
    Posts:
    206
    Just re read the original post. The answer was right there...............
     
  43. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Hello ValrikRobot,
    thank you for your interest in InstantOC,
    I have replied to your PM.
     
  44. ValrikRobot

    ValrikRobot

    Joined:
    Jun 26, 2013
    Posts:
    206
    This InstantOC is amazing. It realy has increased the framerate. how long before the update? being able to load game objects would be fantastic for my at the moment. Ive done a Burning test. This has an additional 500 colliders on the object.
    If I had 1000 I have already lost all my amount of allowed colliders. so being able to load a separate object when close enough will be awesome.
     
  45. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,241
    Hey, is this still something you might be able to add?

     
  46. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Hello gecko,
    I'll send you a custom script for your case tomorrow, and will figure out some more general way to group LODs for a next update.
    BTW InstantOC 2.1.0 is nearing completion :)
     
  47. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Hello ValrikRobot,
    glad you liked it!
    The update is nearing completion, have to add some more polish and will then submit it to the Asset Store.
     
  48. ValrikRobot

    ValrikRobot

    Joined:
    Jun 26, 2013
    Posts:
    206
    Hello Frenchfaso

    Excellent, can't wait. The ability to use the terrains and prefabs is going to create so many possibilities!! Gonna be huge
     
  49. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Actually you can already use Prefabs, it's quite common to use them with InstantOC.
    Please take a look at the video tutorials to see some common ways to setup InstantOC (with simple game objects/prefabs and LODs).
     
    Last edited: Feb 24, 2014
  50. ValrikRobot

    ValrikRobot

    Joined:
    Jun 26, 2013
    Posts:
    206
    Just loading it now.

    Does this then include loading prefabs as LOD's then destroying them when switching?