Light tracer

hi,

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.

thanks in advance.

SceneRadiosity.Radiosity = Light_Tracer()

1 Like

thank you very much

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).

:slight_smile:

that is my next step, is to figure out how to use the bake element to render to texture the ao.

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


Let me know if you have any more questions. :):

[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.

hey guys,

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.

thanks in advance

I think what you’re looking for is,

<theObject>.INodeBakeProperties.bakeChannel = [i]n[/i]

so something like,

myAwesomeObject.INodeBakeProperties.bakeChannel = 2

or whatever channel you’d need it for.

For more information, look in “Intereface: INodeBakeProperties” in the Maxscript reference, or of course, you can just ask here. :):

ok. so it turns out it was user error. my mistake i already had that line of code.

my problem now is this line of code : aoMap= Ambient_Occlusion()

it doesn’t work. I also tried AmbientOcclusionBakeElement() but it still doesn’t render ao.

[QUOTE=khristopher;7894]ok. so it turns out it was user error. my mistake i already had that line of code.

my problem now is this line of code : aoMap= Ambient_Occlusion()

it doesn’t work. I also tried AmbientOcclusionBakeElement() but it still doesn’t render ao.[/QUOTE]

This is how it works.


aoExample = Ambient_Occlusion()
aoExample.outputSzX = 256
aoExample.outputSzY = 256
aoExample.samples = 128

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,

“show aoExample” and you’ll get something like,

  .enabled : boolean
  .filterOn (FilteringOn) : boolean
  .outputSzX (output_width) : integer
  .outputSzY (output_height) : integer
  .autoSzOn (Auto_Size_On) : boolean
  .fileName : filename
  .filenameUnique (Filename_Unique) : boolean
  .fileType : filename
  .elementName : string
  .bitmap : bitmap
  .backgroundColor (Background_Color) : fRGBA color
  .targetMapSlotName : string
  .samples : integer
  .bright : fRGBA color
  .dark : fRGBA color
  .spread : float
  .maxDistance (Max_Dist) : float
  .falloff : float

Hope that helps. :):

ok this is what i have originally. am i missing something?

*when i try to render to texture manually the AmbientOcclusion element is not on the list. i’m thinking that is the reason why my code doesnt work

aoMap= Ambient_Occlusion()
		aoMap.outputSzX = 1024 
		aoMap.outputSzY = 1024
		aoMap.elementName = "Ambient_Occlusion (MR)"
		aoMap.fileType =$.name+".tga"
		aoMap.fileName = $.name+".tga"--"c:/ao.tga"
		aoMap.filterOn =true
		--aoMap.shadowsOn = true
		aoMap.enabled = true
		
		
		$.INodeBakeProperties.removeAllBakeELements()
		$.INodeBakeProperties.addBakeELement aoMap
		$.INodeBakeProperties.bakeChannel = 1
		$.INodeBakeProperties.nDilations =1
render rendertype:#bakeSelected vfb:off progressBar:true outputSize:[1024,1024]

Just need to enable baking before rendering.

$.INodeBakeProperties.bakeEnabled = true

ok i got it working. it turns out i have to enable mental ray render in the script to for the AmbientOcclusion() to work.

my current problem is that i’ve added the feature for the user to assign the resolution of the texture (256x256, 512x512, 1024x1024)

i have a dropdownlist, however i cant get it to work properly when the user pick a resolution.

Hello :):

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. :):

hey it worked thanks. i just used the .selection of the dropdownlist and it worked. thanks guys. thanks j83

Glad to hear. :):

Hey guys, sorry to necro this thread!

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.

Cheers,

cw