Only show opaque objects behind transparent objects I would like to make certain objects in my scene transparent, but only the parts visible to the camera when opaque. 

Currently, when I make objects transparent, I can see other transparent objects behind them, which I don't want. I only want to be able to see opaque objects behind transparent objects.

This is what happens now:



This is what I want:
The simplest solution is to do three passes:


Render opaque meshes to a buffer (front-to-back, depth read/write on)
Render translucent meshes to another buffer (front-to-back, depth read/write on)
This makes sure that only the closest translucent mesh is rendered.
Alpha blend translucent mesh on top of opaque buffer using opaque depth buffer. (depth read on)
This will take care of opaque meshes blocking translucent meshes and preserving translucent opacity levels. Depth test for values less or equal for small early z test (potential) optimisation.


EDIT: As mentioned below you could use the same depth buffer for the translucent pass and do the alpha blend then, the key is rendering the translucent pass front-to-back and depth write/testing.