Is there a way to tell if an object is currently being culled?

Is there a way to tell if an object is currently being culled?

I’d like to perform an LOD operation on the object only if it is not being culled.

renderer.isVisible does not work, it always returns true regardless of culling.

1 Like

Not entirely true. Object is “visible” means that it is used during rendering - say for shadows calculations.

Are you sure you’re not just looking at it in the Scene View?

(I don’t have Pro so I can’t test for occlusion culling or shadow results.)

I setup one cube with “renderer.isVisible” assigned to a boolean every update, and when rotating the camera so the cube is out of view, the cube is culled, the cast shadow remains and the boolean (isVisible) remains true.

I tried it with both the scene and the game view, with same results.

Is there any other way to determine if an object is being culled?

Like Alexey said, how could it be culled if it’s casting a shadow?

This is using Umbra culling. The shadow is still cast yet the object is not there. I don’t know why it happens, unless the object is actually culled after it’s included in the depth pass.

I just want to know how I can find out through code when an object is culled (with Umbra) because isVisible is not working.

Wait, are you saying you’re looking at a shadow from an object that is turned off by Umbra? Wouldn’t that mean that the object is in the Scene View’s camera frustum, and therefore be turning “isVisible” on?

Otherwise, you’re saying that the object is out of view, but its shadow is not, and therefore, can’t be culled? (I have no idea how Unity decides how to cull shadow casters - seems impossible).

Video to clarify is probably best.

Ugh ok, here was the problem…

My cube and plane were being automagically combined into one mesh at runtime, , I just looked at my cube mesh renderer and it said, “combined mesh” so it was being combined with my plane…I guess since they both had default materials, Unity thought it was OK to combine them for me.

As long as my plane was in view, the cube was “in view” and “isVisible” was true… I disabled the plane so it would not be combined and bam, the cube culling and ‘isVisible’ boolean operates properly.

So! ‘isVisible’ can be used to determine whether an object is being culled, however(!) make sure it isn’t being combined into a combined mesh at runtime.

Ah, that makes sense
Actually you just saw the magic of static batching :wink:
It works by creating mesh and attaching it to all batched objects.
Later it will draw only the ones that are visible - so if something is visible you get your combined mesh visible
Though what you are trying to do makes sense - maybe we should consider the way to handle it

Alexey, an option to enable / disable static batching per object (or globally) would be very helpful. :slight_smile:

As it is now, I cannot combine mesh LOD and culling because of this static batching. Unless there is another way…

You can globally disable static batching in player settings
if for object - the easiest will be to just tweak material :wink:

Is there a way to disable batching for the editor? I disabled both batching options but they are still being combined in the editor. I guess I can build to test…

Thanks :wink:

if you disable batching then they are not batched.

if they still appear to be then you have a script that actually combines them, nothing about batching at all.

OK, now I’m not seeing the combined mesh anymore but it’s acting like it is by staying “visible”

By “visible” I mean that all meshes are marked as visible regardless of culling. Only when the camera travels outside of the viewing area the meshes are toggled “visible = false”

I do not see “combined mesh” in the mesh renderer of my meshes anymore though…strange…

The cause is - even when you disable static batching - we still try to batch stuff dynamically - though no combined mesh in that case and only if visible. Also - are you sure that your object is not casting shadows?

I see…And yes, they are set to cast shadows.

Then if the off-screen object can impact shadows calculations - it will be visible.
While I understand that this flag as is isnt very useful to you - what are you trying to achieve?

Ultimately, I am trying to use Umbra culling and LOD.

I have a parent object with two objects as children, a high res mesh and a low res mesh.

The parent has a script that toggles the mesh renderer for each child, based on distance to the camera.

Ideally, I would like to calculate the distance from the camera for only objects that are visible, since this calculation can get expensive for numerous objects.

My main concern is the LOD script and calculating the distance from the camera for multiple objects… Camera distance for 500 objects takes around .5 ms to calculate if “isVisible” is not used…

Is there a better approach to do this?

Yupp, use layers and layer culling distance on the camera instead of wasting time writting code that will perform significantly worse anyway :wink: (unless you have some very specific needs that go over discrete lod levels)

This is being done mainly to keep the vertices below 500k to (I’m hoping) run on on-board graphics GMA950.

I’ll check out layer culling distance with the camera. Thanks guys :slight_smile: