Fade out on distance

Ok, I want some guidance about fading out objects on distance, which are the common methods or what should I look for in order to implement this correctly.

I know how to fade out one object, just calculate the distance to a camera and if its over a limit, hide it, if not, show it.

The problem is that now I want to have 10000 objects, and I find really stupid to have one script checking the distance every frame just to show/hide.

Kind of what the Terrain does with the grass in the floor, that fades out at a determined distance.

Hope someone can put me in the right direction.

Thanks.

You want to fade them(they become transparent and fade away) or just hide them when they go over the distance?

Check out Camera.layerCullDistances in the Scripting Reference. You might try fog, too (in the Render Settings) or both.

I could try both approach to see what fits better, I imagine that just making them disappear would not look nice though.

I thought about that but I forgot to mention there are other objects that are farther and that I still want to maintain visibility.

You can use the fog idea, and the cullingmask.

Create two cameras, one for rendering objects at far distances, one for only rendering objects with near distances. Set the “Depth” of the first to 1, this will draw that camera on top.

Then change the visible layers of each camera. (i.e. allow the far distance camera to see the “fardistances” layer but nothing else.)