I have been working on a pre-rendered game for quite some time, and wanted to add an object to the game with a transparent background but still having and being affected by volumetric fog to match up with the rest of the game. If I turn off the volumetric lighting and check the transparent box, everything works fine, but the moment I turn on the volumetric lighting, the render background is no longer transparent! Is there any way I could get this render to just include the door shown in the image below? any help would be greatly Appreciated!
//EDIT: The following methods will only work if you use an object as surrounding volume, not if the volume is set in the world itself.
If you want to see the fog occluding the object but make the rest of the image around the object transparent, you have to do that in compositing and the help of, for example, a Color Ramp.
Here a scenario: I have put Suzanne in a box with blue fog and there is a pink light shining on it. You can clearly see the pink light on her head and the face is occluded by the blue fog:
But as you can see in the Alpha channel, the background is not black (fully transparent) but grey. Of course not, because if it had no slight opacity there would be no fog visible:
Which brings us to the problem that you have if I understand the question correctly, if I would overlay this image onto some other background (in this case simply a green color) in the Compositor, the background is also affected by the fog:
But what you want is seeing the pink light and blue fog on the monkey head, but the background should be plainly visible without any fog effect obstructing it.
One way to achieve this is the following:
Plug the Alpha output into a Color Ramp and its Image output into the Fac input of the Alpha Over node. Then move the black slider very far to the right side until the background is completely transparent. How far is dependent on how dense and thus opaque the fog is:
Another way would be to put Suzanne in her own collection so that you have two, one just for the monkey and one for everything else (or at least the volumetric fog object!). Then add another view layer and in the first leave everything visible, in the second you disable everything except the monkey collection by unchecking the collection with the fog object:
If you now go to the Compositor you need two Render Layers nodes, one set to the view layer where everything is visible, the other just for the monkey. The Alpha output of the monkey layer goes into the Fac input of the Alpha Over node:
This method unfortunately requires rendering the scene twice, one time for each layer, but when there is nothing in the second layer except for the monkey it should not take too long.
If you do not want to overlay the monkey directly in the Compositor but instead save an image of it with a transparent background, you can use one of the two methods describe above to use a Set Alpha node with the resulting alpha information (here shown with the last method):