With raymarching I can also check against shadows -> large gif incoming!
The algorithm I use for unshadowed is basically this
We draw a sphere per deferred point light.
So we know the position of the surface of the sphere per pixel.
We also know the position of the light center, the light radius and the camera position.
Therefore we can calculate the depth of the sphere with a pythagoras / cos(alpha) = b / c
c = distance from camera to light.
We can get the cos by making the dot product of (distance from camera to sphere surface , distance from camera to light center).
This way we can get the "b" or distance from camera to halfway between sphere surface entry and exit.
We can double the distance from the surface entry to b and get the whole travel distance for out light through the medium.
We just have to integrate some distance dependent function or fake some integral from the entry of the volume to the exit.
There are cases to consider, for example if the exit is early because an object is closer than the exit of our volume.
And if the camera is inside the volume the algorithm has to change a bit, too, since we now draw with flipped polygons, so our information is about the volume exit and not the volume entry any more.
There may be a better way to do this, but I just sat down with a piece of paper and did the math.
The shadowed algorithm is much much simpler, but much more expensive - we basically raymarch through the volume and check each raystep against our shadow map.
One could also raymarch for unshadowed volumes, but that would be needlessly expensive.