Vray lightcache prerender?

Discussion and Support of Deadline, the Render Management System
User avatar
Posts: 5883
Joined: Tue Nov 15, 2005 10:26 am
Location: Vancouver, Canada

Re: Vray lightcache prerender?

Postby Bobo » Wed May 17, 2017 11:02 am

The content of SMTDSettings.MultiRegionData is your responsibility. If you are appending to it, it will grow. You can always set it to

Code: Select all

::SMTD_MultiRegionSettingsPersistentGlobal = SMTDSettings.MultiRegionData = #()

to clear. The ::SMTD_MultiRegionSettingsPersistentGlobal is stored with the MAX file and can be used to restore the SMTDSettings.MultiRegionData after a MAX scene has been loaded (at least that's how SMTD is using it).

squeakybadger wrote:I've just encountered a small bug when using the create from 3dsmax region script to add it to jigsaw - it doesn't seem to delete the new region data and hangs around even after deadline is closed.

So sending a single region after 2 other regions on different jobs have been sent, then next job will have 3 regions on the render.

I'm guessing the SMTDSettings.MultiregionData that adds it to Jigsaw needs deleting at the end of the submission?
Borislav "Bobo" Petrov
Product Specialist
Thinkbox Software Inc.

Posts: 74
Joined: Tue Jul 28, 2009 9:50 am

Re: Vray lightcache prerender?

Postby squeakybadger » Tue Jun 13, 2017 10:19 am

Hi Bobo,

I've been trying to get clever with this submission script, but it's not working as intended when using the Vray Frame Buffer. Any pointers are appreciated!

What should happen:

Precalc job is sent first with DR slaves.

--This calculates the lightcache file and saves out that vrlmap and temp preview lightcache image in a new folder that is created (_temp\preview.jpg and _temp\jobname.vrlmap) The preview.jpg is specified in the 3dsmax output.

Main tile job is sent

-- This loads the vrlmap from the temp folder. Tiles render and are saved into the output dir specified in the Vray Frame Buffer-Split Channels Option

Assembly Job runs

--And everything gets put back together again.

I have it able to make the new temp folder, save the new lightcache into that folder, create the preview.jpg image but then it all falls down and doesn't render anything useful, just the RGB and Alpha when enabled on the Separate render channels option in the Vray Frame Buffer.

The tile jobs output on Deadline just lists the render elements with a .jpg extension, not exr like the Vray Output.

The end goal of this is to setup some event plugins to email that preview.jpg to the user to check if the lighting looks ok, and to make it easy to delete all the lightcaches/temp files in the _temp folder in one go.

This is my submission script. I've commented everything I have added with a (J) so you can see the method to the madness :)

Code: Select all

(--start local scope
--If SMTD has not been opened yet, or has been closed since the start of 3ds Max, launch its UI:
if SMTD_MainRollout == undefined or not SMTD_MainRollout.open do macros.run "Deadline" "SubmitMaxToDeadline"

local theRenderer = renderers.current                     --get the current renderer
if isKindOf theRenderer VRay do                           --if it is VRay, we are good to go
   --Render final image is disabled, light cache is set to render in the output dir
   local oldRenderDialogState = renderSceneDialog.isopen()      --see if the render dialog was open
   renderSceneDialog.close()                                             --close it before submission
   theRenderer.options_dontRenderImage = true               --disable the rendering
   theRenderer.system_distributedRender =true            --turn on dr (J)

   --make sure vfb and split files is on otherwise it will error (J)
   tempFolder = getFileNamePath theRenderer.output_splitfilename + "_temp" -- specify temp folder (J)
   makeDir tempFolder -- make temp folder (J)
   rendoutputfilename = tempFolder + "\\" + "preview.jpg"  -- set temp 3dsmax output file as a lightcache preview.jpg (J)
   rendSaveFile = false   --disable 3dsmax output file saving (J)
   local lcpath = tempFolder + "\\" + getFileNameFile theRenderer.output_splitfilename + ".vrlmap"   --build the LC name in the new temp folder (J)

   theRenderer.lightcache_autoSave = true                  --enable LC auto-save
   theRenderer.lightcache_autoSaveFileName = lcpath         --and set the file name to the cache path
   theRenderer.lightcache_saveFileName = lcpath

   SMTDSettings.ForceWorkstationMode = false
   SMTDSettings.MergeSceneXRefsOnSubmission = false
   SMTDSettings.MergeXRefsOnSubmission = false
   SMTDSettings.Priority = 99
   SMTDSettings.SingleTileJobDraftErrorOnMissing = true
   SMTDSettings.SingleTileJobCleanup = true
   SMTDSettings.SubmitAsSuspended = true
   SMTDSettings.RemovePadding = true  --removes 0000  (J)
   re = maxOps.GetCurRenderElementMgr() -- turn off render elements to stop the initial dump of 0000 files (J)
   re.SetElementsActive false
   --Handle Region Rendering - LC Job should always be full frame
   local oldRegionMode = SMTDSettings.RegionRenderingMode      --store whatever Region mode SMTD was in
   SMTDSettings.RegionRenderingMode = #none               --and force full frame submission
   SMTDSettings.DBR = true               --turn on VrayDR (J)
   SMTDSettings.DBRUse3dsCmd = true   --turn on 3dscmd in deadline (J)
   SMTDSettings.DBRServers = 5            --set 5 dr servers (J)
   --Job sends to deadline
   ::SMTDIsCurrentlySubmitting = true                     --raise the flag showing we started submission and it is not canceled
   SMTDSettings.PreviousJobsArray = #()                   --clear the dependencies list
   SMTDSettings.SubmitAsDependent = false                   --disable dependencies for first job submission

   SMTD_MainRollout.getNameFromMaxScene()                  --update the job name in the UI
   local oldJobName = SMTDSettings.JobName            --store the current job name

   SMTDSettings.JobName = oldJobName +" (Pre)"            --set the LC job's name
   local batchName = oldJobName + " (Render:BF/LC)"      --a batch name to combine the two jobs
   local result = SMTDFunctions.SubmitJobFromUI batchName:batchName      --submit the job to Deadline as part of the batch
   SMTDSettings.RegionRenderingMode = #singleFrameTiles --switch to tile mode
   SMTDSettings.TilesInX = 1 --number of tile columns
   SMTDSettings.TilesInY = 1 --number of tile rows
   TilesPadding = 0 --whatever padding you want to use
   SMTDSettings.SingleTileJobDependent = true --submit a dependent Draft Tile Assembly job
   if SMTDSettings.PreviousJobsArray.count > 0 do            --if a previous job exists to depend on,
      --Render final image is enabled, lc is switched to "from file" and uses the precalced light cache

   rendSaveFile = false       --make sure output file saving is off (J)
   re = maxOps.GetCurRenderElementMgr() -- turn on render elements to stop the initial dump of 0000 files
   re.SetElementsActive true

    theRenderer.options_dontRenderImage = false            --re-enable rendering
   theRenderer.system_distributedRender =false         --turn off dr (J)
    theRenderer.lightcache_autoSave = false               --disable the auto save mode

   local old_lightcache_mode = theRenderer.lightcache_mode   --store the old mode
    theRenderer.lightcache_mode = 2                     --set LC mode to From File
   theRenderer.lightcache_loadFileName = lcpath         --set the load file to the cached path from the previous submission
   SMTDSettings.DBR = false               --turn off VrayDBR (J)
   SMTDSettings.DBRUse3dsCmd = false   --turn off 3dscmd in deadline (J)
      --Job sends to deadline with the first as a dependency.
   SMTDSettings.CloseAfterSubmission = true
    SMTDSettings.SubmitAsDependent = true               --enable dependencies
    SMTDSettings.DependencyJobItems = #{1}               --set the dependency on the first entry from the list
    SMTDSettings.DependOnPreviousJobMode = #last         --set the mode to last, so only the last job is concidered
    SMTDSettings.JobName = oldJobName+" (Render)"      --set the job name
   SMTDSettings.Priority = 80
   SMTDFunctions.SubmitJobFromUI batchName:batchName      --submit to Deadline as part of the same batch

   SMTDSettings.JobName = oldJobName                  --restore the job name
   SMTDSettings.SubmitAsDependent = false               --disable dependencies
   SMTDSettings.DependencyJobItems = #{}               --and clear the dependency jobs bitarray flags
   theRenderer.lightcache_mode   = old_lightcache_mode       --restore the old cache mode#

   ::SMTDIsCurrentlySubmitting = undefined                  --lower the cancel submission flag since we are done
   if oldRenderDialogState do renderSceneDialog.open()       --reopen the render dialog if needed
 try(destroyDialog SMTD_MainRollout)catch() -- close the SMTD window
    format "%\n" result
)--end if
)--end local scope


User avatar
Posts: 5883
Joined: Tue Nov 15, 2005 10:26 am
Location: Vancouver, Canada

Re: Vray lightcache prerender?

Postby Bobo » Tue Jun 13, 2017 12:20 pm

Max tends to update its render elements' paths to match the main output path. So if you have a .jpg in rendOutputFilename, your render elements might end up saving with .jpg extensions. They might even be OpenEXRs with the wrong extension in the worst case.

For that reason, we (well, one of our customers shared the code with us) added the option to rebuild the render elements on submission to ensure they have the right internal settings matching the external settings. However, they will still end up with .jpg extensions, but their internal settings will match the file format specified by the extension, so they will be actually JPGs, not EXRs.
I wonder if the rebuild option is on or off in your case - the SMTDSettings.RebuildRenderElements defaults to true.

In short, if you are outputting rendOutputFilename to JPG, your render elements might follow... :(

If you need a preview, I would suggest saving to EXR, and then running some post script to convert it to JPG for viewing. You could even use Draft to do it. Or give your users a viewer that can see EXRs ;)

Alternatively, make sure you set the rendOutputFilename back to EXR before submitting the second job to hopefully force your Render Elements back to EXR.

Also, don't forget to update to Deadline 9.0.4 as it fixes a few VRay VFB output path issues as noted elsewhere.

Finally, check out this thread! https://forums.thinkboxsoftware.com/vie ... 11&t=15433
Soon you will be able to park your script inside the SMTD UI :mrgreen:
Borislav "Bobo" Petrov
Product Specialist
Thinkbox Software Inc.

Return to “Thinkbox Software - Deadline”

Who is online

Users browsing this forum: No registered users and 2 guests