How to get list of GameObjects visible by the camera,

I am making a game in which the player can “take a picture”, and all the objects that are visible to the player will be affected in some way. This has proven to be a harder task than I first realized (I currently have 20 tabs open after having done several hours of research on the matter, with implementations in C# and ShaderLab alike). I also haven’t found any example games or projects that could help in this endeavor, despite my best efforts.

For clarity, I’m not looking for IsVisible() or any function that works regardless of obstruction (e.g. a wall or another object that is super close to the camera won’t stop isVisible() from returning true on an object). I’d also prefer not to purchase from the Unity Asset Store, though I’m not afraid to cut my losses if this becomes too difficult on my own.

As an example, imagine 3 cubes within the camera’s frustum planes, colored red, green, and blue; their transform positions aren’t aligned on any axis. The red cube is visible to the player, the green cube is partially obstructed by the red cube, but the blue cube is hidden because of where red and green are positioned. All three objects are considered visible to the renderer, but to the player this wouldn’t be the case. Is there a script, shader, or some combination therein that can detect that the red cube is visible, the green cube is visible, but the blue cube is not visible?

Thank you!

yea, it’s a hard task…

You maybe need to indeed use IsVisible, and then check one by one if all “IsVisible” objects are really visible from the camera, using raycasts, a lot of them, you should create a script that, with a given object, you make raycast over all its surfaces to the camera, and check if it touches another gameobject,. If some of them canr each the caera without any other contact, means the object is really visible.

Or something like this…

:smiley: Bye!

Yes, this makes sense. But what if you have an imported model that has let’s say 100 parts and you only want to grab the visible objects that the frustum sees, I don’t want to apply the IsVisable script to every imported object.