Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

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:
    477
    Glad to hear this!
    Thanks for your offer, I'm currently testing the "Occludee" code on the Light Probes, this should be a great improvement to InstantOC's lights occlusion culling.
     
  2. Zyxil

    Zyxil

    Joined:
    Nov 23, 2009
    Posts:
    111
    Hi! Just purchased. Very nice asset.

    With Realtime Shadows enabled, I get this exception when running:

    IndexOutOfRangeException: Array index is out of range.
    IOClod.Update () (at Assets/InstantOC/IOClod.cs:240)

    and the feature, of course, does not work.

    A feature that would be very helpful for me would be a radius from the camera where objects will not be culled. In my minecraft clone, there can be a bunch of geometry around and behind the camera that would be helpful to have present.

    Thoughts?
     
  3. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    477
    Hello @Zyxil
    thank you for your purchase!
    Do you get the error only when "Realtime Shadows" is enabled in IOCcam? That's strange, could you please send me a sample scene that exposes the problem, so that I can inspect it?
     
  4. Zyxil

    Zyxil

    Joined:
    Nov 23, 2009
    Posts:
    111
    Thanks, I have started a private conversation with the share link.
     
  5. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    477
    Thank you @Zyxil, I've downloaded the test scene.
    I'll make some tests and report back!
     
  6. Zyxil

    Zyxil

    Joined:
    Nov 23, 2009
    Posts:
    111
    Thanks for the review, @frenchfaso! Works great now.

    I determined that I don't need the tag system and cleaned up the other bits.

    Fantastic product!

    For others that might read this: tagging objects that do not have a mesh will cause the real-time shadows feature to throw an exception.
     
    frenchfaso and hopeful like this.
  7. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    477
    Glad to hear this :)
    Thanks!
     
  8. Zyxil

    Zyxil

    Joined:
    Nov 23, 2009
    Posts:
    111
    @frenchfaso, I'm wondering if the OC raycasts should come from 5 points in the view frustrum instead of only from the camera position. Correct me if I'm wrong, but it looks like the Raycaster underneath the MainCamera where IOC is attached is the source of the casts, right?

    I have lots of small objects on the screen and am seeing a lot of pop-in and pop-out of objects, even with samples at 1500, fov 75 (on 60 camera) and hide delay of 250. The black beyond the foreground green humps is occluded objects that are visible. The screenshot was taken after several seconds of delay to ensure the hide delay had completed.

    IOC visible objects.png

    With four more points of raycasting, one from each corner of the frustrum, these should capture the ojects that are on the edges of visibility or "just out" of sight that will become visible with small movements, like cresting a hill.

    Thoughts?
     
  9. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    477
    Firing rays from more points unfortunately wouldn't help, what counts in occlusion culling are the visible pixels on the 2d screen plane.
    I think the problem could be that the blocks colliders do not perfectly match the shape of the rendered mesh, InstantOC needs colliders to resemble the shape of the objects rather precisely to get the expected results.
    If you send me an updated scene, I'll do some more tests.
     
  10. Zyxil

    Zyxil

    Joined:
    Nov 23, 2009
    Posts:
    111
    OK, in the midst of getting the project into a state fit for others to view it, I figured out the problem.

    My objects had two colliders on them, one of which was for triggers, which required that they be marked convex.

    I removed that one and it works. Duh.

    Thanks for your help!
     
    Last edited: Jun 16, 2016
    hopeful and frenchfaso like this.
  11. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    477
    Glad to hear this!
    Crap, the first time I tested your code I noticed the double collider generation, this should have come to my mind seeing the black spots! :p
     
  12. Zyxil

    Zyxil

    Joined:
    Nov 23, 2009
    Posts:
    111
    No worries. The project is a bit of a mess right now, lots of cleaning and refactoring going on as base architecture is getting built in. Thanks for your help!
     
  13. gamearti5t

    gamearti5t

    Joined:
    May 25, 2016
    Posts:
    19
    hey frenchfaso,

    the asset looks really great! just wanted to make sure it works with speedtree trees without any problems before i purchase it. (w/o problems means i would be fine if the occlusion works great, since speedtree already uses it's own lod system; however if instantoc can even handle the speedtree lod that would be great!)

    thanks!
     
    frenchfaso likes this.
  14. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    477
    Hello @gamearti5t thanks for your interest in InstantOC!
    Should work fine, I'll have to do some tests though and report back.
     
  15. thornebrandt

    thornebrandt

    Joined:
    Mar 22, 2015
    Posts:
    4
    Hello,

    I'm getting a flickering problem with the demo scene.

    I created a blank project in Unity 5.3.5f1, imported the Standard Assets, then imported InstantOC. When I walk around the scene, the assets are all flickering, constantly hiding and showing incorrectly. What am I missing?

    Here is a video of my experience.
     
  16. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    477
    Hello @thornebrandt
    that is weird... I'll test it in a blank project and report back asap.
     
    thornebrandt likes this.
  17. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    477
    @thornebrandt there is a setup error in the demo scene, please do the following:
    • in the InstantOC/Demo Scene/Prefabs folder, locate and select the "Logo" prefab
    • disable "Occludee"
    • enable "Static" (in the IOClod component inspector panel)
    • in the IOCcam component (attached to the main camera) set Samples to 300
    the Logo prefab should look like this:


    Please take into account the following:
    to obtain predictable results, the "PreCull Check" option in the IOCcam component should be disabled
    • while testing in editor with multiple views/windows (camera/perspective + top/left/front/etc..)
    but should be always ENABLED
    • while testing in editor with single-window/fullscreen
    • in every build, test and/or final
    it's a powerful optimization to drastically reduce the "popping" effect of distant/small/sparse objects.
     
  18. thornebrandt

    thornebrandt

    Joined:
    Mar 22, 2015
    Posts:
    4
    I did your suggestions, such as changing the logo prefab to static away from occludee, set samples to 300, and it did improve on the flickering, but it still exists. This happens when PreCull Check is checked or not.

    Here is a video.
     
  19. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    477
    that is even weirder! Did you import InstantOC in a blank Unity project, or in an existing one?
    Opening the demo scene imported in an existing project with custom layers, could be problematic, please try importing it in a blank Unity project.
     
  20. thornebrandt

    thornebrandt

    Joined:
    Mar 22, 2015
    Posts:
    4
    I still have problems with the demo scene flickering. I noticed that the demo scene layers and tags are blank for some reason. If I use the dropdown to try to select a proper layer, the blank layer that the prefab used to be on disappears and the objects don't show up at all when the scene starts. I can't them back unless I reopen the scene. If I don't use the demo scene and make a "IOCcam Layer Mask" layer and apply that to the camera, it behaves wonderfully.
     
    frenchfaso likes this.
  21. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    477
    Glad to hear this!
     
  22. Zyxil

    Zyxil

    Joined:
    Nov 23, 2009
    Posts:
    111
    Hey, @frenchfaso, love the tool.

    I made a small performance change for instantiating large amounts of objects. In IOClod.cs, mark iocCam and shadowDistance as static, give shadowDistance a default value of -1f, and add these checks in Init():

    Code (CSharp):
    1.             if (iocCam == null)
    2.                 iocCam = Camera.main.GetComponent<IOCcam>();
    3.             if (shadowDistance == -1f)
    4.                 shadowDistance = QualitySettings.shadowDistance * 2f;
    5.  
    Hope this helps!
     
    jeromeWork likes this.
  23. Zyxil

    Zyxil

    Joined:
    Nov 23, 2009
    Posts:
    111
    Also, it would be really nice to have a global toggle to enable/disable the whole system. Unless I'm missing something, it looks like the only way to disable the system is to follow the complex steps in IOChud.cs ToggleIOC() which touches every GameObject in the scene.
     
  24. vutruc80

    vutruc80

    Joined:
    Jun 28, 2013
    Posts:
    48
    I have a question. Does InstantOC cull submesh or mesh is the atomic unit for culling process?
     
  25. Ascensi

    Ascensi

    Joined:
    Sep 7, 2013
    Posts:
    577
    @frenchfaso Will InstantOC work on moving objects/fragmented meshes to be demolished (all fragmented pieces have colliders)
    For an example a wall or building falling/crumbing apart. I want to use this with the fragment and destruction kit. I know Unity has a method to cull moving objects but will your asset work for this type as well?
     
    Last edited: Sep 8, 2016
  26. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    477
    Hello @Ascensi sorry for the superlate reply, I totally missed the notification!
    Thank you for your interest in InstantOC!
    As long as game-objects have colliders (you can also use simple trigger colliders if you don't need full collision detection, they are lighter and faster), they will work fine with InstantOC;
    Moving and/or dynamically generated objects are not a problem, in fact, they are InstantOC's specialty :)
     
  27. Koru

    Koru

    Joined:
    Feb 14, 2012
    Posts:
    39
    Hi, I recently checked your asset and it works great, this is something we really needed :). But there is one issue that I think makes your plugin mobile UNfriendly. I've built your scene on Galaxy S7 and loading time was way too long. I did a quick research and profiler showed 7.1MB allocation in IOCcam.Start() method. You are allocating 2 arrays of floats related to device screen size, what makes on Galaxy S7 921600 records each.

    I didn't check what those arrays are for, I personally don't like to mess up with plugins' code. That is why I have a request to think about reducing loading time on high resolution devices and make an update. Anyway, I still enjoy your plugin and keep up the good work!
     
    frenchfaso likes this.
  28. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    477
    Hello @Koru
    glad to hear you like InstantOC!
    The 2 arrays are generated once at start for the "quasi random" Halton sequence, that InstantOC uses to fire rays.
    With smartphone displays getting pretty high resolutions, this can delay start-up times..
    I'll publish an update that takes care of this, in the meantime, you can safely change the first line of code in the "Start" function of the "IOCcam" script, from:
    Code (csharp):
    1. pixels=Mathf.FloorToInt(Screen.width*Screen.height/4f);
    to:
    Code (csharp):
    1. pixels=Mathf.FloorToInt(Screen.width*Screen.height/8f);
     
    Last edited: Oct 5, 2016
    jeromeWork, villeHelin and hopeful like this.
  29. Cyber_2016

    Cyber_2016

    Joined:
    Aug 27, 2016
    Posts:
    46
    Excellent Asset. . :D Any chance of an updated version ? Also the demo with the 5000 houses was Epic! ! Also I did have a problem with this Asset conflicts with other assets that use Raycasting Ex: Third person Camera jerks something fierce when used with this Asset. . If I turn off Collision , than Np
     
    frenchfaso likes this.
  30. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    477
    Thanks @Cyber_2016 ! Glad you liked it :p
    I'm still working on an update, I'm currently experimenting with shaders to see if it's possible somehow to optimize the raycasting.. but before that, I'll try to publish a long awaited bug-fix release, primarily to fix the demo scene (which is setup incorrectly!) and the slow boot time with super-high res displays.
     
  31. Ascensi

    Ascensi

    Joined:
    Sep 7, 2013
    Posts:
    577
    I'm working in VR and finally found a solution for now -stopped using IO Clod.


    IO Ccam.png Maze.png I may have set up my IO Clod with IO Ccam wrong like in a conflicting way.

    Anyway here are my settings, it might help you.
     
    Last edited: Nov 5, 2016
    frenchfaso likes this.
  32. Cyber_2016

    Cyber_2016

    Joined:
    Aug 27, 2016
    Posts:
    46
    K.. Yes, sounds great.. I'll try the New version as soon as you upload to the Asset store.. Thanks.
     
  33. villeHelin

    villeHelin

    Joined:
    Mar 27, 2013
    Posts:
    13

    Thank you for the information! I've also optimized this so that the array is static and calculated only once when the app boots, not every time the scene is loaded.

    Anyway, I've also optimized & simplified the implementation a little bit; changed a recursion to iteration, optimized loops, etc., and taken away all LOD code as in my project I don't use LODs, all geometry is close to the camera... If you want this alternative version just let me know. It has given my project a big boost when compared to the official release which was also quite fast...
     
    frenchfaso likes this.
  34. villeHelin

    villeHelin

    Joined:
    Mar 27, 2013
    Posts:
    13
    A question: This big screen related array, could it be saved to disk per application, and loaded from there later, so the app would need to calculate it only once?

    EDIT: This might not be a good idea; I tested this on my Nexus 5X and it was actually faster to calculate the arrays than load them precalculated from the disk... Phones really have slow hard drives even though they are memory chips.
     
    Last edited: Jan 3, 2017
    frenchfaso and hopeful like this.
  35. papathor

    papathor

    Joined:
    Oct 8, 2012
    Posts:
    33
    Hi,

    I just bought your asset and I'm using Ascencsi's values for IOCcam in my own VR project. It works fine when the map is super small (the perfomance is about the same for using IOC and disabling it). However when the map gets bigger (30 by 30 tiles or more, which is still quite small as each tile is only a little bigger than the player), I get massive frame drops. In the profiler it seems IOC is eating up a TON of cpu.
    I tried this by attaching the IOClod script to every gameobject, which someone above says might be the cause of the scaleability problem. Is this true?
    I'm trying to do it without IOClod now, but am running into problems. The procedurally generated environment (generated once at the beginning of the game) consists of Walls, floors, doors, and tables/chairs/desks/couches, all of which are on the "Transparent/FX" layer so that the pathfinding algorithm knows they're obstacles. The smaller objects (like desk ornaments) that are populated on the desks and tables are just on the default layer. I removed the IOClod script from all gameobjects. I've created an IOC tag and applied it to everything on "Transparent/FX" as well as the desk objects on the default layer, and set the tag in the inspector for IOCcam just like Ascencsi did. I've set Layer mask to "Transparent/FX". I created a separate empty layer called "Occludee" and set that to the Occludee Layer in IOCcam.
    Currently this doesn't even work very well for the super small map, and only seems to work for the walls and some of the desks, also with big performance hits.

    Does it sound like I've set up something wrong or what?

    Thanks so much for the help!
     
    frenchfaso likes this.
  36. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    477
    Hello @papathor , I just replied to your email, let me know if it helps!
     
  37. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    4,958
    I'd be curious to know how the above situation works out. :)
     
  38. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    477
    I'll keep you updated, in the meantime a couple of quick InstantOC tips:
    • if there is a frame drop when enabling InstantOC the first thing to check is the console, are there any errors?
    • if there are errors in the console, most of the times it's a setup problem with layers/tags/colliders
    • the "static" option in InstantOC IOClod is meant for small/sparse/distant objects, and manages max 2048 objects/groups, do not use it for big objects like buildings, walls, etc..
    • the occludee option in InstantOC is primarily meant for transparent objects, there is no need to mark small, non transparent objects as occludees
     
  39. Cyber_2016

    Cyber_2016

    Joined:
    Aug 27, 2016
    Posts:
    46
    Hello frenchfaso! Any chance of a New updated InstantOC? :D
     
    frenchfaso likes this.
  40. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    477
    You are right :p
    I wasted (or maybe this was not a total waste..) a lot of time exploring various hazardous optimizations, but they turned out not to be very useful... (custom raycasting, shader-assisted raycasting, etc..).
    I will try to make ASAP a little update which fixes some long-standing issues (demo scene occludee bug, slow init on high-res displays).

    PS: I'm thinking about stripping away the LOD stuff from InstantOC, this would clean up the code and make it more maintainable, how many of you actually use InatntOC LOD system?
     
  41. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    477
    I started a poll, please take your side!
     
  42. JBR-games

    JBR-games

    Joined:
    Sep 26, 2012
    Posts:
    570
    If there is a saving on performance to remove lod calculations from ioc then i would be good with removing it. I have used it in the past with projects but im unsure if i would want to use it moving forward.
     
    frenchfaso likes this.
  43. HonoraryBob

    HonoraryBob

    Joined:
    May 26, 2011
    Posts:
    1,101
    This looks like exactly what I need, although I'm wondering how it can do realtime occlusion culling on procedural geometry (how does it possibly do raycasting that quickly)?
     
    frenchfaso likes this.
  44. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    477
    It uses the integrated physics raycasting, which since Unity 5 is pretty quick, with a bunch of custom optimizations to make "educated guesses" on where to fire rays and keeping the number of needed rays low.
    That also means you need colliders (they can also be triggers only, which are lighter).
     
  45. andywatts

    andywatts

    Joined:
    Sep 19, 2015
    Posts:
    42
    Poll is closed, but I'd vote "Yes- break out LOD".
    I don't need LOD and would like the simplest possible cam and GO scripts.
     
    frenchfaso likes this.
  46. BonsaTech

    BonsaTech

    Joined:
    Dec 22, 2015
    Posts:
    73
    Is there any updated about the Speedtree integration?
     
  47. Aubrey-Falconer

    Aubrey-Falconer

    Joined:
    Feb 13, 2008
    Posts:
    434
    Hi @frenchfaso ! I'm concerned that you are calculating the HaltonSequence only once, at startup. What about games which allow the player to customize their screen resolution via an ingame settings panel? Wouldn't this result in further play during the customized session occurring with suboptimal Halton values?

    Edit: Also, why not use the https://docs.unity3d.com/ScriptReference/GameObject.FindGameObjectsWithTag.html method rather than iterating every object in the scene?
     
    Last edited: Apr 13, 2017
    FlockingBehavior likes this.
  48. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    477
    Hy
    @BonsaTech sorry for the long delay!
    Not yet, should be able to answer this in the next couple of weeks though.
     
  49. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    477
    Hello @Aubrey-Falconer the halton-sequence output is in 0.0 - 1.0 form, so no problems when changing res at runtime (it's always expressed in percentage of screenspace).
     
  50. Aubrey-Falconer

    Aubrey-Falconer

    Joined:
    Feb 13, 2008
    Posts:
    434
    Hi @frenchfaso! Perhaps I'm missing something. I understand that Halton divisions are expressed in screen space, but the InstantOC code appears to initialize a resolution-dependent number of Halton divisions in the main camera's Start method. Doesn't this mean that any InstantOC-powered app would be running with a suboptimal number of Halton divisions if resolution is changed at runtime?

    pixels = Mathf.FloorToInt(Screen.width * Screen.height / 4f);
    hx = new float[pixels];
    hy = new float[pixels];
    for(int i=0; i < pixels; i++)
    {
    hx = HaltonSequence(i, 2);
    hy = HaltonSequence(i, 3);
    }
     
    FlockingBehavior likes this.