- Home /
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: https://www.youtube.com/watch?v=5DKIP9N-OB4 )
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.
Thank you very much!
Best,
Hi, is what you want something like this http://forum.unity3d.com/threads/simple-cross-section-shader.34508/ but with a cube cuting the objects ? It's possible to have the world position of the current rendered pixel in the pixel/surface shader so it's quite easy to "clip" it if it's inside a cube.
Answer by SilentSin · Jul 31, 2015 at 11:55 AM
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.