0
$\begingroup$

enter image description hereI 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! enter image description here

$\endgroup$
2
  • $\begingroup$ Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer - like before and after screenshot, what the desired result should look like. What options did you change (screenshots of tweaked settings). Or even a .blend file for others to test. $\endgroup$ Commented Nov 8, 2023 at 8:33
  • $\begingroup$ Well, of course the background is no longer transparent (or at least not fully transparent), because there is volumetric fog. If it were fully transparent you would not see the fog... $\endgroup$ Commented Nov 8, 2023 at 8:39

1 Answer 1

0
$\begingroup$

//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:

basic render

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:

original alpha

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:

foggy background

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:

color ramp

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:

two view layers

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:

use second alpha

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):

set alpha

$\endgroup$
6
  • $\begingroup$ It sort of works, I copy the exact same node setup as you have in the example and it turns out like this: file:///C:/Users/cyrfa/Downloads/EX.jpg. I'm not sure why this is or if my render is simply too noisy. $\endgroup$
    – sypher
    Commented Nov 9, 2023 at 0:29
  • $\begingroup$ @sypher That's a local link to a file on your computer. I cannot open it. $\endgroup$ Commented Nov 9, 2023 at 5:09
  • $\begingroup$ Thats odd, is there any way to upload an image to a comment? Or can I share the file with you? $\endgroup$
    – sypher
    Commented Nov 9, 2023 at 23:11
  • $\begingroup$ You can edit it into your question, but I suspect it is just your volume is very dense - at least in the example I can hardly see anything because it is so dark. The more dense, the less transparent and the harder it gets to separate object from background with a Color Ramp. Too noisy? I used denoising, did you? And did you try the first or second method? $\endgroup$ Commented Nov 9, 2023 at 23:50
  • $\begingroup$ I used the first method, I wasn't exactly sure how to do the second one because my volumetric lighting is in the world settings and not an object. But I just added the image to the post so you can look at it now. $\endgroup$
    – sypher
    Commented Nov 10, 2023 at 0:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .