Render points only if visible from another camera 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 !
All you need - projection mapping. Just put additional UV layer on objects which you want to control, add UV project modifier, and add new logic to material. Second camera projects normalized UV coordinates [0;1][0;1], but we can calculate if some point is outside and apply different material to it. Emissive like on first screenshot, or Transparent like on second one.





OK, lets get really freaky!

Of course, you have to render Z-channel to some EXR file (or sequence if you have an animation). Then add more to material: drivers to get camera position, math nodes to calculate distance for sampling point, and little more to avoid another reincarnation of z-fighting problem.

Just one fix to previous: that UV projecting produces "square", so you have to correct aspect (based on projecting camera render), it was 1080/1920=0.5625 to ScaleY.

I love Cycles magic!