Rendering occluded object without loosing it's material

Hello, I found some tutorials on how to render occluded objects with post-processing and custom depth, but their material is getting replaced by uniform colour. Is there a way to do it without loosing the original material?