Featured post

new redirect for blender.org bpy docs.

http://www.blender.org/api/blender_python_api_current/ As of 10/11 november 2015 we can now link to the current api docs and not be worr...

July 08, 2011

Tile Renderer (Make Big Renders)

This post was written quite some time before I completed a decent version of the tile renderer. Monster Tile Renderer - for more information, or search this blog or checkout the github page
import bpy
# tile rendering 0.1
# Dealga McArdle (zeffii) 2011-July 8.

# fill in how many tiles you want, must be non zero.
n = 2 # n tiles wide (x)
m = 2 # m tiles high (y)
percentage_of_current = 300
total_tiles = n*m
location = "/home/zeffii/"
filename = "MyRender"
filetype = "png"


name_list = []
for j in range(m):
    for i in range(n):
        name_list.append(str(i+1)+"_"+str(j+1))

border_list = []
wslice = 1/n
hslice = 1/m

# use border and crop
bpy.context.scene.render.use_border = True
bpy.context.scene.render.use_crop_to_border = True

# set resolution percentage
bpy.context.scene.render.resolution_percentage = percentage_of_current

for cell in name_list:
    wdiv, hdiv = cell.split("_")
    bmin_x = float((int(wdiv)-1)*wslice)
    bmax_x = float(int(wdiv)*wslice)
    bmin_y = 1.0 - (float(int(hdiv)*hslice))
    bmax_y = 1.0 - (float((int(hdiv)-1)*hslice))
        
    str_borders = ("bmin_x="+str(bmin_x),
                   "bmax_x="+str(bmax_x),
                   "bmin_y="+str(bmin_y),
                   "bmax_y="+str(bmax_y))
                   
    border_list.append((cell,str_borders))

    # set border for this tile
    bpy.context.scene.render.border_min_x = bmin_x
    bpy.context.scene.render.border_max_x = bmax_x
    bpy.context.scene.render.border_min_y = bmin_y
    bpy.context.scene.render.border_max_y = bmax_y 
    
    bpy.ops.render.render()
    RR = "Render Result"
    bpy.data.images[RR].save_render(location+filename+"_"+cell+"."+filetype)
    print("rendered", cell)

2 comments:

  1. Hi Dealga,

    a nice little script. Because of no way (yet) to pause rendering in Blender, I try to create an addon based on your idea. So I extend your script with a function, that compose the rendered tiles to one final image. But there is a problem. It needs too much time to import tiles and create a final image. Normally I use ImageMagick to do that work. But as addon, it has to work without. I try PIL instead, but that also doesn't work. No idea why, but I even search a way without any installations.

    So I ask you, as an Blender Python script expert. Is there a fast way, to compose rendered tiles to a final render?

    Here's my script. I hope you can complete the function 'compose'. I am overchallenged with.

    [code]
    import bpy
    import math


    dir = "d:/blender/tiles/"
    fname = "final"
    tname = "tile"
    itype = "png"
    rr = "Render Result"

    bds = bpy.data.scenes["Scene"]
    bcs = bpy.context.scene
    bdi = bpy.data.images
    br = bds.render

    resx = br.resolution_x
    resy = br.resolution_y

    perc = br.resolution_percentage

    tilex = br.tile_x
    tiley = br.tile_y

    br.use_border = True
    br.use_crop_to_border = True

    br.pixel_aspect_x=1.0
    br.pixel_aspect_y=1.0

    tlist = []
    blist = []

    x = math.ceil(resx/tilex)
    y = math.ceil(resy/tiley)

    for j in range(y):
    ymin = tiley*j
    ymax = ymin+tiley
    if ymax > resy:
    ymax = resy
    for i in range(x):
    xmin = tilex*i
    xmax = xmin+tilex
    if xmax > resx:
    xmax = resx
    blist.append([xmin/resx,xmax/resx,ymin/resy,ymax/resy])
    tlist.append(str(i+1)+"_"+str(j+1))


    def renderscene():
    a = 0
    for cell in tlist:
    xt, yt = cell.split("_")

    print(cell,blist[a][0],blist[a][1],blist[a][2],blist[a][3])

    br.border_min_x = blist[a][0]
    br.border_max_x = blist[a][1]
    br.border_min_y = blist[a][2]
    br.border_max_y = blist[a][3]

    bpy.ops.render.render()
    bdi[rr].save_render(dir+tname+"_"+cell+"."+itype)
    a += 1


    def compose():
    a = 0
    render = bdi.new(dir+fname+"."+itype, resx, resy)

    for cell in tlist:
    tile = bdi.load(dir+tname+"_"+cell+"."+itype)
    w, h = tile.size
    xadd = blist[a][0]
    yadd = blist[a][2]
    a += 1

    plist = list(tile.pixels)
    px = len(plist)
    for i in range(px):
    render.pixels[i] = plist[i]

    render.save_render(dir+fname+"."+itype)

    renderscene()
    compose()
    [/code]

    ReplyDelete
  2. Hopefully this answer won't be disappointing. Start with the reason you need this feature in the first place and search BlenderStackExchange for ways to get around the 'pause render' situation. I've seen that come up a few times and with satisfying answers.

    As you can imagine, I wrote this post in 2011 and the details are vague. I do remember writing a stitcher for Python 2.7 and 3.x and also a GIMP plugin for stitching.

    https://github.com/zeffii/rawr/tree/master/monster_render , i think the files explain what to do.

    If this has been no help, best advice is to ask on BlenderStackExchange, post link to your code se a Gist or PasteBin link. many more eyes will see your question.

    All the best!

    ReplyDelete

Please use Blender.StackExchange.com for python scripting questions unrelated to this post.