Calculate screen area of a 3D object

Hey all,

Can someone tell me how to calculate the “screen area” (i.e. how much of the screen) is occupied by a visible object? Say, given the object’s aabb, distance from camera, screen size, etc, what % of the screen does the object occupy?

Calculate from that the 4 coordinates which are closest to the camera and plug them into…

You will then have a polygon, which would then be easy to figure out what percentage of screen space it occupies.

This won’t work correctly if some of the object is clipped by the camera’s frustum though, right?

Imagine a big standing domino. You are standing in front of it, looking slightly down at it. The four closests point are on the top, but the largest surface exposed to you is the front of the domino.

Any other suggestions?

That is correct. The bounding box trick would give quite bizarre and incorrect information at that point.

In a case such as that, you would have to figure out in some fashion which faces are visible from the camera, run the above calculations adding up the screen area for all the relevant faces.

One possible solution for you would be to see if a ray cast from each individual face both intersects the camera’s near plane…and doesn’t intersect any other face. If a face satisfies both of those conditions it can be added to the mix.

I’m sure if you google about you can find numerous visibility and occlusion tests for a box’s faces. However iirc a lot of them are based on access to the z-buffer.

Yeah, I’m thinking now I may just fudge it based on the magnitude of the bounds and the distance from the camera. I don’t really need a pixel/face perfect number. Thanks for your help.

For something in between, you might like to use this method. Check the section under “Building Occlusion Volumes”.

The basics of it are:

  1. Generate convex hull (you can do this before runtime, and store it as a non rendered mesh).
  2. Test dot product of face normals and camera facing direction to see if they are facing the camera.
  3. Use those triangles to determine screen space.

You could render that off to a render target as just white, and then test how much of the target is white. To help speed vs precision, you could also make the render target say 25% of the total screen resolution.

If you’re doing this on lots of objects every frame it may not be ideal, but its a more accurate solution if required.