-
Notifications
You must be signed in to change notification settings - Fork 6
CommandLineRendering
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.
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.
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.
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.
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 outputblock.png
inside theRenderOutput
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 asspace-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:
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.
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.
Return Home.
Introductory Series
-
Blender Basics
How to use Blender -
Plates and Beams
Dynamic and manual Mesh-making -
Gears
Blender Add-Ons, simple Materials, and environments -
Corroded Metal Things
Using Shader Nodes for procedural materials -
Gravel Pile
How to use Geometry Nodes to procedurally generate Meshes, including automatic item variants
Miscellaneous Techniques
-
Saving a Startup File to Save Time
Using pre-configured Startup Files to save time -
Collection Instances for Convenience
Using Collection Instances for easy positioning in renders -
Constraints for Precise Camera Aiming
Applying Constraints to make Camera aiming easier -
Making Molecules - The Easy Way
Create 3d molecular Meshes of nearly any substance imaginable, almost without effort -
Easy Pipes and Tubes
Use Curves to automatically generate stylish pipes, wires, and tube items or entity decorations -
Rendering from the Command Line
Useful command-line arguments for background or automatic rendering
Blender-External Techniques
-
Automatically Processing Renders with ImageMagick
Using command-line tools to automatically process renders -
PNG Optimization
Automatically optimizing PNGs for reduced file sizes
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.