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

    Z4urce

    Joined:
    Mar 22, 2013
    Posts:
    6
    Hello,

    I have a question about InstantOC.
    So I have a huge open world scene (City) with full of prefabs. I have LOD levels for each prefab, but I can't use them since I'm a free user, so I created all the prefab using the most detailed meshes, and everithing is on it's right place now.

    I'm going to need a LOD solution, and this one looks like it's the best one, but:
    - The manual says that I must create an empty and drop into it all levels of my objects, named: “ Lod_0”, “Lod_1”, “Lod_2”
    - If I do that, I get a new prefab, which use InstantOC, but I have already populated my scene with clones of my original prefab using just the most detailed meshes

    Question:
    Is there a way to apply InstantOC LOD to my previously existing prefabs without putting them into empty?
     
    Last edited: Jun 11, 2013
  2. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Hello Z4urce,
    thank you for your interest in InstantOC!
    One solution could be to put the Lods under your already existing prefab and then remove all the components (mesh renderer, mesh filter, collider, etc.. EXCEPT the transform) from the parent (your existing prefab)
    You should end up with your prefab in the correct position, but updated with the LODs as child objects.


    PS: I would love to see a screenshot of your scene, it seems the perfect case for InstantOC!
     
    Last edited: Jun 11, 2013
  3. Z4urce

    Z4urce

    Joined:
    Mar 22, 2013
    Posts:
    6
    Thanks for the quick reply.
    Okay, I'll give it a try :)


    In a short time, I will be able to send you some pictures and/or video if you want :)
    (You know we've started in blender and then moved to Unity... So we have only old pictures and videos which ones made in Blender.)
     
  4. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Great, thanks!
    If you and your team like the idea, I'll put your project on the "Powered by InstantOC" gallery on the InstantOC webpage.
     
  5. bravery

    bravery

    Joined:
    Mar 26, 2009
    Posts:
    270
    Hi

    I just notice your plugin, I have a situation where all my level assets are instantiated in real time (procedural level generation) so I wonder how your plugin can help me in enhancing the performance of my game?
     
  6. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Hello Bravery,
    thank you for your interest in InstantOC!
    InstantOC is actually the only fully dynamic Occlusion Culling system for Unity, so the only one capable of managing procedural levels.
    Whether InstantOC will boost the performance of your game, depends mainly on the type of scene you have, how many objects there are, and on how much they occlude each other. Please take a look at the InstantOC FAQ and the Manual to gain a deeper insight on InstantOC and watch the Video Tutorials to see how to set up a scene with InstantOC.
    Feel free to contact me for further questions, I will be glad to help!
     
  7. rockysam888

    rockysam888

    Joined:
    Jul 28, 2009
    Posts:
    650
    (bookmarked)
     
  8. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Thanks! :)
     
  9. sgtkoolaid

    sgtkoolaid

    Joined:
    May 11, 2010
    Posts:
    899
    did you fix the flickering of the shadows with the lights?
     
  10. TimBorquez

    TimBorquez

    Joined:
    Mar 18, 2013
    Posts:
    81
  11. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Hello TimBorquez,
    InstantOC (generally) disables the renderer component of culled objects, so the result will be: "renderer.isVisible = false"
    But, when you enable "Realtime Shadows" in IOCcam, the behaviour for near objects is different, InstantOC changes the shader of near objects to an "invisible shader", so that shadows will be cast correctly by culled objects, but it's more lightweight on rendering calculations.
    Be that as it may, "renderer.isVisible" will mostly not behave as you would expect, you will have to do some other checks, like "distance check"
     
  12. TimBorquez

    TimBorquez

    Joined:
    Mar 18, 2013
    Posts:
    81
    ok, thanks for the response :D
     
  13. Z4urce

    Z4urce

    Joined:
    Mar 22, 2013
    Posts:
    6
    Hello, If you remember me, i told you that we've working on a "city" game, and using InstantOC.
    So here is it's webpage:
    http://korosi.tk/
    IndieDB: http://www.indiedb.com/games/the-swindler-alley-arrival
    Steam: http://steamcommunity.com/sharedfiles/filedetails/?id=150923125

    Okay, so I have a problem using IOC:
    I have a high-poly semi-transparent object. I want to use the IOC's LOD function in it, but I don't want this object to act like an occluder. So everything behind it would be visible. But I have no idea how to do this... because if I enable 'LOD only' the object still acts like an occluder... and if I remove it from the IOC layer, the LOD stops working :(
     
    Last edited: Jul 2, 2013
  14. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Hello Z4urce,
    a possible solution to your case would be to setup a custom collider with many holes for your transparent object;
    the transparent object (with LODs) would be hit by some rays, activating the LOD, and some other rays would pass through the holes of the collider, finally hitting (and activating) the objects behind it.

    $Transparent LOD.jpg

    PS: Great Project! Looking forward to play around with the Beta!
     
    Last edited: Jul 3, 2013
  15. gheeler

    gheeler

    Joined:
    Nov 7, 2012
    Posts:
    18
    Ive edited this a bit to work with transparent objects... Ive added a new layer in the inspector for transparent objects. window elements in my scene...
    im using OC only so i dont know if it will work with everything else but it works for me. when a ray hits an object it unhides it then also checks if its a transparent object and if so fires the ray again from the hit point with a different mask. This only works for one depth so windows in windows will not be seen which is enough for me. but you could change the update to call a seperate recursive FireRay() method with a set maximum depth.

    i also disable iocLod after an object is hidden and enable it again when found

    also i dont have any parent child objects so didnt add it to that part of the code

    Code (csharp):
    1.  
    2. void Update () {
    3.     for(int k=0; k <= samples; k++)
    4.     {
    5.         ray = cam.ViewportPointToRay(new Vector3(hx[haltonIndex], hy[haltonIndex], 0f));
    6.         haltonIndex++;
    7.         if(haltonIndex >= pixels) haltonIndex = 0;
    8.            
    9.            
    10.             if(Physics.Raycast(ray, out hit, viewDistance, 1536))   //layers 9 and 10 or layerMsk.value + windowLayerMsk
    11.             {
    12.                 if(iocLod = hit.transform.GetComponent<IOClod>())
    13.                 {
    14.                     iocLod.enabled = true;
    15.                     iocLod.UnHide(hit);
    16.                     if (iocLod.gameObject.layer == 10) {    //my window layer
    17.                         if (Physics.Raycast(new Ray(hit.point, ray.direction), out hit, /*new distance value*/, layerMsk.value)) {
    18.                             if(iocLod = hit.transform.GetComponent<IOClod>()) {
    19.                                 iocLod.enabled = true;
    20.                                 iocLod.UnHide(hit);
    21.                             }
    22.                         }
    23.                     }
    24.                 } else if(iocLod = hit.transform.parent.GetComponent<IOClod>()) {
    25.                     iocLod.enabled = true;
    26.                     iocLod.UnHide(hit);
    27.                 }
    28.             }
    29.         }
    30. }
    31.  
     
    Last edited: Jul 4, 2013
    Arkade likes this.
  16. gheeler

    gheeler

    Joined:
    Nov 7, 2012
    Posts:
    18
    Also I recommend adding a public variable to this for the check distance when an object is checking if its still hidden.
    The scale of my scene is quite small so had to read this whole thread to find the feature as everything was still flickering for me.

    But great Asset for dynamic OC. My project isnt a game but a viewer for user uploaded models. so we load in assetbundles which doesnt support OC
     
  17. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Hello Gheeler,
    thank you for sharing your Mod! Very much appreciated!

    Yep, on the next update, which should have been already released, but is a little bit late :p

    Thank you :)
    I would really like to know a little more about your project, would you be interested in getting a link/screenshot of your project on the InstantOC gallery?
     
    Last edited: Jul 4, 2013
  18. chillersanim

    chillersanim

    Joined:
    Mar 31, 2013
    Posts:
    219
    Hi everybody.
    Back from holiday.

    No update yet? :(

    Well, I can wait ;).
    Haven't done anything yet so no problem.

    I had an idea.
    For the ray's you use a loop through of all pixels on the screen. That can take a time on big screens, before all pixels are used.
    That can be seen when you turn or move the camera fast around, then sometime objects appear first after some frames.
    You can prevent that when you only use each fifth (example!) pixel on the screen and in the next loop throught each fifth + 1 pixel and so on.

    1.
    O _ _ _ _ O _ _ _ _ O
    _ _ _ _ O _ _ _ _ O _

    2.
    _ O _ _ _ _ O _ _ _ _
    O _ _ _ _ O _ _ _ _ O

    3.
    _ _ O _ _ _ _ O _ _ _
    _ O _ _ _ _ O _ _ _ _

    So you get at least all pixels, but get objects in different corners much faster.
    At least in theory ;)

    Greetings
    Chillersanim
     
  19. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    @chillersanim
    Hello you! Welcome back :)
     
  20. chillersanim

    chillersanim

    Joined:
    Mar 31, 2013
    Posts:
    219
    When do you publish the other project on which you are working?
    I'm interested what you are doing.

    Greetings
    Chillersanim
     
    Last edited: Jul 8, 2013
  21. gheeler

    gheeler

    Joined:
    Nov 7, 2012
    Posts:
    18
    Sorry but dont think I'd be allowed do that tbh.

    I thought it wasnt doing every pixel. its doing a random selection using the halton sequence http://en.wikipedia.org/wiki/Halton_sequence
     
  22. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Yep, that's right, it does a random selection with the halton sequence of half of the pixels of the screen; it iterates through them at x pixels/frame where x = "Samples" (the IOCcam value)
    In the next update it will be 1/4 of the pixels of the screen, it's quite enough, and the initialisation of the halton sequence is far more quicker (especially on highres displays like "retina"s (new iPads, etc..))
     
    Last edited: Jul 9, 2013
  23. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Haven't yet fixed a date, should be in a couple of months.
    Like "spoiled" before, it will be AssetStore related, but not available "on" the AssetStore.
    It will be useful to AssetStore publishers with smartphones :)
     
  24. chillersanim

    chillersanim

    Joined:
    Mar 31, 2013
    Posts:
    219
    Oh, I've overseen that with the halton_sequence...
    Well that explains why my tests with my tests with my way haven't improved anything...

    Ok I will wait. ;)
    Event tough that I don't use a smartphone...

    Greetings
    Chillersanim
     
  25. Z4urce

    Z4urce

    Joined:
    Mar 22, 2013
    Posts:
    6
    Well, Hello again,

    I would like to report a small bug:

    If there's no Lod_2 exist, the IOClod reports an error:
    I understand that it is because it needs 3 levels of LOD objects, but you didn't write it to the manual that it require exactly 3 objects:
    Thanks,
     
  26. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Hello Z4urce,
    that's strange, it should work without problems with 2 and/or 3 LOD levels, I'll investigate and report back soon.
    Thank's for pointing this out!

    PS: just for clarity, if you have 2 LODs call them "Lod_0" and "Lod_1" if you have 3 LODs call them "Lod_0", "Lod_1" and "Lod_2"
     
  27. Z4urce

    Z4urce

    Joined:
    Mar 22, 2013
    Posts:
    6
    It works usually, just reports that error once, when the game starts. (Also in your Demo Scene, when I remove the "Lod_2" from the Logo object) ... and it just occurs, when "LOD Only" is not enabled.
    $error.JPG

    I hope it helps.
     
  28. TimBorquez

    TimBorquez

    Joined:
    Mar 18, 2013
    Posts:
    81
    firstly i already bought and used this product and i am very happy with it:)

    i was wondering if there is a downside to setting the layer mask to default or everything and not a custom one, will the game run slightly worse if it does the culling to everything?
     
  29. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Hello TimBorquez,
    thank you for your purchase, I'm glad to hear you're happy with InstantOC!
    The raycasting will check for colliders on all layers of the layermask, so if you have objects with colliders that you don't want to be managed by InstantOC, it's better to move them on a different layer. This optimization should not change much (performancewise) in small scenes with few objects, but it certainly becomes important in big scenes with many objects.
    So as a rule of thumb, yes, place on the InstantOC layers only objects that you want to be managed by InstantOC.
     
  30. TimBorquez

    TimBorquez

    Joined:
    Mar 18, 2013
    Posts:
    81
    ok thanks
     
  31. Caine_00

    Caine_00

    Joined:
    Aug 1, 2013
    Posts:
    13
    Hi there, recently purchased InstantOC and am reading up on the documentation so I can get it properly working. I'm developing something for the Oculus Rift so it's important that framerate is high smooth - hoping InstantOC can do what I can't achieve with Umbra! Will report back once I have a chance to really dive in and get it working.
     
  32. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Hello Caine_00,
    thank you for your purchase!
    Oculus Rift and InstantOC, that's awesome! I can't wait to discover more about your project :)
    Maybe you can find some quick help in the video tutorials too, and feel free to contact me if you need further help with InstantOC.
    I'll will be glad to do some mods/updates to let it work as smooth as possible with the Oculus, so let me know if there are some "corners" to smooth out.
     
  33. Caine_00

    Caine_00

    Joined:
    Aug 1, 2013
    Posts:
    13
    Thank you for your reply - when I was doing some reading on InstantOC prior to purchasing I was very impressed how willing you seem to be to respond to users and make tweaks based on feedback. Thanks for the link to the video tutorials - I'll check those out. From what I've read so far, it shouldn't be too difficult to get this all integrated and running in my project :)
     
  34. Caine_00

    Caine_00

    Joined:
    Aug 1, 2013
    Posts:
    13
    So far really liking this, very easy to get setup and working - I tried a few different approaches with the Oculus Rift Cameras and found out that you can get away with just putting the IOCam script on 'Camera Left' alone (works when placed on both cams too but if you just put it on 'Camera Right' alone it doesn't seem to work).

    One issue I'm having that I'm assuming I'll find the answer to somewhere in the documentation is my scene is inside a house, and when IOCam is on and the front door and the surrounding transparent windows all are set to the IO layer, the door seems to work correctly, but the windows stay disappeared. If you see this and have any ideas let me know, I'll keep reading what I can in the meantime and will update if I find a solution.

    EDIT - Since the windows are static, I'm just using Umbra for their OC.
     
    Last edited: Aug 1, 2013
  35. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Hello Caine_00,
    glad to hear that!
    The "Camera Left" of the Oculus is probably tagged as "Main Camera"; It's perfectly fine to use the IOCcam script only on one of the two (and it should be the "Main Camera").
    Please check if the window objects have colliders and if they are on the right layers.
     
  36. Caine_00

    Caine_00

    Joined:
    Aug 1, 2013
    Posts:
    13
    Interestingly, both cameras are tagged as 'Main Camera'. Thks for the reminder about the colliders, that was the problem exactly, working super well now - off to write you a glowing review :)
     
  37. Caine_00

    Caine_00

    Joined:
    Aug 1, 2013
    Posts:
    13
    Is there a way to have a 'pre-loading' type of collider so that when you are walking down hallways with 90 degree turns it would be possible to have the models pop-in as you are approaching the turn? I've tried a setup with a collider (IOC layer 1) as a parent object to a bunch of objects I wanted to 'pre-load' this way, and still have mesh colliders (IOC layer 2) on the individual models, but that doesn't seem to do it.
     
  38. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    You are welcome :)
    Thank you really much for the awesome review!
     
  39. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    You could try to use a single collider for a group of objects (and no single colliders for each of them). For instance group each room or each straight piece of the hallways and assign each group a single collider (that resembles the shape of the whole group). The colliders of this groups can overlap, and this overlapping should do the trick.
    Let me know if this helps.


    EDIT:
    Better than overlapping you can try this: use a compound collider (shape that resembles the group + sphere collider) with the little sphere collider (marked as "trigger only") placed so that it triggers the group before you can actually see the group; this should act really as a "preloader".
     
    Last edited: Aug 2, 2013
  40. Caine_00

    Caine_00

    Joined:
    Aug 1, 2013
    Posts:
    13
    Thanks for this suggestion it works very well for static objects - what would you suggest for ones that can be moved around? (in that case the orientation of the little sphere collider won't necessarily be where you want it for preloading purposes if the player moves the object)

    One more question, with Oculus Rift since you can turn your head quickly I was wondering if there is a way to widen the scope of the raycasts just a bit further than what is actually visible to the camera so things just to your periphery won't pop out (I didn't want to increase the 'hide' delay too much as I want to keep framerate up, especially if the player runs quickly through a few complicated parts of the scene).
     
  41. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    You are welcome :)
    In this case you could try to raise the Ray Samples, or as a last resort you can mark this objects as LOD only.

    Try this change in the IOCcam script:
    after this line in the Update method
    Code (csharp):
    1. r = cam.ViewportPointToRay(new Vector3(hx[haltonIndex], hy[haltonIndex], 0f));
    insert the following:
    Code (csharp):
    1. r.origin += transform.forward * rayOffset;
    and change "rayOffset" with a negative number, try some values between -10 and -100.
    This just does what you suggested, by offsetting the rays, you slightly widen the scope of the raycast.
    Offsetting them is not the best solution, I'm currently trying to change the direction and let the starting point where it currently is (near camera clip plane).
     
    Last edited: Aug 3, 2013
  42. Caine_00

    Caine_00

    Joined:
    Aug 1, 2013
    Posts:
    13
    Edit - solved issue by putting prefabs from broken scene into new scene.

    And thank you very much for the code tweak above - I'm finding -5 is working well for my setup :)
     
    Last edited: Aug 3, 2013
  43. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    I finally managed to do that :)
    No more popping along the borders!
    I'm currently adding some final touches and will then publish the update to the store (with some other updates and bugfixing), stay tuned!
     
  44. Caine_00

    Caine_00

    Joined:
    Aug 1, 2013
    Posts:
    13
    That's awesome news, as using the work around obviously causes other issues when a first person perspective player is in confined spaces - looking forward to the update :)
     
  45. Caine_00

    Caine_00

    Joined:
    Aug 1, 2013
    Posts:
    13
  46. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Hy Z4urce,
    it helped! Bug fixed
    Thanks :)
     
  47. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    Thanks for sharing!
    currently downloading the Win build because the Mac build does not start on my MacBook :(
     
  48. Caine_00

    Caine_00

    Joined:
    Aug 1, 2013
    Posts:
    13
    Oh darn, I don't have a Mac so can't test the Mac builds - let me know if you aren't able to get the Win version running.
     
  49. frenchfaso

    frenchfaso

    Joined:
    Aug 12, 2008
    Posts:
    479
    InstantOC 1.6 is on it's way to the Asset Store!
    here is the blog post, with all the juicy details and thanks to all the "bug-hunters" and supporters!
     
  50. ruswizz

    ruswizz

    Joined:
    Aug 9, 2013
    Posts:
    1
    Hello! Will work with dynamic objects? with Rigidbody?