View Full Version : Render To Texture with Maxscrip

09 September 2008, 07:56 AM
Hey all, im trying to make an interface that does a render to texture of the diffuse channel, specifying the size, output dir, output file type etc. I have looked in the help under RTT_Methods but am now more confused than when I started. Can anyone give me a bit of a starting point to the RTT interface and how to do it. Cheers!!!

09 September 2008, 05:55 PM
It took me a while to figure this out also. For some time I just thought it couldn't be done, but after staring at the help docs long enough, and a bit of trial and error, I got it working.

The two interfaces you want to look at are INodeBakeProperties and INodeBakeProjProperties. Plus, take a look at the Macro_BakeTextures.mcr file (if you're feeling brave).

Here's a sample script to render the diffuse channel from one object to another:

-- add project modifier and projection objects
fn addProjMod lowResObj highResObjs cageOffset =
modMode = getCommandPanelTaskMode()
setCommandPanelTaskMode #modify
projMod = projection()
addModifier lowResObj projMod
for obj in highResObjs do
projMod.addObjectNode obj
projMod.pushCage cageOffset
projMod.displayCage = true = "ProjMod"
setCommandPanelTaskMode modMode

-- set up the objects
theObj = sphere radius:50 segs:32 mapcoords:on
theProjObj = sphere radius:50.5 segs:32 mapcoords:on
theProjObj.material = standard diffuseMap:(Perlin_Marble ())

-- define variables
renderSize = 512
fileName = + "_Diffuse.tif"
filePath = "c:\\" + diff.filename

-- the bake object needs to be selected
select theObj

-- set up the bake interfaces
bakeProps = theObj.INodeBakeProperties
bakeProjProps = theObj.INodeBakeProjProperties

-- add diffuse element
diff = DiffuseMap()
bakeProps.addBakeElement diff
-- file name
diff.filename = fileName
diff.filetype = filePath
-- map size
diff.outputSzX = renderSize
diff.outputSzY = renderSize
diff.enabled = true

-- projection
bakeProjProps.enabled = true
bakeProjProps.projectionMod = (addProjMod theObj #(theProjObj) 1)

-- open and close RTT "Render" "BakeDialog"
destroyDialog gTextureBakeDialog

-- do the render
curBM = bitmap renderSize renderSize
render rendertype:#bakeSelected frame:0 to:curBM vfb:true cancelled:&wasCanceled
close curBM

-- display the diffuse map
display (openBitMap filePath)

10 October 2008, 01:15 AM
Cheers for that. It works great, only it always saves the element as 640x480, not the specified 1024x1024. It renders as 1024x1024 but only saves the top left 640x480 segement of it.
Im using vray and the VRay_DiffuseFilterMap() Element and im setting the element size, and the curBM (bitmap) size and even the render() size all with the same property (1024)

11 November 2008, 12:26 AM
It seems that if i choose .exr as an output format it will only save a 640x480 segment of the render, while using .tiff will save the whole 1024x1024 image. Weird

11 November 2008, 07:10 PM
Have you seen this thread (

Look towards the end where he talks about the difference between rendering directly to the bitmap versus copying the result to a new bitmap and then saving that one. That might help with this issue too.

CGTalk Moderation
11 November 2008, 07:10 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.