An alpha-based visibility test?

Hi,
Here is what I am trying to do:
Let’s say I have CUBE_A and CUBE_B and a CAMERA (at some pre-specified position), and CUBE_A and CUBE_B are located in the scene such that CUBE_A is in front of (and blocks the visibility of) CUBE_B.

Let’s say then that I want to allow the user to perform a translation on CUBE_B but before doing so test whether the visibility of CUBE_A will change as a result.

So, if I move CUBE_B in front of CUBE_A, CUBE_A will no longer be visible, and in such a case, this translation of CUBE_B is not allowed.

More specifically, I want to test not only whether CUBE_A is still visible but whether the same portion of CUBE_A is visible (since there may be cases of partial visibility blocking).

I was thinking one way to achieve this might be to render an alpha image of CUBE_A where the portion of the cube that is visible to the camera is white and everything else is black. Then compare this image with another alpha image of CUBE_A after the translation of CUBE_B and if the two alpha images are the same, then the translation of CUBE_B is legal.

There may be another way to do this, can anyone provide guidance? Thanks!

If your hardware supports it, ARB_occlusion_query extension might interest you.

Hey,
thanks - that is a great idea… test the number of visible pixels rather than testing each pixel. In some very rare circumstances, the test could have a false negative I suppose, but almost always would be reliable… and would cut down on the overhead of checking each pixel.
But I’m not certain that my hardware does support this.
Anything more generally supported that might be useful?

Occlusion queries should be supported on virtually all modern graphics hardware.