Search Unity

Need help getting occlusion culling working...

Discussion in 'iOS and tvOS' started by TouchSoft, Oct 27, 2008.

  1. TouchSoft

    TouchSoft

    Joined:
    Oct 18, 2008
    Posts:
    218
    I've read the unity iphone manual for "Using Occlusion Culling" But after following the steps... nothing seems to be happening in my game.

    Unlike the example in the manual (which has it's view areas setup by rooms) my game is an open environment with buildings and streets.

    I would like to hide buildings that aren't in view or ones that are behind other buildings.

    So what I've done is setup a huge view area and scaled it so all the buildings fit inside of it... then I set the cell size to 40 so just about each building has it's own cell. After previewing or building my occlusion data.. nothing happens... there is no change in the rendering.

    Does anyone know exactly how to work occlusion culling?

    Thanks.
     
  2. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    I'm pooling my ignorance here since I haven't used occlusion culling at all yet, but I did find in the docs where it says something about a property of GameObject called "isStatic" that may have something to do with it.
     
  3. TouchSoft

    TouchSoft

    Joined:
    Oct 18, 2008
    Posts:
    218
    Yes, I have all the meshes set as static.
     
  4. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    Can you post a screenshot of how you have the view areas actually set up? Placing a single, enormous view area over your entire scene might not be the best way to go about this. It's best to set up multiple areas to encompass all the places the camera can get to.

    Ethan
     
  5. TouchSoft

    TouchSoft

    Joined:
    Oct 18, 2008
    Posts:
    218
    The red box around the buildings is the view area.. basically what I need is for the game to not render the buildings that are not in the camera's view.

    Also I should note that I'm using the CombineChildren script... will this cause a problem? or can certain buildings still be occluded.

    Thanks
     

    Attached Files:

  6. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    No, you can't combine all the buildings into one mesh and expect them to then separately disappear when they're occluded from view. For a scene like that it would be best to keep each building its own mesh. Also it would be better to make several viewing areas going along the streets (even if they overlap) instead of one big viewing area.
     
  7. TouchSoft

    TouchSoft

    Joined:
    Oct 18, 2008
    Posts:
    218
    Thanks for the tip!!

    So the height of the viewing area isn't important? And the viewing areas don't have to actually touch the buildings?

    I think once I figure out what the viewing area is actually doing.. I'll have a better understanding of how to lay them out.

    But thanks so much for your advice thus far.
     
  8. TouchSoft

    TouchSoft

    Joined:
    Oct 18, 2008
    Posts:
    218
    The buildings are all separate meshes now ... Still no luck. The editor isn't even displaying changes. Here's how I changed the view areas. (I just don't know what I'm doing wrong) :cry:
     

    Attached Files:

  9. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    The viewing areas have to encapsulate all the areas where the camera can move to... as soon as the camera moves out of these viewing areas everything will be visible regardless of culling data.

    There is a new viewing option in the Scene View for seeing how well your occlusion data is working. It can be found under the "Textured, Wireframe, Tex/Wire" drop down menu. If you don't see any occlusion happening in the Scene View with this viewing option selected then the occlusion data isn't working properly.

    This is a new feature/concept for Unity users so it's going to take some time for people to get their head around how to use it properly. If you'd like I can take a look at your project and set the occlusion up for you once so you can see how it's done properly... just email me your project to ethan [at] unity3d [dot] com. Hopefully by the end of the week we should have an example up on the resources section of unity3d.com of a scene that is set up to use occlusion culling properly.

    Ethan
     
  10. TouchSoft

    TouchSoft

    Joined:
    Oct 18, 2008
    Posts:
    218
    Thanks so much for all your help Ethan. I'll send what I have so far.
     
  11. TouchSoft

    TouchSoft

    Joined:
    Oct 18, 2008
    Posts:
    218
    Just letting everyone know Ethan solved the problem!! In the current version of Unity the occlusion culling will only take place if the camera is tagged as MainCamera.

    Ethan thanks! and you rock! You just made me feel 10x better about my Unity purchase... very helpful support team you all have.
     
  12. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    I had a similarly awesome support experience not long ago. Let's hear it for the Unity team!!!

    Oh, and would you be willing to share an example by uploading a package to this thread so we could all learn from it?
     
  13. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    We'll hopefully have one up by the end of the week on the Unity Resources page. We showed it at Unite and now just need to clean up the project folder a little bit.

    Ethan
     
  14. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Awesome, I can't wait to see it! Does it demonstrate an outdoor scenario? That seems to be the most challenging. Indoor seems like it would be pretty straightforward.
     
  15. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Actually occlusion culling itself will take place for all cameras. Regardless of them being tagged main camera or not.

    It is only the previewing mode in the scene view which basically just uses the position of the game view camera to see the occlusion culling results from the perspective of another camera. In the scene veiw previewing mode only a camera tagged as main camera will use the occlusion preview.
     
  16. TouchSoft

    TouchSoft

    Joined:
    Oct 18, 2008
    Posts:
    218
    I just laid over 200 buildings in my scene which would have easily added up to over 9,000!!! tris ... but after adding occlusion culling.. my tris were at about 800-900!!!

    I feel like I should do a commercial for Unity now..
     
  17. psychicparrot

    psychicparrot

    Joined:
    Dec 10, 2007
    Posts:
    884
    You could do something like those infomercials where you have a 'before' and 'after' shot .. how you lost x no. of polys on the occlusion diet or something ;)

    I could really use a tutorial on how the occlusion stuff works ... I know my game would benefit from it, but I have no idea how it is supposed to work!

    Jeff.
     
  18. TouchSoft

    TouchSoft

    Joined:
    Oct 18, 2008
    Posts:
    218
    Well I know it was mentioned that Unity is putting out a tutorial... but in the mean time if anyone wants to look at the file Ethan edited for me... I've attached it.

    I'm sure it'll be no where as professional as Unity's demo. But here goes..
     

    Attached Files:

  19. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Hi Jeff, did you read this page:
    file:///Applications/Unity%20iPhone/Documentation/Manual/Using%20Occlusion%20Culling.html
     
  20. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    TouchSoft, I'm eager to see your example, but it looks like the attachment didn't come through. :(
     
  21. TouchSoft

    TouchSoft

    Joined:
    Oct 18, 2008
    Posts:
    218
    Hi Brady, What happens when you try to download it? I just did a test download and it worked fine. Is it that you can't see the attachment at all?
     
  22. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    There we go! It wasn't showing up until just now. Sorry.
     
  23. psychicparrot

    psychicparrot

    Joined:
    Dec 10, 2007
    Posts:
    884
    Thanks, Jo.

    And thanks Brady for posting that. I think I get it ... we'll soon see, as I'm currently generating occlusion data for my level!

    Jo - I seem to find it difficult to find things in the docs and I don't know why - guess I just keep putting the wrong things in the search box. Sorry. Glad you pointed me to it, since it all makes sense now thanks :D

    Is this feature going to make it into regular Unity, too? If it works the way it look like it should this should be REALLY useful!

    You guys rock.
     
  24. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Thanks, TouchSoft. After messing with the project, I didn't notice a very significant poly reduction in the stats between the camera looking over everything and the camera being inside the viewing areas, but I did notice a huge reduction in the number of draw calls.

    When outside of the viewing areas, I was getting 3-3.5k tris, and inside I was getting 2.1-2.5k, but the draw calls outside were around 100 versus anywhere between about 15-40 inside. That result is a bit confusing to me, but the reduced draw calls are certainly going to be a boon on the iPhone! (I didn't test it on-device.) You had mentioned getting down to around 900 polys, was there something extra I needed to do in the project to get the same results?
     
  25. psychicparrot

    psychicparrot

    Joined:
    Dec 10, 2007
    Posts:
    884
    OMG the generate occlusion stuff needs a cancel button lol
     
  26. TouchSoft

    TouchSoft

    Joined:
    Oct 18, 2008
    Posts:
    218
    Brady I forgot to mention that I also did some optimization to the scene. I removed the mesh colliders and used Box colliders instead. I also reduced the far clipping plane.

    But I noticed when I set the clipping plane back to default 1000 ... I'm still getting about 800-900 trigs ... and 15-20 draw calls.

    The frame rate stays consistently between 28-30fps.
     
  27. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    That's cool. I'm not sure what I'm doing wrong that I'm getting so many more tris than you.

    By the way, if you aren't using mesh colliders, what are you using for the terrain?
     
  28. TouchSoft

    TouchSoft

    Joined:
    Oct 18, 2008
    Posts:
    218
    Opps I meant to say, I'm no longer using mesh colliders on the buildings. The terrain is still mesh collider.
     
  29. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    And you're still getting 30fps with a mesh collider for the terrain, eh? That's great news!
     
  30. TouchSoft

    TouchSoft

    Joined:
    Oct 18, 2008
    Posts:
    218
    Yes, have you tried testing on the iphone? I added a guiText object to count the tris on the iPhone ... the editor gives me a higher number.
     
  31. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    Ahh, that may be it then. I hadn't tested it on iPhone yet.
     
  32. TouchSoft

    TouchSoft

    Joined:
    Oct 18, 2008
    Posts:
    218
    Something very important just crossed my mind.

    Will occlusion culling work when objects are being placed in the scene dynamically during runtime?

    Let's say I add 2 more buildings prefabs during runtime.. will they take part in the occlusion culling?
     
  33. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Dynamic objects will be culled correctly by the system. So you can have characters running around in your scene being culled by the system
    However occluders themselves can not move or be created / removed at runtime.

    So if you mark a renderer as static but then later move it, you will get incorrect results as in objects popping into view because the occluder no longer exists at a point where the occlusion culling system expects it to be.
     
  34. TouchSoft

    TouchSoft

    Joined:
    Oct 18, 2008
    Posts:
    218
    Thanks for explaining that Joachim Ante .... just one last question. What if my landscape / terrain starts off empty with no objects... and I want to add the buildings dynamically... but the catch is.. all the spots where the buildings will go are predefined.

    Is there a way I can trick the view areas into thinking those predefined spots are filled? Can I use a cube primitive and set it as editor only, and use those cubes as occludes?
     
  35. Bael

    Bael

    Joined:
    Jul 21, 2008
    Posts:
    106
    Anyone else getting CTDs when trying to generate occlusion data? Unity just instantly closes when I try to generate 'preview' occlusion data on my scene (haven't tried the other types). Thinking maybe it was something with my scene specifically, I downloaded the example scene posted earlier in this thread and it crashes in that one as well... the progress bar pops up and almost instantly Unity disappears.
     
  36. Brady

    Brady

    Joined:
    Sep 25, 2008
    Posts:
    2,474
    I'd put together a barebones test package that can reproduce this error and file a bug report.
     
  37. Bael

    Bael

    Joined:
    Jul 21, 2008
    Posts:
    106
    I submitted a bug report with the previous posted example, and also created a barebones scene (attached) that should be set up properly but still causes CTDs when generating occlusion data.

    Its hard to be specific because every scene I've tested crashes - I've not successfully generated occlusion data on any file yet - the progress bar pops up then immediately I'm dumped to desktop. This is on an out-of-the-box Mac Mini I got last year - I can build Unity iPhone projects and play them on my iPhone just fine, I just can't generate occlusion data. Even the example posted earlier builds and runs fine (with working occlusion) as long as I don't mess with the pre-generated data, but if I reset the occlusion data and try and generate it myself it crashes.
     

    Attached Files:

  38. Ricko

    Ricko

    Joined:
    Dec 9, 2007
    Posts:
    169
    IIRC, during the occlusion culling demo at Unite, they mentioned it was using the graphics hardware to generate the occlusion culling data.

    The integrated Intel graphics in the Mini may be causing the problem. Just a guess. Do you have any other hardware to test on with a dedicated graphics card from NVIDIA or ATI?

    Ricko
     
  39. Bael

    Bael

    Joined:
    Jul 21, 2008
    Posts:
    106
    Meh, that sounds a likely culprit. Unfortunatly no, the only Mac I have is the mini - which I bought for iPhone development.
     
  40. kusako

    kusako

    Joined:
    Jun 30, 2008
    Posts:
    33
    Same problem here on a MacBook with GMA950.
    So it might well be grafics card / driver related.

    -markus
     
  41. SteveB

    SteveB

    Joined:
    Jan 17, 2009
    Posts:
    1,451
    Hope you don't a bit of forum-necromancy as I bring a thread back from the dead but...

    ...the reason the visAreas are as thin as they are in the Occlusion Culling demo (Warehouse) is to reduce the amount of draw determination? In other words the fewer cells, and thinner visAres mean fewer cells, then less work the CPU needs to do (iPhone in this case)? If the player(camera) is meant to be jumping or crouching or flying for example, it would require larger visArea volumes and thus a performance loss I'm assuming; how significant are these checks(cpu cost wise) that even reducing the movement space for the camera is crucial?

    Also just to be clear, this is technically Portal Culling (yes I know semantics but Occlusion Culling today, such as in CryEngine2, Unreal 3 and Virtools, is very specific in the vernacular use), so in order to benefit from say inserting a large object in the middle of an open area, I'd need to to create a series of visAreas 'around' this object, correct? ...such as with TouchSoft's city sample?

    Thanks again. :)
     
  42. warby

    warby

    Joined:
    Mar 23, 2009
    Posts:
    162
    why is this view area object not in my unity demo ?! is there a separate unity editor binary just for the iphone ? why cant everybody use this ?
     
  43. AmazingRuss

    AmazingRuss

    Joined:
    May 25, 2008
    Posts:
    933
    I've read a bunch of threads on this, but Occlusion Culling is still mysterious. For example, I have the camera sitting in one view area, but things that are in other rooms/view areas don't get culled except when I move the camera to the very edge of the view area.

    I had similar behavior playing with the demo.

    Can someone explain what Occlusion Culling DOES? I think I am setting it up right, but I apparently don't understand what it's supposed to be doing.
     
  44. minevr

    minevr

    Joined:
    Mar 4, 2008
    Posts:
    1,018
    What are the functions of "Cell Size"? :?: