Alpha transparency not included in Z-depth - issues with compositing

I have a scene that uses two render passes, one with volumetric scattering, and one with normal mesh lights. I have composited the two based on Z-depth, this works well for the art style I am going for, and works for everything apart from the little planar meshes created by the ivy generator that I have now started trying to implement.

I have used an alpha mask to make the ivy transparent around the leaves (works fine in the normally lit render, see below). However, compositing the two render passes based on Z-depth now results in undesirable artifacts around the ivy (see second image below).

The Z-depth currently record the depth the texture plane that the ivy is on, rather than take into account the complete transparency around the edge of each texture. Is there a way to include transparency in the calculation of z-depth? If not, does anyone have any ideas on how I can composite my volumetric layer into the normally lit layer and not have issues with the transparency on the ivy?

Normally lit render (no compositing. Note: the alpha transparency around the ivy works correctly):

The render above composited with the volumetric lighting render based on the z-depth (note edges of ivy are deemed to be closer to the camera because they are on a plane):

mmmm volumetric compositing… fun fun fun… i would suggest trying to get it all working together in the beauty render rather then trying to add it in in comp… mainly because volumetric compositing requires something called deep compositing (… because you can volumetric info at random z-depths with random values, you need to be able to store multiple values per pixel… rather then just one (which zdepth does)…

You could try using the mist output instead (as that handles transparencies)… but yeh, comping with volumetric data… you can only put stuff infront of the volumetrics or behind… not inside.

Thanks, I was hoping that wasn’t going to be the case :wink: I can’t do the volumetrics in my main pass because I only want one light to generate that effect (any more and it is rather detrimental to my whole image). In this particular case I think I may be able to do some manual editing of the z-depth pass and make it work, but that could be very time consuming in some more complicated cases.

Can you use a mist pass for a depth pass as it respects alpha mapped planes.

Thanks, unfortunately the mist pass appears to be quite different from the z-depth pass. I don’t quite understand what the mist pass is calculating (the result lacks any detail…I will get a pic when I’m home).

You can setup the mist pass such that it is in fact the Z-Pass, but antialiased and respecting alpha from textures.
The way to do it is like this:
Go to the world settings and open “Mist Pass” settings, set Start to zero, Depth to something big (more than a distance from camera to furthest object in the scene, let’s say 100), set Falloff to linear.

This can be used as a depth input of Z-Combine node. Remember to use Mist as both inputs, so you need mist for both render layers.
When you multiply Mist by the value that you set as “Depth” - the result will be equal to Z, but better.

Thanks Bartek! I’m just re-rendering with this set up and a quick test prior suggested that it was going to do exactly what I needed. :slight_smile:

Yep mist is awesome and zdepth mostly sucks and I don’t understand why. Really why not just use mist…

That is really cool to know, thank you Bartek! Seems then that Z Depth could be replaced with Mist then?