I was wondering if there is a way to turn on light tracer through script to render ambient occlusion. I’ve searched through the internet and still couldn’t find a way. I’ve tried every possible combination I can think of to turn it on but nothing works.
You can also,
(1) Use Mental Ray and use the Material Override and render the scene with ambient occlusion, and you’ll get better results than light tracer most likely.
(2) If you’re eventually going to render this to a texture, you can use the ambient occlusion bake element and skip the light-tracer (or Mental Ray override) step all together, as the ambient occlusion bake element does that for you (uses Mental Ray).
To point you in the right direction, you can look up in the Maxscript reference,
Ambient_Occlusion : BakeElement
You can also refer to this example in the Maxscript reference,
“Render To Texture Using MAXScript”
fn BakeDiffuseAndLighting obj size =
(
--Clear all render elements
obj.iNodeBakeProperties.removeAllBakeElements()
--Preparing the Bake Elements:
be1 = diffusemap() --instance of the bake element class
be1.outputSzX = be1.outputSzY = size --set the size of the baked map
--specify the full file path, name and type:
be1.fileType = (getDir #image+"\\"+obj.name+"_diffuse.tga")
be1.fileName = filenameFromPath be1.fileType
be1.filterOn = true --enable filtering
be1.shadowsOn = false --disable shadows
be1.lightingOn = false --disable lighting
be1.enabled = true --enable baking
be2 = LightingMap() -- instance of the bake element class
be2.outputSzX = be2.outputSzY = size --set the size of the baked map
--specify the full file path, name and type:
be2.fileType = (getDir #image+"\\"+obj.name+"_lighting.tga")
be2.fileName = filenameFromPath be2.fileType
be2.filterOn = true --enable filtering
be2.shadowsOn =true --enable shadows
be2.enabled = true --enable baking
--Preparing the object for baking:
obj.INodeBakeProperties.addBakeElement be1 --add first element
obj.INodeBakeProperties.addBakeElement be2 --add second element
obj.INodeBakeProperties.bakeEnabled = true --enabling baking
obj.INodeBakeProperties.bakeChannel = 1 --channel to bake
obj.INodeBakeProperties.nDilations = 1 --expand the texture a bit
select obj --we are baking the selection, so we select the object
--Call the renderer to bake both elements:
render rendertype:#bakeSelected vfb:off progressBar:true outputSize:[size,size]
theComp = CompositeTextureMap() --create a composite map
theComp.add() --add a second layer
theComp.blendMode = #(0,5) --set second layer to Multiply
--Create two maps, one with the diffuse, one with the lighting map
theMap1 = bitmaptexture filename:be1.fileType
theMap2 = bitmaptexture filename:be2.fileType
theComp.mapList = #(theMap1, theMap2) --composite the two maps
theComp.opacity = #(100,70) --set the lighting map to 70% opacity
--Create a standard self-illum material using the Composite map
bakedMat = standard diffusemap:theComp selfIllumAmount:100
--Assign a Shell Material to the object,
--keep the old material as original material,
--set the new bakedMat as the baked material:
obj.material = Shell_Material originalMaterial:obj.material \
bakedMaterial:bakedMat viewportMtlIndex:1 renderMtlIndex:1
--Show the textures of the baked material in the viewport
showTextureMap obj.material obj.material.bakedMaterial true
)--end fn
resetMaxFile #noprompt --reset the scene to start from scratch
--Create a shadow casting white Omni light
theLight = omniLight pos:[0,-60,100] rgb:white
theLight.baseobject.castshadows = true
--Create a mapped sphere object above the ground plane
theObject = Sphere segs:32 mapcoords:true pos:[0,0,25]
--Create a Cellular map and assign via Standard material to object
theMap = cellular cellColor:blue divColor1:red divColor2:yellow size:15
theObject.material = standard diffusemap:theMap
--Call the Bake function with the object and the desired size
BakeDiffuseAndLighting theObject 256
--Create a mapped plane object on the ground plane
theObject = Plane width:200 length:200 mapcoords:true
--Create a checker map and set the tiling to 4x4, then assign to object
theMap = checker Color1:green Color2:orange
theMap.coordinates.uTiling = theMap.coordinates.vTiling = 4
theObject.material = standard diffusemap:theMap
--Call the Bake function with the object and the desired size
BakeDiffuseAndLighting theObject 256
--Delete the light from the scene and deselect everything
delete theLight
max select none
[QUOTE=j83;7742]You can also,
(1) Use Mental Ray and use the Material Override and render the scene with ambient occlusion, and you’ll get better results than light tracer most likely.
[/QUOTE]
I’ve played with this at my last job. We had both methods available to us as one-click solutions, and ultimately our artists preferred light-tracer to Mental Ray. This could very well be related to what settings we were using for MR light bakes, but I cant really speak to that, as I wasn’t the one who set up the MR baker.
Yes, you have to be mindful of the specific settings for the falloff settings, samples, spread, etc., for Mental Ray, but I suppose a lot of people would prefer using Scanline instead of Mental Ray just for familiarity.
oh the maxscript reference. every time i have a question i use it. and i did got the idea of expanding the AO script to render to texture from that bake element page. i will be playing around that script over the weekend and i’ll most likely have some questions then.
thanks guys. most of the ideas im getting are from my artist friends.
so i got the render to texture the ao working now. but my problem now is telling the script to use the existing map channel so it will use the user’s own uv.
can anyone help me? pls.
i’ve tried setMapChannel =1 and similar syntax but no luck.
Basically, aoExample is now an instance of the Ambient_Occlusion() bake element class, then you can access each member of that class as is shown, or type,
Here’s an example I quickly wrote to show examples of how you can use the drop down list. You can handle that a certain value is assigned when the state is changed, or, you can do something like this,
(
rollout roExample "Drop Down List Example" category:0
(
dropdownlist ddlExample "Texture Resolution" items:#("256", "512", "1024") tooltip: "Example drop down list" selection: 2 width: 66 align:#center\
button btnPrintSelection "Print Drop Down List Selection"
button btnPrintSelected "Print Drop Down List Selection"
on btnPrintSelection pressed do
(
print ddlExample.selection
)
on btnPrintSelected pressed do
(
print ddlExample.selected
print (theLightMapRes = (ddlExample.selected as integer))
)
)
createDialog roExample width: 185 --height: 200
)
Basically, we can use the .selection to get the number of the option selected (1, 2, 3, etc.) or we can use .selected and get the actual value from that selection, which in this case is a string, but we want it as an integer, so we just cast it via,
(ddlExample.selected as integer)
So that is one way. You can use a switch/case of statement, if statement, just get the value, etc., lots of options here. :):
I’m having a real fun time with texture baking via maxscript at the moment. I’ve been trawling the web for any tidbits to help me and so far it has been useful, but nothing yet fixes my main outstanding issue.
My problem is this - No matter how I setup my supersampling I don’t seem to get it in my baked maps. Baking manually with the max UI using the node bake data gives the expected result - has anyone experienced this or know a fix I can use? I’m so close now!
I’ve read through the max rtt script, other baking scripts whch are out there, and none seem to give me the kick I need to crack it.