Only render part of custom depth buffer based on overlap

Perhaps buying this plugin and examining how it works would help: Outliner in Materials - UE Marketplace

I am not affiliated with the plugin or its author, but I have purchased it and used it before.