2
votes

I'm looking for ways to clip an entire unity scene to a set of 4 planes. This is for an AR game, where I want to be able to zoom into a terrain, yet still have it only take up a given amount of space on a table (i.e: not extend over the edges of the table).

Thus far I've got clipping working as I want for the terrain and a water effect:

Look! My trees can float in mid air!

The above shows a much larger terrain being clipped to the size of the table. The other scene objects aren't clipped, since they use unmodifed standard shaders.

Here's a pic showing the terrain clipping in the editor. You can see the clipping planes around the visible part of the terrain, and that other objects (trees etc) are not clipped and appear off the edge of the table. Inside the Editor

The way I've done it involves adding parameters to each shader to define the clipping planes. This means customizing every shader I want to clip, which was fine when I was considering just terrain.

While this works, I'm not sure it's a great approach for hundreds of scene objects. I would need to modify whatever shaders I'm using, and then I'd have to be setting additional shader parameters every update for every object.

Not being an expert in Unity, I'm wondering if there are other approaches that are not "per shader" based that I might investigate?

The end goal is to render a scene within the bounds of some plane.

1

1 Answers

0
votes

One easy way would be to use Box Colliders as triggers on each side of your plane. You could then turn off Renderers on objects staying in the trigger with OnTriggerEnter/OnTriggerStay and turn them on with OnTriggerExit.

You can also use Bounds.Contains.