Search Unity

Instant Occlusion Culling - for all versions of Unity

Discussion in 'Works In Progress - Archive' started by frenchfaso, Jan 2, 2013.

  1. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Good Evening Gentlemen,
    I would like to share with You some fancy idea I'm currently working on, "Instant Occlusion Culling".
    Let me explain what I mean:
    "Instant" means zero baking time, no pre-process needed, works like a charm on mobile (tested on iPhone 3GS :) ) and best of all, it's compatible with the free/basic versions of Unity. All you need is colliders for your Models (need them anyway..)
    It is a fully dynamic Occlusion Culling solution, so it works perfectly fine with moving objects too :D

    So, concept web player is here, would love some precious feedback from You! Would You like it on the Asset Store?
    (The minimap shows all the houses been drawn by the engine with and without Instant OC)

    more then 10X performance boost on my MacBookPro (Core i5 - GeForce GT330M)
    insanely awesome on the iPhone 3GS!!! (the same scene is absolutely unusable without Instant OC on the 3gs and with it, it performs pretty acceptable ~ 16-20 fps)

    UPDATE 1
    - added LOD (2 levels of details, but will add more in final version)
    - demo scene is now a little bit more tweakable, you can generate randomly up to 10.000 Houses and adjust LOD distance
    - added "Belvedere" in demo scene ;-)
    - various little optimizations and bug fixes

    Concept Web Player

    NOW AVAILABLE ON THE ASSET STORE - GET IT NOW!

    NEW THREAD HERE




     
    Last edited: Jan 18, 2013
  2. TheMasonX

    TheMasonX

    Joined:
    Nov 9, 2012
    Posts:
    27
    ZOMG! Wow, you have a real gem here sir, I'm quite jealous. If this was in the asset store, I would pick it up in a heartbeat. And not to pry, so if it reveals to much, say no more, but I'm wondering how you managed this. Since it requires colliders, are raycasts involved at all?
     
  3. scarpelius

    scarpelius

    Joined:
    Aug 19, 2007
    Posts:
    966
    Interesting. Can you make a demo with units arranged in a 3D cube?
     
  4. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    It definitely runs a heck of a lot faster when the optimization is on. Presumably this would work great with any scene that has a tonne of occlusion. For me it was like 3fps versus 50fps. You'd think something like this should be a built-in part of Unity.

    I presume you're doing some kind of ray-casts for visibility or something against all those colliders out there in game land, and then switching those objects off that don't get a collision?
     
  5. brilliantgames

    brilliantgames

    Joined:
    Jan 7, 2012
    Posts:
    1,937
    Haha. Its funny I was just brainstorming about a completely dynamic occlusion culling solution. Is this a grid system?
     
  6. SevenBits

    SevenBits

    Joined:
    Dec 26, 2011
    Posts:
    1,953
    This is great! I went from about 5 FPS without OC to a stable 60 with. Nice job.
     
  7. SevenBits

    SevenBits

    Joined:
    Dec 26, 2011
    Posts:
    1,953
    I'd imagine that's what's going on, but there's got to be some optimization, otherwise wouldn't all of those raycasts reduce performance?

    Yes, I'd like to see that as well.
     
  8. Kokumo

    Kokumo

    Joined:
    Jul 23, 2010
    Posts:
    416
    Very impressive; really good.
     
  9. sc3

    sc3

    Joined:
    Nov 2, 2010
    Posts:
    103
    Definitely interested.
     
  10. laakerules

    laakerules

    Joined:
    Aug 29, 2012
    Posts:
    153
    Very very nice, i was thinking about doing this and the way i thought of doing it was disabling all the objects for rendering then doing a raycast and when the ray hit something it would enable that object and stop the ray. But to me it seemed like it would of caused too much lag for each render.
     
  11. Khyrid

    Khyrid

    Joined:
    Oct 8, 2010
    Posts:
    1,790
    I jumped off the edge and looked up a the houses, I could see almost 1/4 of the houses on the mini-map but the fps stayed about 50fps.

    Anyway, yeah put it on the asset store.
     
  12. login4donald

    login4donald

    Joined:
    Jan 3, 2012
    Posts:
    462
    What you have here is insane. The good kind of insane.
     
  13. Ereous

    Ereous

    Joined:
    Aug 29, 2012
    Posts:
    163
    I see their is no Colliders attached to the houses? I think that might make them be a bit slower to "turn on"?

    I did something similar with a grid based system not as nice however. But similar. The models I used were pretty high tris and had many objects and colliders. I had to add a delay to enable them otherwise you'd get a studder as well as only activating colliders for the player when he was in a certain range.. Otherwise the fps would drop like crazy.
     
  14. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    does each thing being culled need to be inside a grid cell? can you supply a demo where the positions are randomised with a button?
     
  15. UnknownProfile

    UnknownProfile

    Joined:
    Jan 17, 2009
    Posts:
    2,311
    This is very good work. There was a huge difference when OC was off than when it was on.
     
  16. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    This is EXACTLY what i need for my game :)
     
  17. janpec

    janpec

    Joined:
    Jul 16, 2010
    Posts:
    3,520
    Optimisation rate is perfect, but there is very visible poping up of occluded buildings. Maybe if you can you should decrease "loading time" of object when occluded or not.
     
  18. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Thank You so much for all your precious, delightful feedback!
    ..currently working on an update with (hopefully) some more juice :)
     
  19. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    That is the only thing that bothered me honestly... and btw how much is this tool?
     
  20. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    Its clearly based on some partial raycasting based on screen pixels, which also explains why it sometimes takes a split second to show a house. For many games this is fully acceptable and it does provide a significant boost in performance.

    However I noticed that while standing still and looking down a road the houses would pop in and out of view quite frequently. You should add a delay before items gets hidden to remove these random artifacts where a house gets "hidden" just because its impact is very small in the current view frustrum.
     
  21. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    This will definitely solve the issues I am getting with full terrains and other detailed objects in my scene, eating precious framerate. will this work for terrains?
     
    Last edited: Jan 3, 2013
  22. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Seems to me he's staggering updates and using a grid. I need to see a non grid world to be convinced.
     
  23. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Goof Evening Gentlemen,
    it's time for an update!

    UPDATE 1
    - added LOD (2 levels of details, but will add more in final version)
    - demo scene is now a little bit more tweakable, you can generate randomly up to 10.000 Houses and adjust LOD distance
    - added "Belvedere" in demo scene ;-)
    - various little optimizations and bug fixes

    Concept Web Player




     
  24. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    Holy Crap dude... this is awesome with LOD, but I noticed that if I turn down the LOD, the texture quality is f**ked and I may not want that to happen... do the textures always have to be LOD? And I like that the Framerate is a constant 60fps. I also wonder how this would perform with particles and Post processing effects... will the framerate be optimised? Can you also test this with shadow casting for pro users?

    Also will you put a delay when the objects draw in? It is not visually pleasing to see objects popping in when I am looking at them...
     
    Last edited: Jan 3, 2013
  25. Fu11English

    Fu11English

    Joined:
    Feb 27, 2012
    Posts:
    258
    Pretty cool but there is far too much "popping" going on. Solve that and you could be on to a winner!
     
  26. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    This is pretty cool. Been working on my own culling system for mobile and it is nowhere near as nice as yours!
     
  27. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Hello Sir,
    thank You for your interest!
    The LOD does not affect Textures, it's the Low res Model that comes with a low res texture (I downloaded it from the asset store)
    If You use your hy-res texture, they will stay hi-res (even with LOD) :)
     
  28. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Hello Sir,
    do You mean the "popping" that comes from switching LOD levels? If yes, please try to increase the LOD distance.
     
  29. Fu11English

    Fu11English

    Joined:
    Feb 27, 2012
    Posts:
    258
    No I mean the delay of the actual models popping into view.
     
  30. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    This. And definitely fix this, and you will have a MAJOR winner :)
     
  31. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I'm sold now I've seen the random generation and 10k houses. It's very well done. I think it's going to be highly useful for people having problems with umbra or need dynamically generated levels.
     
  32. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    Now we gotta find out pricing...
     
  33. HeadClot88

    HeadClot88

    Joined:
    Jul 3, 2012
    Posts:
    736
    I want this!
     
  34. npsf3000

    npsf3000

    Joined:
    Sep 19, 2010
    Posts:
    3,830
    I'm surprised at the enthusiasm... culling/lod logic is pretty easy to do and I believe there are numerous assets already on the store to handle these problems.

    What am I missing?
     
  35. SevenBits

    SevenBits

    Joined:
    Dec 26, 2011
    Posts:
    1,953
    And for those without Unity pro...!

    Will this be released for free? Any ideas on price?
     
    Last edited: Jan 4, 2013
  36. laakerules

    laakerules

    Joined:
    Aug 29, 2012
    Posts:
    153
    Lol the popping cant be fixed without causing a lil more lag, i have completed a system just like this one, very simple on how it works, just 2 scripts used, maybe 3 for the instant occulsion
    .
     
  37. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    I rather have a tiny bit of lag versus seeing my geo pop into the scene... I would love to test this with post FX
     
  38. laakerules

    laakerules

    Joined:
    Aug 29, 2012
    Posts:
    153
    Whats the optimal FPS cause at around 21-23 i can get 5k trash bins to cull perfectly,


    And thanks french, you have rekindled my pasion to start on my old instant culling project! :)

    And part of the fps bieng low on mine is cause i have all the bins falling from the sky and landing in random spots and such
     
  39. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Good Morning Sir,
    yes there are some OC solutions currently on the asset store, but none of them is fully dynamic,
    this one fortunately is, so you have
    - no baking/preprocess (waste of time)
    - fully compatible with procedural generated content/levels
    - fully compatible with moving objects
     
  40. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    The suspense is killing me, and yes, I would love no baking time... the only thing remains is if this will stay optimal if I use postprocessing effects and heavy shadowing, along with lightmapping...
     
  41. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    It is especially the
    that I like. (I being an collaboration sandbox mmo developer in this context, not a unity employee)

    I really like the improvements in version 2. And it seems to me you added the one second delay before you hide, the result is much more stable now. However if I intentionally position myself so that an object becomes only a few pixels I still see the same pop, only slower. If I'm moving I probably wouldn't notice, but when I'm just standing still on the ramp and looking over the roof tops, the popping is very noticeable. I think this could be fixed simply by storing the ray that hit the object and in case the camera position matches(or near matches) try the same ray again when the second is up.

    Just to make this abundantly clear, unless you used mesh colliders that represented the actual rendering mesh and took transparency into account AND raytraced every pixel on the screen you could not get a perfect occlusion culling from this approach! This is not a solution to all the worlds occlusion culling needs. But it is an approach that produces pretty good results with very little setup and no bake time.

    And due to its low performance cost and easy setup. Its one that I'm personally considering to buy, if the price is right and the right customization options are possible. Based on observation I'm guessing its firing rays at random, I would require it to be a fuzzy algorithm that ensured a maximum distance between rays. A grid where it fired a random ray inside each cell would do, but more complex setups are welcome to (each grid cell could be split into X cells, which sub cell was raycast rotated per frame, or something). Also I would like it to fire additional rays in areas that are far off and areas where there is a "significant" difference between depth of neighboring rays hitting different objects. Of course this part needs to be customizable, number of rays and number of extra rays in "interest zones".
     
  42. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    Never said it was rocket science. But its one of them things I know I would never find time to do on my sandbox mmo. And its one of the things that would really boost performance in a situation where I simply cannot bake the occlusion culling. I already added vertex based ambient occlusion based on a similar pattern. If anyone is interested its based on the http://www.youtube.com/watch?v=eeKQAXg-Qo8 approach.

    I don't particularly like the hi-jack, but you're welcome to show case your work. Though I think it would be polite to do in another thread. I look forward to seeing your solution too. :)
     
  43. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    It makes me wonder if I have to use Mesh colliders on every object in my scene if I use this tool, it is kinda wasteful in that sense if I am not interacting with it... and there are multiple parts on the model in question, and if it's a prefab... I have a game that I am making in 2.5D, and would be very useful to keep a slick framerate...
     
    Last edited: Jan 4, 2013
  44. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    In general I'd only recommend using mesh colliders for static objects. As soon as an item rotates mesh colliders have to retranslate which cost performance. I'd say you need a good reason to do something like that. Using the number of primitive colliders needed to approximate the physics for a rotating mesh "should" be faster than using a single mesh collider, even on quite simple meshes. But of course it lacks the same precision. When it comes to all performance estimates like this I'd recommend using the profiler to learn the exact cost of your setup. But I wouldn't hesitate to use ten primitives rather than one mesh collider on moving objects.

    So if you're looking at this solution rather than a baked solution I'm "almost certain" that multiple primitives are what you're looking for in a 2.5D setting. :)
     
  45. npsf3000

    npsf3000

    Joined:
    Sep 19, 2010
    Posts:
    3,830
    Wish I'd realised this before, I'd have made a killing!

    Hmm... I've got a basic idea of a system that can be entirely offloaded to an alternative core, be very performant and should be more accurate that random ray casts. Luckily for you I've got prior commitments so that'll give you head-start :p
     
  46. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    True, thankfully, only my characters are the only thing moving in my scene... I also use prefabs and having things like buildings that use multiple pieces (hopefully this will reduce draw calls)
     
  47. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    Well in that case mesh colliders should work fine. But it sounds like you could benefit from the usually better baked Occlusion culling systems. The way I see it is that this is a tool that will produce acceptable quality for dynamic settings, a 2.5D world where only the player is moving is quite static, so unless you got randomized maps I would recommend baked OC.

    I would guess this tool works on MeshRenderer level, perhaps French should elaborate.
     
  48. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    I also forgot to mention the 3D camera movement for stuff like throwing animations, and special kills (I treat it like a cutscene)... I need to learn how to use the OC system in Unity first...
     
  49. UnLogick

    UnLogick

    Joined:
    Jun 11, 2011
    Posts:
    1,745
    You need to learn to use Unity :p ? Combined read is smaller than this thread. ;)
    http://docs.unity3d.com/Documentation/Manual/OcclusionCulling.html

    You don't have to worry about the camera and such, moving your camera cut-scene style is exactly the same as moving it any other way in Unity. If you have multiple cameras each uses OC based on their view frustrum independently of the others. Something that will be tricky to do with a solution like this.

    The quick summary is select your objects and Mark them as Static Occluders if they can hide stuff and Static Occludee if they can be hidden. Set two settings on the Occlusion tab (Window|Occlusion to open) under bake. I would guess you want Technique set to "PVS Only" and you must set a reasonable Cell Size. For what size is right for you look at your scene view an play with the value. When you see a grid with quite big cells you should be able to bake in less than a minute. Then you got something quick up and running. When the Occlusion tab is open the scene view will show an Occlusion culling window. Instead of Edit go to visualize and select a camera. Move it around and see the OC at work right there in the scene view. :)

    Of course you should set the Cell Size lower when your scene is "final" to gain more performance. The goal is to make cell size small enough that they can be completely occluded by objects in the expected camera trajectories. Bake time goes up drastically but so does performance. Bulk occluding areas can boost performance a lot on bigger scenes.

    Unity OC works for anything where you set up a scene with your 3D in it. But Unity OC cannot be used for sandbox and procedural content that is created at run-time. The fact that this works on Free is of course good news to Free users, but as mentioned there are competing products on the asset store already.

    What I think is really great about this solution is the fully dynamic aspect.
     
  50. KRGraphics

    KRGraphics

    Joined:
    Jan 5, 2010
    Posts:
    4,467
    I will keep this in mind... and I will learn about OC today... mainly with a test scene...