best way to render a list of objects

Hi everyone,

I've written a simple PVS (potential visibility set) system for a game I'm working on. It works fine but I'm concerned about efficiency so I'd like to run past you what I've done and see if there are better ways of doing it..

The way it works is pretty standard for a PVS...

1) The game world is divided into a 2D grid of cells

2) I have an offline tool which for each cell works out which objects in the scene are potentially visible (by ray casting many rays to evey object which takes quite a long time but because it's an offline tool it doesn't impact game play)

3) when the game runs it calculates which cell the player camera is currently in and thus knows which objects are visible and which are not.

4) Then what I do (and this is where I'm not sure about efficiency) is to disable all objects which are not visible and enable all objects which are). I only do this when the player changes cells.

The system works fine but I'm concerned that disabling and enabling the objects might not be the best way to do things. It seems to me that each PVS cell contains a list of all objects which I want to render so theoretically I could remove all objects which are in the PVS from the standard Unity rendering system and instead itterate through the PVS list rendering only those objects. I'm not sure this is possible though. Anyone know if it is or how best to do this? The game runs in a web browser so plug ins are not an option.


Tony Oakden

I don't know if what you are looking for is possible, but maybe it's easier to set all non-visible objects to a layer that is not rendered by the camera than constantly enabling/disabling them.

first of all i should say. unity 3 will have umbra as the scene management system. if you need to implement this now you should use layers. create a layer that camera don't render and then iterate through your list of objects and put those you don't want to render in that layer. setting layers is a fast binary operation but disabling and enabling them is a bit heavier. it involves many other lists like collision detection and many others. internals of the engine are not known for us but i think you can test layers and your current solution and see what get you higher FPS. for disabling you should disable just renderer component of those objects and not make them inactive. animations automatically will not run when the object will not be rendered so you don't need to wory about them.