Skip to content

CommandLineRendering

Malcolm Riley edited this page Jun 21, 2024 · 1 revision
blender --background ${1} --engine CYCLES --scene ${2} --render-output "Renders/${2}-###.png" --render-frame ${3-1} -- --cycles-device OPTIX+CPU

Blender's rendering functions can be invoked from the command-line! An astonishing array of benefits arises from this seemingly-minor feature, especially with regard to workflow automation. Only a little bit of setup is needed to make optimal use of this facility.

Invoking Blender Rendering from the Command Line

Full documentation for this feature is available here. The purpose of this article is to draw special attention to command-line features I have found useful in our context.

Simple Command-Line Rendering

The minimal command syntax to ask Blender to render a file in the background is as follows:

blender --background ${blender_file} --render-output ${output_file_path}

In the above example, ${blender_file} should be replaced with the path to the .blend file to render, and ${output_file_path} with the path to the desired image output. The --background argument can be reduced to the short-form -b, and --render-output can be reduced to -o.

blender -b MetalPlate.blend -o metal_plate.png

This alone has the benefit of allowing one or more instances of Blender to cook while working on other things, though this may cause performance problems on certain computers. Another possibility is allowing the user to schedule renders during off-hours, or rendering on a remote device, such as with AWS. However, rendering a Blender file with more than one scene, or with animations (most likely both), will require some additional configuration.

Rendering Specific Scenes

To render a particular Scene inside a Blender file, one can use the --scene argument (short-form -S, with a capital "S") followed by the name of the scene to render:

blender --background ItemFile.blend --scene brass-gear --render-output brass_gear.png

Creating separate scenes for each thing to be rendered will help leverage this capability; for instance by putting each item model (or a Collection Instance) into its own scene essentially enables the user to select specific things to be rendered from within the Blender file.

Rendering Specific Animation Frames

To render a particular Animation Frame, one can use the --render-frame argument (short form -s, with a lower-case "s")

blender --background ItemFile.blend --scene sand-variants --render-frame "0..3" --render-output "//sand-###.png"

There's something interesting going on with the --render-frame and --render-output arguments in the above example:

The --render-frame argument can accept multiple types of parameter:

  • A single number, to render exactly that frame index
  • A range of numbers, expressed as two numbers concatenated with .., e.g. 0..3 to render frames 0 to 3 inclusive
  • A comma-delineated list of numbers to render those frames, e.g. 3,5,7 to render only frames 3, 5 and 7
  • A + or - token followed by a number to render frames relative to the start or end frame of the Scene, e.g. +3 to render the third frame from the first frame of the Scene (which is not necessarily frame index 3), or -29 to render the 29th frame before the end frame. (The author has yet to find a use for this argument type in this context.)

The --render-output argument can accept a string, and will decode it as follows:

  • A // token will be taken to mean "The file path relative to the location of the Blender file". Thus //RenderOutput/block.png will try to put the render output block.png inside the RenderOutput folder that is itself in the same directory as the source Blender file.
  • Any number of # symbols will be replaced with the frame number, with # symbols beyond the first being used for zero-padding. As such, space-broccoli-###.png will output as space-broccoli-013.png when rendering frame index 13.

The --render-frame argument is not only useful for "conventional" animations, as with sprites of factory buildings. The Animation feature of Blender can be abused to generate variants of items for belt representation as well, for instance with each frame of the Animation being a separate variant. It is simple enough to create Keyframes to view the same model from separate angles, but what about other properties?

As it happens, just about every manipulable Properties field can be Keyframed in an Animation. Consider the Bevel Modifier below:

A cropped screenshot of the Blender workspace, demonstrating the animatable properties of the Bevel Modifier

The dots to the right of each field indicate that it is an Animatable Property, and can therefore be Keyframed; simply click it to do so. Thus, to create belt-only variants from dynamic properties, one can simply advance the Animation Frame, adjust the properties, and set a new Keyframe.

Invoking Python

Just about every aspect of Blender can be invoked using their Python API, and one can invoke Python files or expressions from the command line. To invoke a Python file as a script within Blender's environment, for instance, one can use the --python argument.

While this would probably only be useful for more complex setups, it is given special mention here as the potential for workflow automation cannot be understated.

Table of Contents

Introductory Series

  1. Blender Basics
    How to use Blender
  2. Plates and Beams
    Dynamic and manual Mesh-making
  3. Gears
    Blender Add-Ons, simple Materials, and environments
  4. Corroded Metal Things
    Using Shader Nodes for procedural materials
  5. Gravel Pile
    How to use Geometry Nodes to procedurally generate Meshes, including automatic item variants

Miscellaneous Techniques

Blender-External Techniques

WIP Articles

  • Automatic Decoration: Rivets, Bolts and Fasteners
    A common visual motif is the ever-presence of rivets, bolts, and fasteners on the surface of metal objects. From the humble Assembling Machine to the exotic Spidertron, Factorio machines are a beautiful mess of crudely-fastened metal plates. Manually placing such Objects on the surface of Meshes is too much work, but Blender offers several semi-automated solutions.
  • Creating Compelling Crystals
    There isn't much precedent for effects like this in the base game, but even a relatively simple Material can create compelling images. Even seemingly complex features such as realistic refraction and chromatic aberration are relatively simple to accomplish.
  • Adding Details to Transparent Objects
    No material in real-life is perfectly uniform. Therefore, adding imperfections to the interior of a transparent Object can add realism and visual interest to a render. Whether adding bubbles to a gel or fluid, or adding mineral inclusions to a crystal, this simple method can help.
  • Using Shader Nodes to Rotate an Environment Texture
    HDRIs add realism and character to the lighting of a Scene, but rarely do the light features of these images arrive from the needed direction. Fortunately, there is an easy way to "rotate" the appearance of an HDRI without having to reorganize each and every Object in the Scene.
  • Looping Animations of Procedural Textures - Without Trigonometry
    Creating looping animations of animated procedural textures is fraught with peril - and trigonometry. There is an easier, more flexible, and more comprehensible method; what's more, it doesn't involve using a single trigonometric function. It can be used with 2D or 3D textures - you too can create looping animations of roiling volumetric clouds.
  • Easy Procedural Ores - Including Ground Transitions
    Many Factorio mods seek to add ores to the game - It may be easier than you think to create your own without having to resort to recoloring base-game assets.
  • Holdouts, Shadow Catchers, and Glow Textures
    When making a Factorio mod, sometimes it's necessary to capture only the shadow cast by an Object, only the light or "bloom" that it emits, or only everything except the Object itself. Blender makes alternative rendering techniques very straightforward.
Clone this wiki locally