0
$\begingroup$

Is it possible to have blender render one render layer, then before it renders the next, update textures in your materials?

I want to render my first layer, and then use the output of it as an image texture in the second render layer.

This is currently possible if I manually run each layer via the compositor, but I'm looking for a way to automate it.

$\endgroup$
1
$\begingroup$

I'm not 100% sure we can guarantee the order that layers are rendered in but it does appear to be the order they are listed in the scene layers list. With that the easiest way would be to use a file output node to save the first layers to file before the final layer is rendered.

file output node

The bpy.ops.render.render() operator accepts a parameter for the render layer, this is what is used by the node editor. A script could render one layer at a time, saving the layer to a file ready for the next layer. Note that you are walking into the chicken and egg problem, the render you do for the material will not have a material until you finish the render to give it a material. You should make sure that the camera used for each material does not contain an area that relies on any future materials to be generated.

scn = bpy.context.scene
objs = bpy.data.objects
scn.camera = objs['layer1_cam']
scn.render.filepath='//layer1.jpg'
bpy.ops.render.render(layer='layer1', write_still=True)
scn.camera = objs['layer2_cam']
scn.render.filepath='//layer2.jpg'
bpy.ops.render.render(layer='layer2', write_still=True)
scn.camera = objs['final_cam']
scn.render.filepath='//final_render.jpg'
bpy.ops.render.render(layer='final_layer', write_still=True)

If you are placing the renders as a flat plane on the final render, you can automate it without a script by using multiple scenes, each scene can use a different camera, so they aren't all rendering the same thing. You duplicate the scene with the link objects option so that any changes are seen in each scene and to keep each scene in sync when adding new objects be sure to use ⎈ CtrlL->Objects To Scene->Scene... to add them to each scene.

Once the scenes are setup, add a new render layer node for each scene, use scale and translate nodes to position the layer and alpha over to combine them. You can either use the pass index for an object to get a mask matching an entire object or the pass index of a material to get a mask matching a material, which allows you to apply the material to selected faces of an object. The ID Mask node is then used to get the mask. Enable the object or material index in the render passes to have it available in the compositor.

Now when you render the final scene, all the other scenes will get rendered and be composited onto the final image.

multi scene composite

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.