Rendering of an object with shadow on a transparent background in Blender Cycles

by Svyatoslav Alexandrov
November 3, 2018

Sometimes we need to render just object and shadow, without background. It may be used to product renders with various backgrounds. Or maybe to embed your render on a photo or a video.
Last versions of Blender supports Shadow Catcher. This is an additional object that is not displayed by itself but displays a shadow of the main object. Maybe in release 2.8 version of Blender, it’ll work correct, but for now, it doesn’t.

So, what should we do? How can we get great shadows on a transparent background?
There is a solution. We have to render our scene by layers separately and then just combine them in the compositor. Are you ready? Let’s do the magic.

First of all, we need to prepare our scene. Just add to the scene the main object, a plane and a light source (lamp or meshlight (an object with the Emission shader)). And a camera, of course. Place your main object on a plane surface.

Now let’s spread the objects into layers.
Let’s keep our plane on Layer 1, select your main object and then press M-2-Enter keys. We moved the object on Layer 2. Then select our light source and press M-3-Enter keys. We moved the light source on Layer 3.

Now we need to create 3 render layers:
1 – Background layer without the object and shadow
2 – Background layer without the object but with shadow
3 – Object layer without background

Then let’s select all 3 layers and go to Render Layers. You can find them in Properties panel – Scene tab.
1 – rename (double click) default layer to “Background”
In subpanel “Layer”:
Scene – all 3 layers are selected
Layer – select only the first layer with the plane
Exclude – select only the second layer.

2 – create layer “+” and name it “Shadow”
In subpanel “Layer”:
Scene – all 3 layers are selected
Layer – select only the first layer
Exclude – don’t touch anything. All layers deselected.

3 – create layer “+” and name it “Object”
In subpanel “Layer”:
Scene – all 3 layers are selected
Layer – select only second layer with the object
Exclude – don’t touch anything. All layers deselected.

I highly recommend to switch on “Denoising” option to reduce noise.

Now go to the “Render” tab of “Properties” panel and in the “Film” subpanel select check “Transparent” to render our scene on a transparent background.

Next, we just have to compose our layers to the final image and render. Press F12 button to render our layers AFTER work in “Node editor”. I rendered them before to show you the process, but can’t save correct composite render (maybe I did something wrong).

We got 3 layers and now we’ll compose them.
We need to get “the Object” and “the Shadow” images separately. It’s more flexible to further post-production outside Blender
Let’s go to the “Node editor” panel, and switch to the “Compositing” mode.
1. Check “Use Nodes” and “Backdrop”.
2. Add “Composite” node
Shift + A — Output — Composite
3. Add “Viewer” node, now we can see the result of our manipulations in this window.
Shift + A — Output — Viewer
4. Add our “Render Layers” nodes — one node for each render layer
Shift + A — Input — Render Layers – select “Background”
Shift + A — Input — Render Layers – select “Shadow”

5. Add “Color Mix” node
Shift + A — Color — Mix
A. Select “Divide” mode
B. Connect “Image” output of “Render Layers (Background)” node to second input “Image” of “Divide” node
C. Connect “Image” output of “Render Layers (Shadows)” node to first input “Image” of “Divide” node

6. Add “Invert” node
A. Shift + A — Color — Invert
B. Connect “Image” output of “Divide” node to input “Color” of “Invert” node

7. Add “Set Alpha” node
Shift + A — Converter — Set Alpha
A. Connect “Color” output of “Invert” node to input “Alpha” of “Set Alpha” node
B. Connect “Image” output of “Set Alpha” node to input “Image” of “Composite” node

So, now we have the shadow on transparent background.

8. In “Properties” panel, tab “Render”, subpanel “Output”
Select output file format with Alpha support. .PNG or .TIF, for example. And enable RGBA mode.

Press F12 button to render.
1. Select “Composite” layer and press F3 button to save shadow as image.

2. Select “Object” layer and press F3 button to save object as image.

That’s it. We have two images to flexible post-production. But if you want to get the object with shadows in one image within Blender, in addition to previous steps, just follow next few steps.

1. Add “Object” Lender Layer
Shift + A — Input — Render Layers – select “Object”
2. Add “Alpha Over” node
Shift + A — Color — Alpha Over
A. Connect “Image” output of “Set Alpha” node to first input “Image” of “Alpha Over” node
B. Connect “Image” output of “Render Layers (Object)” node to second input “Image” of “Alpha Over” node
C. Connect “Alpha” output of “Render Layers (Object)” node to input “Factor” of “Alpha Over” node
D. Connect “Image” output of “Alpha Over” node to input “Image” of “Composite” node

Press F12 button to render.
Select “Composite” layer and press F3 button to save your object with shadow as image.

The work is done. Enjoy your results:)

Original article on Russian