17
$\begingroup$

I'm trying to set up multiple cameras for a scene set in a room. Is there a way to link object visibility to a specific camera? Ideally, a wall or ceiling would not render if it were in the way of the specified camera.

I've tried to get around this by keyframing Restrict Rendering, but that gets difficult to keep track of. I've also tried adjusting the clipping plane, but that clips too much and would also need to be keyframed if the camera moves.

Thanks!

$\endgroup$
2
  • 1
    $\begingroup$ This is not possible as far as I know. Common workflow is to use several scenes instead, each with linked objects but different active cameras. Remove undesired objects on each one. $\endgroup$ Sep 20, 2017 at 17:28
  • $\begingroup$ You can try to use Render Layers. Here's an example: youtube.com/watch?v=VUETvN-qtvk $\endgroup$
    – Giraldi
    Feb 3 at 14:03

1 Answer 1

14
$\begingroup$

This is possible using Drivers similar to the method described in the answer to How to change world background based on active camera?

You should set the Pass Index for each of the Camera objects so as to identify each camera.

pass index

Then add the driver to the visibility of the object being controlled - either the eye icon in the Outliner or the Camera icon - depending on whether you want to control the visibility only in the 3D view or in the final render.

add drivers to outliner

Set the Driver expression to :

bpy.context.scene.camera.pass_index == n

Where 'n' is replaced with the pass_index of the camera from which you want that object to be hidden. Repeat for each object, specifying the relevant 'n' for each driver as appropriate.

Changing the active camera should now hide the object from view. Note that the driver will not necessarily update the visibility but will be updated on the next frame change - so animating the change in active camera on a specific frame will now automatically change the visibility of the objects.

Here I had 4 cameras positioned around the objects - with Pass Index of 1,2,3,4 - with the visibility of the objects (Cone, Cylinder, Torus, Icosphere) driven appropriately and the active camera changing on each marker :

animated

$\endgroup$
4
  • 1
    $\begingroup$ Brilliant! Works perfectly. Thanks for your help! $\endgroup$
    – kopi_bon
    Sep 20, 2017 at 21:49
  • 1
    $\begingroup$ 3 years later (2.9beta) this trick doesn't update the viewport but still works fine for renders $\endgroup$
    – pevinkinel
    Aug 26, 2020 at 15:57
  • 1
    $\begingroup$ I can confirm that it still works in Blender 3.0 (and only for the render view). Another tip is if you want a particular object to show up only for a particular camera, just change it to: bpy.context.scene.camera.pass_index != n $\endgroup$
    – Totomobile
    Dec 30, 2021 at 14:58
  • $\begingroup$ Works for Render Visibility in Blender 3.2 != tip by @Totomobile is helpful. $\endgroup$ Jul 19, 2022 at 10:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .