0
$\begingroup$

I have created two layers (for light/shadow management), and enabled rendering in the Layers tab. each layer has Alpha background.

I am using the Compositor to add the images together before

When I render a frame (F12), the desired result is shown in the viewer (both as rendered image and the viewer image). However, the saved file (PNG) is missing the second layer - in other words it does not reflect the results from the viewer/composite nodes.

Saving as JPG works as intended. But does not allow a transparent background.

What is happening here?

Blender 4.0, Cycles, GPU Compute. This is my compositor node set:

Node set up to render two layers

$\endgroup$
1
  • $\begingroup$ pls provide blend file, thx $\endgroup$
    – Chris
    Commented Jan 12 at 6:36

1 Answer 1

1
$\begingroup$

The problem here is the Mix Color node. The first Image input provides not only the colors, but also the alpha mask of the image. The second image input provides colors which are, in your case with the node set to Add, added on top of the other colors or whatever method you have chosen.

However, this operation does not add/merge the alpha channels. So basically your first image has the color black wherever it is transparent. Colors of the second image get added to this black, but in the result they are still transparent. The color is not lost in the PNG though, as the following example shows: a cube over a plane, with the cube being plugged in the first Image input. The second is the plane added to it. The PNG only shows the cube, but when I go into e.g. Photoshop and say "layer mask > from transparency" you can see in the screenshot below that the image has both cube and plane on a black background (just as it would look like when saved as JPG), but the mask is only showing the cube - i.e. the original alpha channel of the first layer.

layer mask

So, first the more complicated way to get those two layers together:

If you want to combine two layers and for some reason have to add them together (maybe because you have overlapping parts and want to add the colors in that area), you have to use either a second Mix Color node or even better though, since the alpha channel is just float values from 0 to 1, a Math node to combine the alpha channels of both images. Then you need a Set Alpha node with Mode: > Replace Alpha to give the combined image a new alpha channel.

The way you combine them depends on what result you want to achieve or if the opaque parts are overlapping or not. For the Mix Color node you could for example use Add like you do for the images or maybe Lighten. For a Math node of course Add would work as well or Maximum for example.

math node for alpha

Now for the simple way:

The method above is just how you do it if you insist on adding the layers together. Usually to put a layer with transparent background over another (no matter if the underlying layer has transparency or not) you would use the Alpha Over node. This node respects the alpha channels of both inputs and combines them automatically. You have a Factor as well, there you could for example even plug in an alpha mask if the image you want to overlay has no transparent areas.

alpha over

The reason the Mix Color works like this is quite simple: it mixes only the color channels. In almost all parts of Blender where you can set colors, setting the Alpha value to anything below 1 will have absolutely no effect.

But apart from your case this might well be desired. As you can see in the next example, I have rendered an image with transparency (the cube and plane now in one layer), the objects just have a neutral white/light grey. Then I add a colorful image to it and there is no need for masking the color image to preserve transprency, the color will not affect the transparent background (well, technically the colors are added to black, but they won't show in the PNG).

adding colors

By the way, in your Viewer node the result might look correct (also in my example above where the color seems to be everywhere), but this is mostly due to the fact that the background is quite dark and it does not show a checker texture to indicate transparency. Looking at the Composite in the Image Editor you can see a checker texture through the colors:

visible checker texture

$\endgroup$
1
  • 1
    $\begingroup$ FYI, I fixed it using the Alpha Over method. $\endgroup$
    – AJD
    Commented Jan 12 at 21:14

You must log in to answer this question.

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