# HG changeset patch # User Mahlon E. Smith # Date 1465233832 25200 # Node ID 0e0924ca1b96593bd3df367f820a881eac68234c Initial commit. diff -r 000000000000 -r 0e0924ca1b96 chunked_render.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chunked_render.py Mon Jun 06 10:23:52 2016 -0700 @@ -0,0 +1,101 @@ +# vim: set nosta noet ts=4 sw=4: +# +# Split a single frame into 100 separate pieces, for blender network +# rendering. +# +# Assumptions: +# - Shared storage between all render nodes. +# - A method for simultaneous blender execution on all nodes (even +# just ssh) +# - Re-constituting the image performed out of band (most easily with +# ImageMagick toolset) +# +# Copy this script into the same directory as your blend file, then run +# like so across your render farm: +# +# blender file.blend -b -P chunked_render.py +# +# When all nodes are finished rendering their chunks, you'll have 100 +# separate images. Combine them back into a single image like so, if +# you have ImageMagick installed: +# +# montage -background none -mode concatenate -tile 10x10 chunk_* rendered.jpg +# +# Authors: +# +# Mahlon E. Smith and +# Justin Smith +# +# License: +# +# Copyright (c) 2016, Mahlon E. Smith +# All rights reserved. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# * Neither the name of Mahlon E. Smith nor the names of his +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY +# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +import bpy +import os +import math + +tiles = 100 +t_sqr = math.sqrt( tiles ) + +bpy.ops.wm.addon_enable( module='render_auto_tile_size' ) + +s = bpy.context.scene +r = s.render + +s.ats_settings.is_enabled = True +s.ats_settings.use_optimal = True + +r.use_border = True +r.use_crop_to_border = True +r.threads_mode = 'AUTO' + +count = 0 +for row in range( 1, 11 ): + for column in range( 1, 11 ): + count = count + 1 + filepath = "chunk_%04d" % count + placeholder = "." + filepath + r.filepath = "//%s" % filepath + + if not os.path.isfile( placeholder ): + print( "Working on chunk %d (row %d, column %d)" % (count, row, column) ) + placeholder = open( placeholder, 'w') + placeholder.close + + r.border_min_x = ( column - 1 ) / t_sqr + r.border_max_x = column / t_sqr + r.border_min_y = ( t_sqr - row ) / t_sqr + r.border_max_y = ( t_sqr - row + 1 ) / t_sqr + + bpy.ops.render.render( write_still=True ) + + else: + print( "Another worker already on %s, skipping." % filepath ) + +