How to draw depth-based volume in real-time Normally when we talk about realistic transparent volumes, we care about refraction (and total internal reflection), and we care about scattering. But there's a much simpler case of volume transparency, where the opacity of the object depends on the distance that light travels through it.

I'm writing a real-time visualization with a forward-rendering pipeline (on WebGL) and I'd like to show transparent solids this way, without having to resort to path tracing. My solids are homogeneous and isotropic, and I'm not interested in scattering or refraction. I just want thin parts of the solid to be very transparent and thicker parts of the solid to be more opaque.

It seems like most real-time transparency algorithms (e.g. OIT) are mainly for getting surfaces/sheets right, instead of volumes, and are more concerned about correct stacking, refraction, and scattering.

It seems like making the colour of the object depend on the thickness of material behind each fragment should be easily achievable with something like an extra depth pass where I draw opaque objects that intersect transparent objects, and back faces of transparent objects, possibly with some extra correction where the notional ray for one pixel goes through a torus-like object more than once. Intuition tells me that this ought to be a standard algorithm, but I don't know of one. Does this algorithm already exist, or do I just need to get my pencil and paper out and write one?
The issue is that an extra depth pass won't cut it. You may need an arbitrary number of extra depth passes. Just imagine the volume between two sinusoidal surfaces, you would have infinitely many alternating z-intervals of volume/empty space as long as you're looking from a specific direction.

Edit:
Taking into consideration the updated formulation, here's my suggestion for a rather general algorithm with different attenuation coefficients $\kappa_i$ for each volume. Note that there are non-trivial parts that are missing, also if you do not require different attenuation coefficients it can be optimized even further.
The algorithm relies on you drawing the volumes pixels in reverse z-order (this is the non-trivial missing part). You draw your volumes in a separate pass. You keep an attenuation density accumulation variable $\kappa$ for each pixel (initialize to $0$), as well as a distance time stamp $\delta$ (initialize to the the $z$ of the far plane, which I will denote $\max$), and a "color" variable $c$ (initialize to $0$). Whenever you draw a pixel:


if $\delta==\max$ and you drew a front face of volume $i$ then:
$$d = \delta-pixelDepth$$
$$c = attenuate(c,\kappa_i,d)$$


Where $\kappa_i$ is the attenuation of the currently drawn pixel (you can simply draw the volumes in the "color" of their attenuation and use that).


if $\delta&lt;\max$ and you drew a back face of volume $i$ then:


$$d = \delta - pixelDepth$$
$$\delta = pixelDepth$$
$$c = attenuate(c,\kappa, d)$$
$$\kappa = \kappa + \kappa_i$$


if $\delta&lt;\max$ and you drew a front face of volume $i$ then:
$$d = \delta -pixelDepth$$
$$\delta = pixelDepth$$
$$c = attenuate(c,\kappa, d)$$
$$\kappa = \kappa - \kappa_i$$
after you've drawn all pixels if $\kappa &gt; 0$:
$$c = attenuate(c,\kappa,\delta)$$


Note that the 4th check handles the case where the camera is inside a volume (and it ends behind the camera), but the frustum is not entirely inside it. Similarly the first check handles the case where a volume is cutoff by the frustum. However, the case where the camera frustum is totally inside a volume is not handled (you can try to check this by verifying that the camera is inside a volume and then simply adding a constant to $\kappa$, then you have to modify the end case too, to check $&gt;const$, or just not have such large volumes).
Note that the $\delta$ part can be handled by the depth buffer. Obviously you can use a compute shader, or use additional buffers to perform all of this. The function $attenuate$ can be standard Beer-Lambert uniform attenuation or whatever else you want. Combining the volumes with the original scene happens by setting the "far plane" for each pixel to the closest drawn solid geometry depth (that is initialize $\delta$ based on what you have in the depth buffer for your solid geometry).