x


How to use two cameras, one for culling one for rendering

This might be an odd question, but for my game I need to show just one area of the setting (imagine a rectangular slice of a terrain) and all objects out of this area need to be culled away. I tried to do this using shaders for clipping, but objects out of the area are rendered anyway, they just are not visible.

My question is whether it's possible to have a culling process in Unity independently of the actual rendering camera, so that the culling camera would determine which objects are out of the visible area (imagine an orthogonal camera pointing downwards with dimensions the size of the visible area), and the rendering camera would cull those that are out of the frustum volume.

Is this somehow possible? If not, how do I cull manually the objects out of my visible area (trees, etc.) and how do I set them invisible to hide them from view - and I don't mean setting them to alpha=0 or some trick to make them invisible, I mean not being rendered at all.

Thanks in advance,

more ▼

asked Jun 02 '11 at 03:32 PM

magarcias gravatar image

magarcias
1 1 1 1

Hey, you could use CalculateViewFrustum() and then TestPlanesAABB() to check for objects within the cameras viewport, then disable all of their renderers. Use google for the functions.

Feb 10 at 03:42 AM Josh707
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

To not render an object, disable it's mesh renderer or the object altogether. Also your idea for culling is not possible.

more ▼

answered Jun 02 '11 at 03:35 PM

Johan 4 gravatar image

Johan 4
412 81 84 97

(comments are locked)
10|3000 characters needed characters left

You could alter the render distance for the layers in real time (which might be a workaround for you). http://unity3d.com/support/documentation/ScriptReference/Camera-layerCullDistances.html

You could trigger this via a collider and a for-loop for either switching the layer for the particular objects inside or altering the distances for your layers.

more ▼

answered Jun 02 '11 at 04:28 PM

save gravatar image

save
8.2k 22 31 62

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2988
x147
x81

asked: Jun 02 '11 at 03:32 PM

Seen: 1254 times

Last Updated: Feb 10 at 03:42 AM