Testing how much of an object is visible on camera

I’ve done some searching but am yet to find a solution to this exact problem, so I’d love some tips or to be pointed in the right direction.

High concept of the issue: It’s a simple photography game, and I want to know how much of the object is on the camera (preferably as a percentage of the whole object).

Elaboration: There is an object on the screen, and I want to test how accurate the player has been in taking the shot. Most solutions simply check if the object is partially on screen, and that simply tells me some part of it is visible, but not whether it is completely visible or how much is actually on the screen.

This is a problem in two ways as a character a screenshot is taken of will be considered “visible” if their big toe is on the screen, and also perfectly visible if they are so close that only a single pixel of the entire character was on screen.

And it may be too much, but it would be great for the solution to be applicable to an object also being off camera because it is being blocked. So for example, a character could be partially off screen or partially covered by a wall, and the result is basically the same for what I need here. Attached is a photo showing the cut off (not sure if it helps much).

Current Work: I am currently using TestPlanesAABB to see if the collider is within the camera’s view, and that works fine. I have been attempting to use raycasts to the min and max bounds of the collider also, but this feels like a poor and ultimately limited solution to the problem as it only looks at two points of what could be a complex shape.

If you’d like my to elaborate on anything let me know.

2637912--185585--unityphotoscene2.PNG

This is another solution that I would do myself.

  1. Render the only object to a texture ( low rez ) seen from the camera render it with no light on a black surface with a white material.

  2. Render the object and with the white mateiral along with the rest of the scene in a black material on a non lit scene to a texture. ( low rez )

  3. Render the normal game to the game view.

When the user takes a photo with the camera i would flash the image and while it is flashing i would do a lookup on texture 1 to find the number of pixels that are white and do a lookup on texture 2 to find the number of pixels that are white. That way you can determine how much of the object is occluded or not by the geometry…

I would combine that with some information if the object is “party in the frustum” or “fully in the frustum” or “not in the frustum”.

Cheers
/C