I am trying to find a way to render only parts of the objects and scene that are visible from another camera. As an example, imagine I have two cameras pointing towards an object, the second making, say, a 45° angle with the first one. I want to render the scene from the first camera, and then render on the second a mask with only points that are visible from the first camera (like a visibility mask).
I can do this either using Nodes or Python (or something else). What I can think of now is :
- something similar to the Node Light Path output Is Camera Ray, used as a factor of a Mix Shader in Cycles. However, I would like to use another camera than the one being used for the render.
- In Python, I can render a depth map from the second camera, and then for each pixel, use the camera matrix and the depth information to backproject-it to a 3D point, and evaluate the distance of the first camera to that 3D point. If that distance is greater than the depth of the pixel on the first camera, I know that this pixel is occluded. So I would render it on the mask.
Is there any simpler way to do so ? Thanks in advance for your time !