Rendering depending on world coordinates

Hi,

I am looking for a method to able/disable rendering GameObjects depending on the world coordinate of the objects (or their parts). For example, assuming that I have many objects in the scene, I want to show only objects (or their parts) whose x-coordinates are less than 100. So basically think of putting a cross-section-plane in the middle of the scene.

In order to implement this, I tried to use DepthMask, however it only blocks the camera’s sight and does not necessarily disable the rendering. This causes a problem when the movable-camera goes passed the ‘DepthMasking’ plane or cube, and the camera is still able to see the objects inside the ‘DepthMask’.
To sum up, I want to turn on/off GameObjects and possibly their parts depending on their coordinates, regardless of the camera’s position.

Will Stencil help? I looked into it, but I felt like it’s very similar to DepthMask in that it’s dependent on the camera’s position.
(For example, if the camera goes into the cube from the example below, the Stencil magic will stop. Am I correct?
Link: Unity 3D - Portal Room Cubes via Stencil Buffer - YouTube )

Again, what I want to do is Cross-sectioning the whole scene like the picture below, without having to care about the camera’s position or angle.

alt text

Thank you very much!

Best,

Keep a list of all GameObjects you want to turn on/off. Each frame, loop through the entire list, check their position, and turn on/off as appropriate.

That’s the simplest way to do it.

For a more efficient (and more complicated) solution, you could look into Quad Trees or Binary Space Partitioning.