# Rendering Freestyle along with Grease Pencil

I’ve been trying to render a grease pencil drawing on top of a Freestyle rendered object. But, when I do it the Freestyle lines can be seen behind the Grease Pencil object. Is there a way to solve this?

I made an example with a blue circle made with Grease Pencil, in front of a cube rendered with Freestyle.

I’ve tried using Eevee, Cycles and Benchmark.

Viewport:

Render:

This isn't a perfect solution (I don't know that there is one, at least as of 2.82) but when faced with the same problem, I added a utility mesh to put behind the grease pencil object, just so that the freestyle pass knew to obscure whatever was behind the mesh. In order to stop the utility mesh from itself creating freestyle lines, I added to a collection that I then excluded under Freestyle Line Set. I'm animating my grease pencil object using an armature, so I parented the utility object appropriately to the same armature, so it moved in sync with the grease pencil drawing.

Another cleaner possible solution, depending on what your scene required, would be to render the grease pencil object and the 3d environment separately and composite them together afterwards, but that only works if you never want any of the rendered objects in front of the grease pencil drawing (though, of course, you could also composite more than two renders together, but this could get more complicated than the first solution).

• Thank you jwrush! I'll try this method. – nestorantonio Apr 29 '20 at 20:46

I found a workaround using View Layers and the Z Combine node in compositing:

• Put all your GPencil objects and 3D objects in separate collections.
• Create 2 new View Layers with the Copy Settings option (top right). For clarity I named one "GP" and the other "3D".
• In the "3D" View Layer disable the GPencil collection and in the "GP" View Layer disable the 3D collection (by un-checking the box next to the collection's name).
• In the Compositing tab, check Use Nodes and at the bottom of the Render Layers node, change the Layer to "3D".
• Duplicate the Render Layers node and change the Layer to "GP".
• Finally add a Z Combine and link both Render Layers nodes to it, like this:

Now you can switch back to the first View Layer to work with both type of objects visible.

Notes:

• If some of your strokes use transparency (ie: are not fully opaque), you will have to check the Use Alpha box in the Z Combine node and enable Transparent in the Film part of the render options to get a nice result. This in turns means you'll have to add a background back in compositing.
• The result isn't perfect for 3D objects in front of GPencil objects because the freestyle lines are not taken into account in the depth pass, so the lines get a bit chopped off when overlapping. I haven't found a way around that.