- Home /
Is it possible to check what percentage of an object is visible in a camera's view?
I know it is fully possible to check if an object can be "Seen" or not by a camera. However, I'm curious about another part of the same question. Is it possible to check what percentage of a object is visible? Say, in a situation where the object itself is partially obscured and you need to be able to uncover it, but it only comes "loose" when it's mostly freed.
I think Renderer.bounds and Camera.WorldToViewportPoint are a good start.
Getting an accurate percentage would be difficult. If you also want to exclude any part of the object that is occluded by another object, it gets significantly more difficult. If you can live with some inaccuracy, and not worry about occluding objects, you could create a bounding rectangle in Viewport space and calculate what parts of that rectangle that are outside of a rectangle defined by the points (0,0) to (1,1). There is some code in the following answer you can build on. The conversion in the code are to screen space, so you would need to change them to viewport space and not clamp the values.
http://answers.unity3d.com/questions/691066/how-to-calculate-screen-area-coverage-of-a-3d-obje.html
Your answer