Render and save to PNG all render targets

Forum for OctaneRender Lua scripting examples, discussion and support.
Post Reply
User avatar
smicha
Licensed Customer
Posts: 3151
Joined: Wed Sep 21, 2011 4:13 pm
Location: Warsaw, Poland

LUA coders,

I need your help. I have about 10 render targets in my scene. Each scene takes about 1h to render. I would love to leave my computer for one night and have all render targets done and saved. Could you please write such LUA script?

smicha
3090, Titan, Quadro, Xeon Scalable Supermicro, 768GB RAM; Sketchup Pro, Classical Architecture.
Custom alloy powder coated laser cut cases, Autodesk metal-sheet 3D modelling.
build-log http://render.otoy.com/forum/viewtopic.php?f=9&t=42540
rosol
Licensed Customer
Posts: 4
Joined: Wed Mar 09, 2011 8:17 am

Hi
I use this script ( there is 6 rendertargets but you can make more). You should modify project path and path for saved images of course.
I hope I helped

pozdrawiam Piotr
Attachments
batch2.lua
(2.32 KiB) Downloaded 671 times
User avatar
smicha
Licensed Customer
Posts: 3151
Joined: Wed Sep 21, 2011 4:13 pm
Location: Warsaw, Poland

Piotrek,

Thank you!

(Wielkie dzięki. Przetestuję i dam znać jak to działa.)

s
3090, Titan, Quadro, Xeon Scalable Supermicro, 768GB RAM; Sketchup Pro, Classical Architecture.
Custom alloy powder coated laser cut cases, Autodesk metal-sheet 3D modelling.
build-log http://render.otoy.com/forum/viewtopic.php?f=9&t=42540
User avatar
stratified
OctaneRender Team
Posts: 945
Joined: Wed Aug 15, 2012 6:32 am
Location: Auckland, New Zealand

Hi everybody,

I modified Piotrek's excellent script to work with multiple render targets. It will ask the user for an output directory and render all the render targets in the project to png images (names result_01.png, result_02.png, ...)

Code: Select all

-- Renders all the available render targets of the loaded project.
-- Ask the user for an output directory and saves all the images into
-- that directory (result_01.png, result_02.png, ...)
--
-- @author  Thomas
-- @version 0.1


-- settings used for batch rendering
local settings =
{
    ["projectPath"]     = octane.project.getCurrentProject(),
    ["renderTargets"]   = octane.project.getSceneGraph():findNodes(octane.NT_RENDERTARGET),
    ["maxSamples"]      = 10,
    ["outputDirectory"] = nil
}

-- no render targets availabe -> error out
if #settings.renderTargets == 0 then
    error("no render targets to render in project:", projectPath)
end

-- ask the user for an output directory for the results
local ret = octane.gui.showDialog
{
    type            = octane.gui.dialogType.FILE_DIALOG,
    path            = octane.file.getParentDirectory(settings.projectPath),
    browseDirectory = true,
    save            = false,
    title           = "Select output directory for the render results", 
}
if not ret.result or ret.result == "" then
    error("no output directory selected")
end
settings.outputDirectory = ret.result

-- loop over all the render targets and render them
for ix, renderTarget in ipairs(settings.renderTargets) do
    print(string.format("render project '%s', render target '%s' with %d s/px",
                        settings.projectPath, renderTarget.name, settings.maxSamples))
    -- render the image
    octane.render.start
    { 
        renderTargetNode = renderTarget,
        maxSamples       = settings.maxSamples,
    }
    -- create an output path for the image
    local outImage = string.format("%s/result_%02d.png", settings.outputDirectory, ix)
    -- save out the image
    octane.render.saveImage(outImage, octane.render.imageType.PNG8) 
    print("saved out render result:", outImage)
end
If somebody's keen, it would be cool to have a batch render script with a gui to configure max samples, choose and output directory and show the intermediate progress. This is something every Octane customer could benefit from.

cheers,
Thomas
Tugpsx
Licensed Customer
Posts: 1150
Joined: Thu Feb 04, 2010 8:04 pm
Location: Chicago, IL
Contact:

Sweet. Thanks
Win 11 64GB | NVIDIA RTX3060 12GB
User avatar
smicha
Licensed Customer
Posts: 3151
Joined: Wed Sep 21, 2011 4:13 pm
Location: Warsaw, Poland

Piotrek, Thomas,

Many many thanks!!! This code works like a charm. I hope that we see in the nearest future GUI version of it. Now I can render many rendertargets at once during the night.
3090, Titan, Quadro, Xeon Scalable Supermicro, 768GB RAM; Sketchup Pro, Classical Architecture.
Custom alloy powder coated laser cut cases, Autodesk metal-sheet 3D modelling.
build-log http://render.otoy.com/forum/viewtopic.php?f=9&t=42540
User avatar
MB
Licensed Customer
Posts: 168
Joined: Tue Jan 15, 2013 3:41 am
Location: Washington, D.C.
Contact:

Here it is with a UI
Attachments
Batch Output RenderTargets.zip
(2.74 KiB) Downloaded 637 times
Windows 11, 2x Intel I9, 64GB Ram, 2x GTX 1080 TI, 1 x RTX 380 TI, Oculus Quest 2
User avatar
smicha
Licensed Customer
Posts: 3151
Joined: Wed Sep 21, 2011 4:13 pm
Location: Warsaw, Poland

Phenomenal work, MB!

My final request to OTOY team - please include this script as a standard script next to daylight animation, turntable,....
3090, Titan, Quadro, Xeon Scalable Supermicro, 768GB RAM; Sketchup Pro, Classical Architecture.
Custom alloy powder coated laser cut cases, Autodesk metal-sheet 3D modelling.
build-log http://render.otoy.com/forum/viewtopic.php?f=9&t=42540
User avatar
stratified
OctaneRender Team
Posts: 945
Joined: Wed Aug 15, 2012 6:32 am
Location: Auckland, New Zealand

In the future we'll distribute scripts via the LiveDB as well. We're all working very hard on 2.0 so I don't know if it's going to make it in 2.0 itself.

cheers,
Thomas
kavorka
Licensed Customer
Posts: 1351
Joined: Sat Feb 04, 2012 6:40 am

Testing it out now!

We got ahead of ourselves and got over 80 separate images ready to render, but manually saving and loading each one takes time (and can't happen while you sleep).

So, I may be putting this script to the test this weekend. It'll be nice getting all those images out and not wasting time swapping them out.
Intel quad core i5 @ 4.0 ghz | 8 gigs of Ram | Geforce GTX 470 - 1.25 gigs of Ram
Post Reply

Return to “Lua Scripting”