Adapting this answer I was able to get a pixel mask in the rendered image for each object in my scene. However, when I have objects that are covered by some other object, their pixel mask covers only the visible part of it. Is there an easy way to get the "complete" pixel mask, which includes the non-visible part of the object as well?
I've tried a couple of things, but they aren't quite ideal:
- Since I have N objects which can cover each other, I've made N different renders in which only one object is visible at a time. That way, I can get the complete pixel mask for each object, but rendering the scene N times is extremely time-consuming
- I've mapped each object's vertices to the corresponding pixels, however what I get is not a uniform pixel mask, but rather a cluster of dots (each one representing one specific vertex). My objects have lots of vertices (they are spheres), so the dots are actually very close to each other, but as I said, they don't quite form a uniform pixel mask. Here's what I mean: