A ZDepth pass stores the distance from camera for each pixel, and there is a lot you can do with that data once it reaches After Effects. EFX Render Elements Z Depth Tools, from reduxFX, is a set of plugins built to make the most of a ZDepth pass rendered from a 3D application.
The set includes three tools. Z_Depth Compose composites two layers based on their depth maps. Z_Depth Cut selects pixels based on a depth map. Z_Depth Shadow projects a layer onto a depth map.
Version 1.5, released in February 2023, introduced new licensing and improved compatibility with the 2023 release. Compatibility spans After Effects 2024, 2023, 2022, 2021, 2020, and the CC versions back to CC 2014. A demo video is available, and the plugins are listed here as free.