0
$\begingroup$

How can I render all cameras in the blender scene automatically, with multiple resolutions and sampling set per camera? I'm using Blender 2.8

The reason I am looking for automation is the following: when the model is remodelled, the old renders are outdated and new ones must be created. Doing so manually for multiple cameras, with each their own settings, is time consuming (and boring).

$\endgroup$
1
$\begingroup$

You can use a script for that. This repo on github has Render.py. It uses a settings file for each camera (or the default if no camera specific setting is found). So for each camera multiple resolutions and sampling settings can be defined. Put the render_settings.json file in the same dir as the blender file. Open the blender file and goto the scripting tab. Load and run the script.

Render.py script

import bpy
import json
import os

renderPath = bpy.path.abspath("//Renders\\")
print('Render path: ' + renderPath)
renderSettingsJsonPath = bpy.path.abspath("//render_settings.json")
print('Settings file: ' + renderSettingsJsonPath)

def ensureDirExists(file_path):
    if not os.path.exists(file_path):
        os.makedirs(file_path)

def loadRenderSettings():
    file = open(renderSettingsJsonPath,"r+")
    contents = file.read()
    file.close()
    return json.loads(contents)

ensureDirExists(renderPath)

renderSettings = loadRenderSettings()
print('Render settings loaded')

for obj in bpy.data.objects:
    if obj.type != "CAMERA":
        continue

    print('Camera with name "' + obj.name +'" found')

    renderSettingName = 'default'
    if obj.name in renderSettings:
        print('Render settings for camera found')
        renderSettingName = obj.name
    else:
        print('No settings for camera found, default settings will apply.')

    if renderSettingName not in renderSettings:
        print('No render settings for "' + renderSettingName + '" not found, skipping')
        continue;

    bpy.context.scene.camera = obj
    print('Active camera set to ' + obj.name)

    for renderSetting in renderSettings[renderSettingName]:
        resolution = renderSetting['resolution']
        resX = resolution['x']
        resY = resolution['y']
        samples = renderSetting['samples']
        engine = renderSetting['engine']

        fileName = obj.name + "_" + str(resX) + "x" + str(resY) + "_s" + str(samples) + ".png"
        print('Render file name: ' + fileName)

        bpy.context.scene.render.filepath = renderPath + "\\" + fileName
        bpy.context.scene.render.resolution_x = resX
        bpy.context.scene.render.resolution_y = resY
        bpy.context.scene.render.engine = engine

        if engine == 'CYCLES':
            bpy.context.scene.cycles.samples = samples
        elif engine == 'EEVEE':
            bpy.context.scene.eevee.taa_render_samples = samples
        print('Render engine settings set')

        print('Render start')
        bpy.ops.render.render(write_still=True)
        print('Render finished')

render_settings.json

{
    "default": [
      {
        "engine": "CYCLES",
        "samples": 32,
        "resolution": {
          "x": 320,
          "y": 240
        }
      }
    ],
    "Camera": [
      {
        "engine": "CYCLES",
        "samples": 128,
        "resolution": {
          "x": 640,
          "y": 480
        }
      },
      {
        "engine": "CYCLES",
        "samples": 512,
        "resolution": {
          "x": 1920,
          "y": 1080
        }
      }
    ],
    "Camera.001": [
      {
        "engine": "CYCLES",
        "samples": 128,
        "resolution": {
          "x": 640,
          "y": 480
        }
      },
      {
        "engine": "CYCLES",
        "samples": 512,
        "resolution": {
          "x": 1920,
          "y": 1080
        }
      }
    ]
  }
$\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.