macroScript TIK_QuickPasses
category: "Tik Works"
tooltip: "Quick Passes"


(
local LastSubRollout = 1
local current_save_path
local save_path_QP
local scstate
local	Matte_ifConMat 
local	Matte_ifDisp
local matte_wh
local matte_bl
local Matte_ifConOt
local Matte_refmat
local AO_sample
local AO_spread
local AO_m_dist
local AO_falloff
local AO_ifwired
local AO_ifBump
local AO_ifDisp
local AO_selectedonly
local REF_envmap = true
local REF_blurchk = false
local REF_spread = 10.0
local REF_sample = 10
local REF_ifBump = false
local REF_ifDisp = false
local SHA_opaque_Alpha
local SHA_Apply_Atmosphere
local SHA_ATMOSTATE
local temp_material
local overrideRENDERER=undefined
local vrayCam
local vrayCam_exp
local vrayCam_vig
local vrayCam_WB
local Use_env
local EnvColor
local TintColor
local TintLevel
local Ambient
local exposureControl
local current_selection=#()
local all_array=#()
local all_mat_array=#()
local all_matobj_array=#()
local all_no_mat_array=#()
local all_visobj_array=#()
local all_visval_array=#()
local all_no_vis_array=#()
local lights_on_array=#()
local lights_temporaryon_array=#()
local lights_temporaryonVray_array=#()
local lights_temporaryinvisibleVray_array=#()
local lights_temporarycastshadows_array=#()
local vray_sun_array=#()
local primvis_off_array=#()
local primvis_on_array=#()
local temp_skylight=undefined
local Rscenedialog
local Rusenet
local Rsavefile
local if_netrender
local re
local REST
local kameralar = for e in cameras where classof e != targetobject collect e
local kamera_isimler=#("Current View")
    for i in kameralar do
    (
        if classof i !=  targetobject do append kamera_isimler i.name
    )
local vr=try(RendererClass.classes[(findItem RendererClass.classes vray)]())catch()
local override_ddl_array=#("Current Renderer","Default Scanline Renderer","Mental Ray Renderer")
	if vr != undefined then
	(
		append override_ddl_array "Vray Renderer"
	)
---------------------------------------------------------------------------------------------------------------
-------------------------------------PREPERATION FUNCTIONS-----------------------------------------
---------------------------------------------------------------------------------------------------------------
	
-------------------------------------GET FUNCTIONS-------------------------------------
--GET SCENE PROPS--
fn get_sceneprops=
(
exposureControl=SceneExposureControl.exposureControl
Rscenedialog=renderscenedialog.isopen()
Rusenet=rendusenet
Rsavefile=rendSaveFile
re = maxOps.GetCurRenderElementMgr()
REST=re.getelementsactive()
current_save_path=rendOutputFilename
)

--Render and SET SCENE PROPS--
fn renderAndrecall=
(
if Rscenedialog==true then (rendersceneDialog.close())
if scstate==true then
	(
		rendSaveFile=true
		rendOutputFilename=save_path_QP
	)
	else 
	(
		rendSaveFile=false
		rendTimeType=1
	)
if if_netrender == true then (rendusenet=true) else (rendusenet=false)

re.SetElementsActive false
	
max quick render	
if Rscenedialog==true then (rendersceneDialog.open())
	
re.SetElementsActive REST
	
rendusenet=Rusenet
rendSaveFile=Rsavefile
rendOutputFilename=current_save_path
)

--GET MATERIAL--

fn get_materials = 
(
-- Save current Render Properties
	renderpresets.saveAll 0 (GetDir #renderPresets + "\\cur_tmp.rps") --#{32,33,34}
	EnvColor=backgroundcolor
	use_env=useEnvironmentmap
	tintcolor=lightTintColor
	tintLevel=lightLevel
	Ambient=AmbientColor
	exposureControl=SceneExposureControl.exposureControl

-- Array Materials
	all_array = (geometry as array) + (shapes as array)
	for i in all_array do
	(
	if i.material != undefined then
	(
	append all_mat_array i.material
	append all_matobj_array i
	)
	else append all_no_mat_array i
	)
)

--GET VISIBILITY--

fn get_visibilities = 
(

-- Array Visibilities
	all_array = (geometry as array) + (shapes as array)
	for i in all_array do
	(
	if getviscontroller i != undefined then
	(
	append all_visval_array i.visibility.controller.value
	append all_visobj_array i
	)
	else append all_no_vis_array i
	)
	for i in all_array do
	(
		if i.primaryvisibility == false then
			(
			append primvis_off_array i
			)
		if i.primaryvisibility == true then
			(
			append primvis_on_array i
			)
		
	)
)

--GET LIGHTS--

fn get_lights =
(
--Exclude Lights
	
	for z in lights where classof z != TargetObject and classof z != VRaySun do
		(
		if z.on == true do
			(
			append lights_on_array z
			z.on = false
			)
		)
               
--Exclude VraySun
	for j in lights where classof j != TargetObject and classof j == VRaySun do
		(
		if j.enabled == true do
			(
			append vray_sun_array j
			j.enabled = false
			)
		)	
)

--GET CAMERAS--
fn get_cameras = 
(
	vraycam = viewport.getCamera()
	if classof vraycam == VRayPhysicalCamera then
		(
			vrayCam_exp=vraycam.exposure
			vrayCam_vig=vraycam.vignetting
			vrayCam_WB=vraycam.whiteBalance
			vraycam.exposure = false
			vraycam.vignetting = false
			vraycam.whiteBalance = white
		)
)
-------------------------------------RECALL FUNCTIONS-------------------------------------

--RECALL MATERIALS--

fn recall_materials = 
(

	-- Return Original Material
	(
	if all_matobj_array.count != 0 do
		(
		for m = 1 to all_matobj_array.count do
			(
			all_matobj_array[m].material = all_mat_array[m]
			)
		)
	-- Return No Material
	if all_no_mat_array.count != 0 do all_no_mat_array.material = undefined
	)
		--Return Render Properties
renderpresets.load 0 (GetDir #renderPresets + "\\cur_tmp.rps") #{1,4,32,33,34}
	backgroundcolor=EnvColor
	useEnvironmentmap=use_env
	lightTintColor=tintcolor
	lightLevel=tintLevel
	AmbientColor=Ambient
	SceneExposureControl.exposureControl=exposureControl

)

--RECALL VISIBILITY--

fn recall_visibilities = 
(
	objects.primaryVisibility = on
	-- Return Original Visibility value
	(
	if all_visobj_array.count != 0 then
		(
		for m = 1 to all_visobj_array.count do
			(
			all_visobj_array[m].visibility.controller.value = all_visval_array[m]
			
			for h in primvis_off_array do (h.primaryVisibility=off)
			)
		)
	-- Return No Visibility
	if all_no_vis_array.count != 0 then
	(
		for g in all_no_vis_array do
		(
		if g.visibility != true then
		(
		deletekeys g.visibility.controller
		g.visibility = on
		for h in primvis_off_array do (h.primaryVisibility=off)
		for j in primvis_on_array do (j.primaryVisibility=on)
		)
		)
	)
	)
)

--RECALL LIGHTS--

fn recall_lights = 
(
	try (delete temp_skylight) catch()
	-- Return Lights
	if lights_temporaryon_array.count != 0 do (for i in lights_temporaryon_array do i.on=false)
	if lights_temporarycastshadows_array.count != 0 do (for i in lights_temporarycastshadows_array do i.baseobject.castshadows=off)
	if lights_on_array.count != 0 do lights_on_array.on = true
	if vray_sun_array.count != 0 do vray_sun_array.enabled = true
	if lights_temporaryonVray_array.count != 0 then
	(
		for t in lights_temporaryonVray_array do
		(
			case of
			(
				(classof t==VraySun):t.enabled=false
				(classof t==VrayLight):t.on=false
				)
		)
	)
	if lights_temporaryinvisibleVray_array.count != 0 do lights_temporaryinvisibleVray_array.invisible=off
)

--RECALL  CAMERAS--
fn recall_cameras = 
(
	if classof vraycam == VRayPhysicalCamera then
	(
		vraycam.exposure = vrayCam_exp
		vraycam.vignetting = vrayCam_vig
		vraycam.whiteBalance = vrayCam_WB
	)
)
-------------------------------------SCANLINE-------------------------------------

fn scanline_PREPS BGcolor useENV=
(
scanlineRR = Default_Scanline_Renderer ()
renderers.current = scanlineRR
SceneExposureControl.exposureControl=()
ambientColor = color 0 0 0
useEnvironmentMap = useENV
backgroundColor = BGcolor
)

-------------------------------------MENTALRAY-------------------------------------

fn mentalray_PREPS BGcolor useENV=
(
	mentalRR = mental_ray_renderer ()
	if classof renderers.current==mental_ray_renderer then
			(
			mentalRR.filter=renderers.current.filter
			mentalRR.MinimumSamples=renderers.current.MinimumSamples
			mentalRR.MaximumSamples=renderers.current.MaximumSamples
			mentalRR.BoxFilterWidth=renderers.current.BoxFilterWidth
			mentalRR.BoxFilterHeight=renderers.current.BoxFilterHeight
			mentalRR.GaussFilterWidth=renderers.current.GaussFilterWidth
			mentalRR.GaussFilterHeight=renderers.current.GaussFilterHeight
			mentalRR.TriangleFilterWidth=renderers.current.TriangleFilterWidth
			mentalRR.TriangleFilterHeight=renderers.current.TriangleFilterHeight
			mentalRR.MitchellFilterWidth=renderers.current.MitchellFilterWidth
			mentalRR.MitchellFilterHeight=renderers.current.MitchellFilterHeight
			mentalRR.LanczosFilterWidth=renderers.current.LanczosFilterWidth
			mentalRR.LanczosFilterHeight=renderers.current.LanczosFilterHeight
			mentalRR.LanczosFilterWidth=renderers.current.LanczosFilterWidth
			mentalRR.scanlineMethod =renderers.current.scanlineMethod
			mentalRR.motionblurEnable=renderers.current.motionblurenable
			mentalRR.MotionBlurAllObjects=renderers.current.MotionBlurAllObjects
			mentalRR.Shutter=renderers.current.Shutter
			mentalRR.MotionBlurOffset=renderers.current.MotionBlurOffset
			mentalRR.Segments=renderers.current.Segments
			mentalRR.TimeSamples=renderers.current.TimeSamples
			mentalRR.RapidMotionResample=renderers.current.RapidMotionResample
			mentalRR.DepthOfFieldEnable=renderers.current.DepthOfFieldEnable
			mentalRR.DepthOfFieldMode=renderers.current.DepthOfFieldMode
			mentalRR.FocusPlane=renderers.current.FocusPlane
			mentalRR.fStop=renderers.current.fStop
			mentalRR.NearFocus=renderers.current.NearFocus
			mentalRR.FarFocus=renderers.current.FarFocus
			)
	mentalRR.FinalGatherEnable2 = false
	mentalRR.CausticsEnable = false
	mentalRR.GlobalIllumEnable = false
	mentalRR.Enable_Material_Override = false
	renderers.current = mentalRR
	SceneExposureControl.exposureControl=()
	ambientColor = color 0 0 0
	useEnvironmentMap = useENV
	backgroundColor = BGcolor
)

-------------------------------------VRAY-------------------------------------

fn Vray_PREPS BGcolor useENV=
(
VrayRR = vr
if classof renderers.current==classof vr then
	(
		VRayRR.camera_type=renderers.current.camera_type
		VRayRR.camera_overrideFOV=renderers.current.camera_overrideFOV
		VRayRR.camera_fov=renderers.current.camera_fov
		VRayRR.camera_cyl_height=renderers.current.camera_cyl_height
		VrayRR.camera_fish_autoDistance=renderers.current.camera_fish_autoDistance
		VrayRR.camera_fish_distance=renderers.current.camera_fish_distance
		VrayRR.camera_fish_curve=renderers.current.camera_fish_curve
		VrayRR.dof_on=renderers.current.dof_on
		VrayRR.dof_distance=renderers.current.dof_distance
		VrayRR.dof_getFromCamera=renderers.current.dof_getFromCamera
		VrayRR.dof_shutter=renderers.current.dof_shutter
		VrayRR.dof_subdivs=renderers.current.dof_subdivs
		VrayRR.dof_bias=renderers.current.dof_bias
		VrayRR.dof_sides_on=renderers.current.dof_sides_on
		VrayRR.dof_sides_num=renderers.current.dof_sides_num
		VrayRR.dof_sides_rotation=renderers.current.dof_sides_rotation
		VrayRR.dof_anisotropy=renderers.current.dof_anisotropy
		VrayRR.moblur_on=renderers.current.moblur_on
		VrayRR.moblur_duration=renderers.current.moblur_duration
		VrayRR.moblur_intervalCenter=renderers.current.moblur_intervalCenter
		VrayRR.moblur_geomSamples=renderers.current.moblur_geomSamples
		VrayRR.moblur_prepassSamples=renderers.current.moblur_prepassSamples
		VrayRR.moblur_dmc_minSamples=renderers.current.moblur_dmc_minSamples
		VrayRR.moblur_geometryParticles=renderers.current.moblur_geometryParticles
		VrayRR.moblur_bias=renderers.current.moblur_bias		
	)
renderers.current = VrayRR
SceneExposureControl.exposureControl=()
ambientColor = color 0 0 0
useEnvironmentMap = useENV
backgroundColor = BGcolor
)

---------------------------------------------------------------------------------------------------------------
-------------------------------------MATERIAL REPLACEMENT STRUCTURE----------------------------
---------------------------------------------------------------------------------------------------------------

fn BaseMaterialReplace n func =
(
if func == 1 then

	(
		(--base Matte	
		matte_wh = standardMaterial diffuse: (color 255 255 255) selfIllumAmount: 100 twosided: true
		--Standard Material	
		if classof n ==undefinedclass then
		(
			temp_material=matte_wh
		)
		if classof n == standardmaterial then
			(
			if Matte_ifConMat==true then
				(
					matte_wh.opacity=n.opacity
				if n.OpacityMapEnable == on then
					(
					matte_wh.OpacityMap=n.opacityMap
					matte_wh.OpacityMapAmount=n.OpacityMapAmount
					)
				)
			if n.DisplacementMapEnable == on and Matte_ifDisp==true then
				(
				matte_wh.DisplacementMap=n.DisplacementMap
				matte_wh.displacementMapAmount = n.displacementMapAmount
				)
				temp_material=matte_wh
			)

		--VRay Material		
		if classof n == VRayMtl then
			(
			if Matte_ifConMat==true then
				(
					matte_wh.opacity=((n.refraction.v/255)*100)
			if texmap_opacity_on == on then
					(		
					matte_wh.OpacityMap=n.texmap_opacity
					matte_wh.OpacityMapAmount=((n.refraction.v/255)*100)
					)
				)
			if n.texmap_displacement_on == true and Matte_Disp==true then
				(
				matte_wh.Displacementmap=n.texmap_displacement
				matte_wh.displacementMapAmount = n.texmap_displacement_multiplier
				)
			)

		--Arch Design Material	
		if classof n ==Arch___Design__mi  then
			(
			if Matte_ifConMat==true then
			(
				matte_wh.opacity=(1-n.refr_weight)*100
			if cutout_map_on == on then
				(		
				matte_wh.OpacityMap=n.cutout_map
				)
			)
			if n.displacement_map_on == true and Matte_ifDisp==true then
				(
				matte_wh.Displacementmap=n.displacement_map
				matte_wh.displacementMapAmount =n.displacement_map_amt*10
				)
				temp_material=matte_wh
			)

		)
	)--end of BaseMAtte
	
	
--AO_RENDER_PREFUNCTION 1	
	
if func == 2 then
	
	(	
		if classof renderers.current == mental_ray_renderer and overrideRENDERER !=2 then
		(
		mAO = mental_ray()
		mAO.surface = Ambient_Reflective_Occlusion__3dsmax samples: AO_sample spread: AO_spread max_distance: AO_m_dist falloff: AO_falloff
		)
		else
		(mAO = standardmaterial diffuse:white)

		--Standard Material	
		if classof n == standardmaterial then
			(
			if n.bumpMapEnable == on and AO_ifBump==true then
			(		
			if classof renderers.current == mental_ray_renderer and overrideRENDERER !=2 then
				(
					BumpVal = n.bumpMapAmount / 100
					mAO.Bump=Bump__3dsmax ()
					mAO.Bump.map=n.bumpmap
					mAO.Bump.multiplier=BumpVal
				)
				else
				(
					mAO.Bumpmap=n.bumpmap
					mAO.BumpmapAmount=n.bumpMapAmount
				)
			)
			if n.displacementMapEnable == on and AO_ifDisp==true then

			(		
			if classof renderers.current == mental_ray_renderer and overrideRENDERER !=2 then
				(
					DispVal = n.displacementMapAmount / 100
					mAO.Displacement=Displacement_3D__3dsmax ()
					mAO.Displacement.objectIndependent = off
					mAO.Displacement.map=n.displacementMap
					mAO.Displacement.mapAmount=DispVal
				)
				else
				(
					mAO.DisplacementMap=n.displacementmap
					mAO.displacementMapAmount=n.displacementMapAmount 
				)
			)
			temp_material=mAO
			)
		--VRay Material		
		if classof n == VRayMtl then
			(
			if n.texmap_bump_on == on and AO_ifBump==true then
			(		
			if classof renderers.current == mental_ray_renderer and overrideRENDERER !=2 then

				(
					BumpVal = n.texmap_bump_multiplier / 100
					mAO.Bump=Bump__3dsmax ()
					mAO.Bump.map=n.texmap_bump
					mAO.Bump.multiplier=BumpVal
				)
			else
				(
					mAO.Bumpmap=n.texmap_bump
					mAO.BumpmapAmount=n.texmap_bump_multiplier
				)
			)
			if n.texmap_displacement_on == true and AO_ifDisp==true then
			(
			if classof renderers.current == mental_ray_renderer and overrideRENDERER !=2 then		
				(
					DispVal = n.texmap_displacement_multiplier / 100
					mAO.Displacement=Displacement_3D__3dsmax ()
					mAO.Displacement.objectIndependent = off
					mAO.Displacement.map=n.texmap_displacement
					mAO.Displacement.mapAmount=DispVal
				)
				else
				(
					mAO.DisplacementMap=n.texmap_displacement
					mAO.displacementMapAmount=n.texmap_displacement_multiplier
				)
			)
			temp_material=mAO
			)

		--Arch Design Material	
		if classof n ==Arch___Design__mi  then
			(
			if n.bump_map_on == on and AO_ifBump==true then
			(		
			if classof renderers.current == mental_ray_renderer and overrideRENDERER !=2 then
				(
					BumpVal = n.bump_map_amt
					mAO.Bump=Bump__3dsmax ()
					mAO.Bump.map=n.bump_map
					mAO.Bump.multiplier=BumpVal
				)
				else
				(
					mAO.Bumpmap=n.bump_map
					mAO.BumpmapAmount=n.bump_map_amt*100
				)
			)
			if n.displacement_map_on == on and AO_ifDisp==true then
			(	
			if classof renderers.current == mental_ray_renderer and overrideRENDERER !=2 then
				(
					DispVal = n.displacement_map_amt
					mAO.Displacement=Displacement_3D__3dsmax ()
					mAO.Displacement.objectIndependent = on
					mAO.Displacement.map=n.displacement_map
					mAO.Displacement.mapAmount=DispVal
					print dispval
				)
				else
				(			
					mAO.DisplacementMap=n.displacement_map
					mAO.displacementMapAmount=n.displacement_map_amt*100
				)
			)
			temp_material=mAO
			)
		if classof n != Arch___Design__mi and classof n != VRayMtl and classof n != standardmaterial then
			(
			temp_material=mAO
			)
	)--end of BaseAO
	
if func == 3 then
	
	(	
		
		if classof renderers.current == mental_ray_renderer and overrideRENDERER !=2 and overrideRENDERER !=4 then
		(
		mental_ref_mat=mental_ray()
		mental_ref_mat.surface = metal ()
		mental_ref_mat.surface.Surface_Material = color 0 0 0 255
		mental_ref_mat.surface.Reflectivity = 1
		mental_ref_mat.surface.Reflect_Color = color 255 255 255 255
		mental_ref_mat.surface.Blur_Reflection = REF_blurchk
		mental_ref_mat.surface.spread = REF_spread
		mental_ref_mat.surface.Samples = REF_sample
		)
		else
		(
		VRay_ref_mat=VRayMtlWrapper()
		VRay_ref_mat.baseMtl=VRayMtl reflection:white diffuse:black reflection_subdivs:REF_sample reflection_lockGlossiness:off
		if REF_blurchk==false then
		(VRay_ref_mat.baseMtl.reflection_glossiness=1)
		else
		(VRay_ref_mat.baseMtl.reflection_glossiness=(1-REF_spread))
		)

		--Standard Material	
		if classof n == standardmaterial then
			(
			if n.bumpMapEnable == on and REF_ifBump==true then
			(		
			if classof renderers.current == mental_ray_renderer and overrideRENDERER !=2 then
				(
					BumpVal = n.bumpMapAmount / 100
					mental_ref_mat.Bump=Bump__3dsmax ()
					mental_ref_mat.Bump.map=n.bumpmap
					mental_ref_mat.Bump.multiplier=BumpVal
				)
				else
				(
					VRay_ref_mat.BaseMtl.texmap_bump=n.bumpmap
					VRay_ref_mat.BaseMtl.texmap_bump_multiplier=n.bumpMapAmount
				)
			)
			if n.displacementMapEnable == on and REF_ifDisp==true then
			(		
			if classof renderers.current == mental_ray_renderer and overrideRENDERER !=2 then
				(
					DispVal = n.displacementMapAmount / 100
					mental_ref_mat.Displacement=Displacement_3D__3dsmax ()
					mental_ref_mat.Displacement.objectIndependent = off
					mental_ref_mat.Displacement.map=n.displacementMap
					mental_ref_mat.Displacement.mapAmount=DispVal
				)
				else
				(
					VRay_ref_mat.BaseMtl.texmap_displacement=n.displacementmap
					VRay_ref_mat.BaseMtl.texmap_displacement_multiplier=n.displacementMapAmount 
				)
			)
			if classof renderers.current == mental_ray_renderer then
			(temp_material=mental_ref_mat)
			else (temp_material=VRay_ref_mat)
			)
		--VRay Material		
		if classof n == VRayMtl then
			(
			if n.texmap_bump_on == on and REF_ifBump==true then
			(		
			if classof renderers.current == mental_ray_renderer and overrideRENDERER !=2 then
				(
					BumpVal = n.texmap_bump_multiplier / 100
					mental_ref_mat.Bump=Bump__3dsmax ()
					mental_ref_mat.Bump.map=n.texmap_bump
					mental_ref_mat.Bump.multiplier=BumpVal
				)
			else
				(
					VRay_ref_mat.BaseMtl.texmap_bump=n.texmap_bump
					VRay_ref_mat.BaseMtl.texmap_bump_multiplier=n.texmap_bump_multiplier
				)
			)
			if n.texmap_displacement_on == true and REF_ifDisp==true then
			(
			if classof renderers.current == mental_ray_renderer and overrideRENDERER !=2 then		
				(
					DispVal = n.texmap_displacement_multiplier / 100
					mental_ref_mat.Displacement=Displacement_3D__3dsmax ()
					mental_ref_mat.Displacement.objectIndependent = off
					mental_ref_mat.Displacement.map=n.texmap_displacement
					mental_ref_mat.Displacement.mapAmount=DispVal
				)
				else
				(
					VRay_ref_mat.BaseMtl.texmap_displacement=n.texmap_displacement
					VRay_ref_mat.BaseMtl.texmap_displacement_multiplier=n.texmap_displacement_multiplier
				)
			)
			if classof renderers.current == mental_ray_renderer then
			(temp_material=mental_ref_mat)
			else (temp_material=VRay_ref_mat)
			)

		--Arch Design Material	
		if classof n ==Arch___Design__mi  then
			(
			if n.bump_map_on == on and REF_ifBump==true then
			(		
			if classof renderers.current == mental_ray_renderer and overrideRENDERER !=2 then
				(
					BumpVal = n.bump_map_amt
					mental_ref_mat.Bump=Bump__3dsmax ()
					mental_ref_mat.Bump.map=n.bump_map
					mental_ref_mat.Bump.multiplier=BumpVal
				)
				else
				(
					VRay_ref_mat.BaseMtl.texmap_bump=n.bump_map
					VRay_ref_mat.BaseMtl.texmap_bump_multiplier=n.bump_map_amt*100
				)
			)
			if n.displacement_map_on == on and REF_ifDisp==true then
			(	
			if classof renderers.current == mental_ray_renderer and overrideRENDERER !=2 then
				(
					DispVal = n.displacement_map_amt
					mental_ref_mat.Displacement=Displacement_3D__3dsmax ()
					mental_ref_mat.Displacement.objectIndependent = on
					mental_ref_mat.Displacement.map=n.displacement_map
					mental_ref_mat.Displacement.mapAmount=DispVal
				)
				else
				(			
					VRay_ref_mat.BaseMtl.texmap_displacement=n.displacement_map
					VRay_ref_mat.BaseMtl.texmap_displacement_multiplier=n.displacement_map_amt*100
				)
			)
			if classof renderers.current == mental_ray_renderer then
			(temp_material=mental_ref_mat)
			else (temp_material=VRay_ref_mat)
			)
		if classof n != Arch___Design__mi and classof n != VRayMtl and classof n != standardmaterial then
			(
			if classof renderers.current == mental_ray_renderer then
			(temp_material=mental_ref_mat)
			else (temp_material=VRay_ref_mat)
			)
	)--end of BaseAO
	
	
	if func == 4 then
	
	(	
------------------------
if classof renderers.current==default_scanline_renderer then
(
				scanline_ref_mat = matteshadow ()
				scanline_ref_mat.receiveshadows = off
				scanline_ref_mat.amount=100
				scanline_ref_mat.map=Raytrace ()
				temp_material=scanline_ref_mat
)
else
(
		
		case of
			(
				(classof renderers.current==Mental_Ray_Renderer): 
					(
						mental_ref_mat=mental_ray()
						mental_ref_mat.surface = metal ()
						mental_ref_mat.surface.Surface_Material = color 0 0 0 255
						mental_ref_mat.surface.Reflectivity = 1
						mental_ref_mat.surface.Reflect_Color = color 255 255 255 255
						mental_ref_mat.surface.Blur_Reflection = REF_blurchk
						mental_ref_mat.surface.spread = REF_spread
						mental_ref_mat.surface.Samples = REF_sample
					)
				(classof renderers.current==classof vr): 
					(
						VRay_ref_mat=VRayMtlWrapper()
						VRay_ref_mat.baseMtl=VRayMtl reflection:white diffuse:black reflection_subdivs:REF_sample reflection_lockGlossiness:off
						if REF_blurchk==false then
						(VRay_ref_mat.baseMtl.reflection_glossiness=1)
						else
						(VRay_ref_mat.baseMtl.reflection_glossiness=(1-REF_spread))
					)
			)
		
----------------------------------

		--Standard Material	
		if classof n == standardmaterial then
			(
			if n.displacementMapEnable == on and Matte_ifDisp==true then
			(		
			if classof renderers.current == mental_ray_renderer then
				(
					DispVal = n.displacementMapAmount / 100
					mental_ref_mat.Displacement=Displacement_3D__3dsmax ()
					mental_ref_mat.Displacement.objectIndependent = off
					mental_ref_mat.Displacement.map=n.displacementMap
					mental_ref_mat.Displacement.mapAmount=DispVal
				)
				if classof renderers.current==classof vr then
				(
					VRay_ref_mat.BaseMtl.texmap_displacement=n.displacementmap
					VRay_ref_mat.BaseMtl.texmap_displacement_multiplier=n.displacementMapAmount 
				)
			)
			if classof renderers.current == mental_ray_renderer then
			(temp_material=mental_ref_mat)
			else (temp_material=VRay_ref_mat)

			)
		--VRay Material		
		if classof n == VRayMtl then
			(

			if n.texmap_displacement_on == true and Matte_ifDisp==true then
			(
			if classof renderers.current == mental_ray_renderer and overrideRENDERER !=2 then		
				(
					DispVal = n.texmap_displacement_multiplier / 100
					mental_ref_mat.Displacement=Displacement_3D__3dsmax ()
					mental_ref_mat.Displacement.objectIndependent = off
					mental_ref_mat.Displacement.map=n.texmap_displacement
					mental_ref_mat.Displacement.mapAmount=DispVal
				)
				else
				(
					VRay_ref_mat.BaseMtl.texmap_displacement=n.texmap_displacement
					VRay_ref_mat.BaseMtl.texmap_displacement_multiplier=n.texmap_displacement_multiplier
				)
			)
			if classof renderers.current == mental_ray_renderer then
			(temp_material=mental_ref_mat)
			else (temp_material=VRay_ref_mat)
			)

		--Arch Design Material	
		if classof n ==Arch___Design__mi  then
			(

			if n.displacement_map_on == on and Matte_ifDisp==true then
			(	
			if classof renderers.current == mental_ray_renderer and overrideRENDERER !=2 then
				(
					DispVal = n.displacement_map_amt
					mental_ref_mat.Displacement=Displacement_3D__3dsmax ()
					mental_ref_mat.Displacement.objectIndependent = on
					mental_ref_mat.Displacement.map=n.displacement_map
					mental_ref_mat.Displacement.mapAmount=DispVal
				)
				else
				(			
					VRay_ref_mat.BaseMtl.texmap_displacement=n.displacement_map
					VRay_ref_mat.BaseMtl.texmap_displacement_multiplier=n.displacement_map_amt*100
				)
			)
			if classof renderers.current == mental_ray_renderer then
			(temp_material=mental_ref_mat)
			else (temp_material=VRay_ref_mat)
			)
		if classof n != Arch___Design__mi and classof n != VRayMtl and classof n != standardmaterial then
			(
			if classof renderers.current == mental_ray_renderer then
			(temp_material=mental_ref_mat)
			else (temp_material=VRay_ref_mat)
			)
		)
	)--end of BaseAO
	
)	
	
	------------------aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-------------------------

Struct MaterialReplace
	
(
	--MATTE_RENDER
	fn MATTE_REPLACE=
	(	
		--geometry.material=matte_bl
		for i in geometry do
		(
			
			if classof i.material == Multimaterial then
			(
				new_multimaterial = Multimaterial numsubs:i.material.numsubs
				for m = 1 to i.material.numsubs do
				(
				BaseMaterialReplace i.material[m] 1
					if finditem current_selection i == 0 then
					(
						temp_material.diffuse = black
					)
				new_multimaterial[m]=temp_material
					
				)
				i.material = new_multimaterial
			)
			if classof i.material == Blend then
			(
				new_blendmaterial = Blend()
				BaseMaterialReplace i.material.map1 1
					if finditem current_selection i == 0 then
					(
						temp_material.diffuse = black
					)
				new_blendmaterial.map1 = temp_material
				BaseMaterialReplace i.material.map2 1
					if finditem current_selection i == 0 then
					(
						temp_material.diffuse = black
					)
				new_blendmaterial.map2 = temp_material
				i.material = new_blendmaterial
			)
			
				if classof i.material == doublesided then
			(
				new_doublesidedmaterial = doublesided()
				new_doublesidedmaterial.Translucency = i.material.Translucency
				BaseMaterialReplace i.material.material1 1
					if finditem current_selection i == 0 then
					(
						temp_material.diffuse = black
					)
				new_doublesidedmaterial.material1 = temp_material
				BaseMaterialReplace i.material.material2 1
					if finditem current_selection i == 0 then
					(
						temp_material.diffuse = black
					)
				new_doublesidedmaterial.material2 = temp_material
				i.material = new_doublesidedmaterial
			)
					if classof i.material == TopBottom then
			(
				new_TopBottommaterial = TopBottom()
				new_TopBottommaterial.Blend=i.material.Blend
				new_TopBottommaterial.position=i.material.position
				new_TopBottommaterial.coordinates=i.material.coordinates
				BaseMaterialReplace i.material.topMaterial 1
					if finditem current_selection i == 0 then
					(
						temp_material.diffuse = black
					)
				new_TopBottommaterial.topMaterial = temp_material
				
				BaseMaterialReplace i.material.bottomMaterial 1
					if finditem current_selection i == 0 then
					(
						temp_material.diffuse = black
					)
				new_TopBottommaterial.bottomMaterial = temp_material
				
				i.material = new_TopBottommaterial
			)

			
			if classof i.material !=multimaterial and classof i.material !=Blend and classof i.material !=doublesided and classof i.material != TopBottom then
			(

				BaseMaterialReplace i.material 1
				if finditem current_selection i == 0 then
				(
					temp_material.diffuse = black
				)
				i.material=temp_material

			)

		)

	),
		
fn AO_REPLACE =
	(	
				if AO_ifwired == true then -- material for wired AO
				(
				current_selection = selection as array
				mST = standardmaterial ()
				mST.wire = on
				mST.diffuse = color 0 0 0
				mCo =  compositematerial ()
				mCo.materialList[2] = mST
				)

			for i in geometry do
			(
				if classof i.material == Multimaterial then
				(
					new_multimaterial = Multimaterial numsubs:i.material.numsubs
					for m = 1 to i.material.numsubs do
					(
						BaseMaterialReplace i.material[m] 2
						
						if AO_ifwired == true and finditem current_selection i != 0 then
						(
							mCo.basematerial = temp_material
							new_multimaterial[m]=mCo
						)
						else (new_multimaterial[m]=temp_material)
					)
					i.material = new_multimaterial
				)
				if classof i.material == Blend then
						(
							new_blendmaterial = Blend()
							BaseMaterialReplace i.material.map1 2
						
							if AO_ifwired == true and finditem current_selection i != 0 then
							(
								mCo.basematerial = temp_material
								new_blendmaterial.map1=mCo
							)
						else (new_blendmaterial.map1 = temp_material)
							
						BaseMaterialReplace i.material.map2 2
						
							if AO_ifwired == true and finditem current_selection i != 0 then
							(
								mCo.basematerial = temp_material
								new_blendmaterial.map2=mCo
							)
							else (new_blendmaterial.map2 = temp_material)
						
							new_blendmaterial.map2 = temp_material
							i.material = new_blendmaterial
						)
					if classof i.material == doublesided then
				(
					new_doublesidedmaterial = doublesided()
					new_doublesidedmaterial.Translucency = i.material.Translucency
					BaseMaterialReplace i.material.material1 2
					
							if AO_ifwired == true and finditem current_selection i != 0 then
					(
						mCo.basematerial = temp_material
						new_doublesidedmaterial.material1=mCo
					)
					else (new_doublesidedmaterial.material1 = temp_material)
					
					BaseMaterialReplace i.material.material2 2
					
									if AO_ifwired == true and finditem current_selection i != 0 then
					(
						mCo.basematerial = temp_material
						new_doublesidedmaterial.material2=mCo
					)
					else (new_doublesidedmaterial.material2 = temp_material)
					
					
					i.material = new_doublesidedmaterial
				)
						if classof i.material == TopBottom then
				(
					new_TopBottommaterial = TopBottom()
					new_TopBottommaterial.Blend=i.material.Blend
					new_TopBottommaterial.position=i.material.position
					new_TopBottommaterial.coordinates=i.material.coordinates
					BaseMaterialReplace i.material.topMaterial 2
					
							if AO_ifwired == true and finditem current_selection i != 0 then
					(
						mCo.basematerial = temp_material
						new_TopBottommaterial.topMaterial=mCo
					)
					else (new_TopBottommaterial.topMaterial = temp_material)
					
					BaseMaterialReplace i.material.bottomMaterial 2
					
									if AO_ifwired == true and finditem current_selection i != 0 then
					(
						mCo.basematerial = temp_material
						new_TopBottommaterial.bottomMaterial=mCo
					)
					else (new_TopBottommaterial.bottomMaterial = temp_material)
					
					i.material = new_TopBottommaterial
				)
				if classof i.material !=multimaterial and classof i.material !=Blend and classof i.material !=doublesided and classof i.material != TopBottom then
				(

					BaseMaterialReplace i.material 2

					if AO_ifwired == true and finditem current_selection i != 0 then
					(
						mCo.basematerial = temp_material
						i.material=mCo
					)
					else (i.material=temp_material)
				)

			)
		
	),
	
	fn REF_REPLACE=
	(	
		for i in selection do
		(
			if classof i.material == Multimaterial then
			(
				new_multimaterial = Multimaterial numsubs:i.material.numsubs
				for m = 1 to i.material.numsubs do
				(
				BaseMaterialReplace i.material[m] 3
				new_multimaterial[m]=temp_material
				)
				i.material = new_multimaterial
			)
			if classof i.material == Blend then
			(
				new_blendmaterial = Blend()
				BaseMaterialReplace i.material.map1 3

				new_blendmaterial.map1 = temp_material
				BaseMaterialReplace i.material.map2 3

				new_blendmaterial.map2 = temp_material
				i.material = new_blendmaterial
			)
			
				if classof i.material == doublesided then
			(
				new_doublesidedmaterial = doublesided()
				new_doublesidedmaterial.Translucency = i.material.Translucency
				BaseMaterialReplace i.material.material1 3

				new_doublesidedmaterial.material1 = temp_material
				BaseMaterialReplace i.material.material2 3

				new_doublesidedmaterial.material2 = temp_material
				i.material = new_doublesidedmaterial
			)
					if classof i.material == TopBottom then
			(
				new_TopBottommaterial = TopBottom()
				new_TopBottommaterial.Blend=i.material.Blend
				new_TopBottommaterial.position=i.material.position
				new_TopBottommaterial.coordinates=i.material.coordinates
				BaseMaterialReplace i.material.topMaterial 3

				new_TopBottommaterial.topMaterial = temp_material
				
				BaseMaterialReplace i.material.bottomMaterial 3

				new_TopBottommaterial.bottomMaterial = temp_material
				
				i.material = new_TopBottommaterial
			)

			
			if classof i.material !=multimaterial and classof i.material !=Blend and classof i.material !=doublesided and classof i.material != TopBottom then
			(

				BaseMaterialReplace i.material 3

				i.material=temp_material

			)

		)

	),
	
		--Reflection MATTE_RENDER
	fn REFL_MATTE_REPLACE=
	(	

		--geometry.material=matte_bl
		for i in geometry do
		(
		if finditem current_selection i ==0 then
		(funcNumb=1)
		else (funcNumb=4)

			if classof i.material == Multimaterial then
			(
				new_multimaterial = Multimaterial numsubs:i.material.numsubs
				for m = 1 to i.material.numsubs do
				(
				BaseMaterialReplace i.material[m] funcNumb
				new_multimaterial[m]=temp_material
					
				)
				i.material = new_multimaterial
			)
			if classof i.material == Blend then
			(
				new_blendmaterial = Blend()
				BaseMaterialReplace i.material.map1 funcNumb

				new_blendmaterial.map1 = temp_material
				BaseMaterialReplace i.material.map2 funcNumb

				new_blendmaterial.map2 = temp_material
				i.material = new_blendmaterial
			)
			
				if classof i.material == doublesided then
			(
				new_doublesidedmaterial = doublesided()
				new_doublesidedmaterial.Translucency = i.material.Translucency
				BaseMaterialReplace i.material.material1 funcNumb

				new_doublesidedmaterial.material1 = temp_material
				BaseMaterialReplace i.material.material2 funcNumb

				new_doublesidedmaterial.material2 = temp_material
				i.material = new_doublesidedmaterial
			)
					if classof i.material == TopBottom then
			(
				new_TopBottommaterial = TopBottom()
				new_TopBottommaterial.Blend=i.material.Blend
				new_TopBottommaterial.position=i.material.position
				new_TopBottommaterial.coordinates=i.material.coordinates
				BaseMaterialReplace i.material.topMaterial funcNumb

				new_TopBottommaterial.topMaterial = temp_material
				
				BaseMaterialReplace i.material.bottomMaterial funcNumb

				new_TopBottommaterial.bottomMaterial = temp_material
				
				i.material = new_TopBottommaterial
			)

			
			if classof i.material !=multimaterial and classof i.material !=Blend and classof i.material !=doublesided and classof i.material != TopBottom then
			(

				BaseMaterialReplace i.material funcNumb

				i.material=temp_material

			)

		)

	)

	
)

---------------------------------------------------------------------------------------------------------------
-------------------------------------RENDER FUNCTIONS------------------------------------------------
---------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------


--MATTE_RENDER_FUNCTION
fn mattemat Matte_ifConMat Matte_ifConOt Matte_ifDisp overrideRENDERER cam =
(
   
    if selection.count > 0 then
    (

	(
		case overrideRENDERER.selection of
		(
		1: case of
			(
				(classof renderers.current==Default_Scanline_Renderer): scanline_PREPS black off 
				(classof renderers.current==Mental_Ray_Renderer): mentalray_PREPS black off
				(classof renderers.current==classof vr): vray_PREPS black off
			)
		2: scanline_PREPS black off 
		3: mentalray_PREPS black off
		4: vray_PREPS black off
		)
	)

        checksel = for m in selection where superclassof m == geometryclass collect m
        if checksel.count > 0 and selection.count > 0 then
        (           
                if Matte_ifConOt != true then
                (

                    for z in selection do
                    (
                    z.visibility = bezier_float ()
                    z.visibility.controller.value = 1
                    )
                )
                if Matte_ifConMat == true or Matte_ifDisp==true then
                (
					current_selection=selection as array
					materialReplace.matte_replace()
                )
				else
				(
                bl = standardMaterial diffuse: (color 0 0 0) selfIllumAmount: 100 twosided: true
                wh = standardMaterial diffuse: (color 255 255 255) selfIllumAmount: 100 twosided: true
                for i in objects do i.material = bl
                for a in selection do a.material = wh
				)

				renderAndrecall()
				
        )
        else
        (
        messagebox "Select at least one geometry object"
        )
    )
    else
        (
        messagebox "Select at least one geometry object"
        )
)--end of mattemat fn

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--AO_RENDER_FUNCTION
    fn matAO UIsamp UIspread UImdist UIfall AO_ifBump AO_ifDisp wired overrideRENDERER cam=
(

	(
		case overrideRENDERER.selection of
		(
		1: case of
			(
				(classof renderers.current==Default_Scanline_Renderer): scanline_PREPS white off 
				(classof renderers.current==Mental_Ray_Renderer): mentalray_PREPS white off
				(classof renderers.current==classof vr): vray_PREPS white off
			)
		2: scanline_PREPS white off 
		3: mentalray_PREPS white off
		4: vray_PREPS white off
		)
	)
			if AO_selectedonly == true then
			(
				objects.primaryVisibility = off
                selection.primaryVisibility = on
			)				
				
			(	
				if classof renderers.current==Default_Scanline_Renderer then
				(
				temp_skylight=skylight castShadows:on color:white rays_per_sample:UIsamp multiplier:1 on:on
				)
				if classof renderers.current==classof vr then
				(
				temp_skylight=VRayLight dome_spherical:on size0:0 size1:0 type:1 multiplier:1 on:on invisible:on subdivs:UIsamp multiplier:1
				)
				if AO_ifBump == true or AO_ifDisp==true then
							(
								materialReplace.ao_replace()
							)
							else
								(
									if classof renderers.current == mental_ray_renderer and overrideRENDERER !=2 then
									(
									mAO = mental_ray ()
									mAO.surface = Ambient_Reflective_Occlusion__3dsmax samples: UIsamp spread: UIspread max_distance: UImdist falloff: UIfall
									)
									else
									(
										mAO = standardmaterial diffuse:white
									)
									geometry.material=mAO
									if wired == true then
									(
										current_selection = selection as array
										mST = standardmaterial ()
										mST.wire = on
										mST.diffuse = color 0 0 0
										mCo =  compositematerial ()
										mCo.basematerial = mAO
										mCo.materialList[2] = mST
										current_selection.material = mCo
									)
								)
			)

				renderAndrecall()

)--end of matAO fn  


-------END-------------------------AO RENDER FUNCTIONS------------------------------------------------

-------START-------------------------SHADOW RENDER FUNCTIONS--------------------------------------


--SHADOW_PASS_FUNCTION
	
	
    fn matsha opak applyatmo atmodepth overrideRENDERER cam=
    (
		
        if selection.count > 1 then
        (
        checkgeo = for mod in $ where superclassof mod == geometryclass collect mod
		checklight = for kod in $ where superclassof kod == light collect kod
        if checkgeo.count > 0 and selection.count > 1 and checklight.count > 0 then
		(

		--setting render settings
	(
		case overrideRENDERER.selection of
		(
		1: case of
			(
				(classof renderers.current==Default_Scanline_Renderer): scanline_PREPS white off 
				(classof renderers.current==Mental_Ray_Renderer): mentalray_PREPS white off
				(classof renderers.current==classof vr): vray_PREPS white off
			)
		2: scanline_PREPS white off 
		3: mentalray_PREPS white off
		4: vray_PREPS white off
		)
	)
			
                --Object Preperations
                objects.primaryVisibility = off
                selection.primaryVisibility = on
			if classof renderers.current != classof vr then
			(
                msha = matteshadow ()
                msha.receiveshadows = on               
                if opak == true then
                    (msha.opaqueAlpha=true) else (msha.opaqueAlpha=false)
                if applyatmo ==true then
                    (msha.applyatmosphere=true) else (msha.applyatmosphere=false)
                if atmodepth == 1 then
                    (msha.atmosphereDepth = 0) else (msha.atmosphereDepth = 1)
               
                for a in selection do a.material = msha
			)
			else
			(
				Sha_vray_mat= VRayMtlWrapper ()
				Sha_vray_mat.MatteSurface = on
				Sha_vray_mat.AlphaContribution = -1
				Sha_vray_mat.Matte_Shadows = on
				Sha_vray_mat.Matte_ShadowsAffectAlpha = on
				Sha_vray_mat.Matte_ReflectionMultiplier = 0
				Sha_vray_mat.Matte_RefractionMultiplier = 0
				Sha_vray_mat.Matte_GIMultiplier = 0
				
				for a in selection do
				(
					if a.material != undefined then
					(
					Sha_vray_mat.basematerial=a.material
					a.material=Sha_vray_mat
					)
					else
					(
					Sha_vray_mat.basematerial=standardmaterial()
					a.material=Sha_vray_mat
					)
				)

			)
				--turn on selected lights
				for dag in selection do
				(
					if superclassof dag ==light then
					(
						if classof dag !=VraySun then
						(
							dag.on=true
							if finditem lights_on_array dag==0 then (append lights_temporaryon_array dag)
						)
						if classof dag == VraySun then
						(
							dag.enabled=true
							if finditem Vray_Sun_array dag==0 then (append lights_temporaryonVray_array dag)
						)
						if classof dag !=VraySun and classof dag != VRayLight then
						(
							dag.on=true
							if finditem lights_on_array dag==0 then (append lights_temporaryon_array dag)
							if dag.baseobject.castshadows==off then 
								(
									
									append lights_temporarycastshadows_array dag
									dag.baseobject.castshadows=on
								)
						)
					)
					
				)

				renderAndrecall()

			)
			else
			(messagebox "Select at least one geometry and one light object")
		)
        else
        (
        messagebox "Select at least one geometry and one light object"
        )
    

)--end of matsha fn

-------END-------------------------SHADOW RENDER FUNCTIONS--------------------------------------

-------START-----------------------REFLECTION RENDER FUNCTIONS---------------------------------


--REFLECTION_PASS_FUNCTION
    fn matref UIBlurchk UIspread UIsamples Env overrideRENDERER cam=
(
	if selection.count > 0 then
		(
			checkgeo = for mod in $ where superclassof mod == geometryclass collect mod
			checklight = for kod in $ where superclassof kod == light collect kod
			if lights.count == 0 then checklight.count = 1
			if checkgeo.count > 0 and selection.count > 0 and checklight.count > 0 then
		(
    (

		--setting render settings
	(
		case overrideRENDERER.selection of
		(
		1: case of
			(
				(classof renderers.current==Default_Scanline_Renderer): scanline_PREPS black Env
				(classof renderers.current==Mental_Ray_Renderer): mentalray_PREPS black Env
				(classof renderers.current==classof vr): vray_PREPS black Env
			)
		2: scanline_PREPS black Env
		3: mentalray_PREPS black Env
		4: vray_PREPS black Env
		)
	)
	if overrideRENDERER.selection==1 then
		(
		SceneExposureControl.exposureControl=exposureControl
		renderpresets.load 0 (GetDir #renderPresets + "\\cur_tmp.rps") #{32,34}	
		)
                objects.primaryVisibility = off
                selection.primaryVisibility = on
					
			if classof renderers.current == default_scanline_renderer then
			(
				scanline_ref_mat = matteshadow ()
				scanline_ref_mat.receiveshadows = off
				scanline_ref_mat.amount=100
				scanline_ref_mat.map=Raytrace ()
				 for a in selection do a.material = scanline_ref_mat
			)
			
			if classof renderers.current == mental_ray_renderer then
			(
				if REF_ifBump == true or REF_ifDisp == true then
				(
					materialReplace.ref_replace()
				)
				else
				(
					mental_ref_mat=mental_ray()
					mental_ref_mat.surface = metal ()
					mental_ref_mat.surface.Surface_Material = color 0 0 0 255
					mental_ref_mat.surface.Reflectivity = 1
					mental_ref_mat.surface.Reflect_Color = color 255 255 255 255
					mental_ref_mat.surface.Blur_Reflection = REF_blurchk
					mental_ref_mat.surface.spread = REF_spread
					mental_ref_mat.surface.Samples = REF_sample
					 for a in selection do a.material = mental_ref_mat
				)
			)
			
			if classof renderers.current == classof vr then
			(
				if REF_ifBump == true or REF_ifDisp == true then
				(
					materialReplace.ref_replace()
				)
				else
				(
					VRay_ref_mat=VRayMtlWrapper()
					VRay_ref_mat.baseMtl=VRayMtl reflection:white diffuse:black reflection_subdivs:REF_sample reflection_lockGlossiness:off
					if REF_blurchk==false then
					(VRay_ref_mat.baseMtl.reflection_glossiness=1)
					else
					(VRay_ref_mat.baseMtl.reflection_glossiness=(1-REF_spread))
					 for a in selection do a.material = VRay_ref_mat
				)
	
			)		
				--turn on selected lights
				for dag in selection do
				(
					if superclassof dag ==light then
						
					
					(
						if classof dag !=VraySun then
						(
							dag.on=true
							if finditem lights_on_array dag==0 then (append lights_temporaryon_array dag)
						)
						if classof dag == VraySun then
						(
							dag.enabled=true
							if finditem Vray_Sun_array dag==0 then (append lights_temporaryonVray_array dag)
						)
						if classof dag !=VraySun and classof dag != VRayLight and classof dag !=mr_sky then
						(
							dag.on=true
							if finditem lights_on_array dag==0 then (append lights_temporaryon_array dag)
							if dag.baseobject.castshadows==off then 
								(
									
									append lights_temporarycastshadows_array dag
									dag.baseobject.castshadows=on
								)
						)
					)
					
				)
				
			


				renderAndrecall()


    )--end of matref fn
	
         )
		else
        (messagebox "Select at least one geometry and one light object. If there isnt any light in scene just select an object" title:#Error)
        )
        else
        (
        messagebox "Select at least one geometry and one light object. If there isnt any light in scene just select an object" title:#Error
        )	
)
-------END-----------------------REFLECTION RENDER FUNCTIONS---------------------------------

-------START-----------------------MATTE REFLECTION FUNCTION---------------------------------


--MATTE_REFLECTION_FUNCTION
    fn reflmatte UIBlurchk UIspread UIsamples Env overrideRENDERER cam=
(
	if selection.count > 0 then
		(
			checkgeo = for mod in $ where superclassof mod == geometryclass collect mod
			if checkgeo.count > 0 and selection.count > 0 then
		(
    (

		--setting render settings
	(
		case overrideRENDERER.selection of
		(
		1: case of
			(
				(classof renderers.current==Default_Scanline_Renderer): scanline_PREPS black off
				(classof renderers.current==Mental_Ray_Renderer): mentalray_PREPS black off
				(classof renderers.current==classof vr): vray_PREPS black off
			)
		2: scanline_PREPS black off
		3: mentalray_PREPS black off
		4: vray_PREPS black off
		)
	)
			
                objects.primaryVisibility = off
                selection.primaryVisibility = on
					
                if Matte_ifConOt != true then
                (

                    for z in selection do
                    (
                    z.visibility = bezier_float ()
                    z.visibility.controller.value = 1
                    )
                )
					
			if classof renderers.current == default_scanline_renderer then
			(
			
			           

                if Matte_ifConMat == true then
                (
					current_selection=selection as array
					materialReplace.REFL_MATTE_REPLACE()
                )
				else
				(
				matte_bl = standardMaterial diffuse: white selfIllumAmount: 100 twosided: true --Standard Self Illuminated Material 
				objects.material = matte_bl
				scanline_ref_mat = matteshadow ()
				scanline_ref_mat.receiveshadows = off
				scanline_ref_mat.amount=100
				scanline_ref_mat.map=Raytrace ()
				 for a in selection do a.material = scanline_ref_mat
				)
			

			)
			
			if classof renderers.current == mental_ray_renderer then
			(
				if Matte_ifDisp == true or Matte_ifConMat == true then
				(
					current_selection=selection as array
					materialReplace.REFL_MATTE_REPLACE()
					--materialReplace.ref_replace()
				)
				else
				(
					matte_bl = standardMaterial diffuse: white selfIllumAmount: 100 twosided: true --Standard Self Illuminated Material 
					objects.material = matte_bl
					mental_ref_mat=mental_ray()
					mental_ref_mat.surface = metal ()
					mental_ref_mat.surface.Surface_Material = color 0 0 0 255
					mental_ref_mat.surface.Reflectivity = 1
					mental_ref_mat.surface.Reflect_Color = color 255 255 255 255
					mental_ref_mat.surface.Blur_Reflection = REF_blurchk
					mental_ref_mat.surface.spread = REF_spread
					mental_ref_mat.surface.Samples = REF_sample
					 for a in selection do a.material = mental_ref_mat
				)
			)
			
			if classof renderers.current == classof vr then
			(
				if Matte_ifDisp == true or Matte_ifConMat == true then
				(
					current_selection=selection as array
					materialReplace.REFL_MATTE_REPLACE()
				)
				else
				(
					matte_bl = standardMaterial diffuse: white selfIllumAmount: 100 twosided: true --Standard Self Illuminated Material 
					objects.material = matte_bl
					VRay_ref_mat=VRayMtlWrapper()
					VRay_ref_mat.baseMtl=VRayMtl reflection:white diffuse:black reflection_subdivs:REF_sample reflection_lockGlossiness:off
					if REF_blurchk==false then
					(VRay_ref_mat.baseMtl.reflection_glossiness=1)
					else
					(VRay_ref_mat.baseMtl.reflection_glossiness=(1-REF_spread))
					 for a in selection do a.material = VRay_ref_mat
				)


			)


				renderAndrecall()


    )--end of matref fn
	
         )
		else
        (messagebox "Select at least one geometry and one light object. If there isnt any light in scene just select an object" title:#Error)
        )
        else
        (
        messagebox "Select at least one geometry and one light object. If there isnt any light in scene just select an object" title:#Error
        )	
)
-------END-----------------------MATTE REFLECTION FUNCTION---------------------------------
---------------------------------------------------------------------------------------------------------------------------------------
--------------ROLLOUT-------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------

(--UI start
global Quick_Passes
try(destroyDialog Quick_Passes )catch()



   
    rollout mat "Matte Render"
    (
	checkbox con_disp "Preserve Displacement Maps"
    checkbox con_mt "Preserve Material Transparency"
    checkbox con_ot "Preserve Object Transparency"
	checkbox reflection_matte "Reflection Matte" tooltip:"Renders mattes of object reflections on selected objects"
		
        on mat open do
        (
		if Matte_ifConMat != undefined then (con_mt.state=Matte_ifConMat) else (Matte_ifConMat=con_mt.state)
		if Matte_ifConOt !=undefined then (con_ot.state=Matte_ifConOt) else (Matte_ifConOt=con_ot.state)
		if Matte_ifDisp !=undefined then (con_disp.state=Matte_ifDisp) else (Matte_ifDisp=con_disp.state)
		if Matte_refmat != undefined then (reflection_matte.state=Matte_refmat) else (Matte_refmat=reflection_matte.state)
        )
		on con_mt changed state do (Matte_ifConMat=con_mt.state)
        on con_ot changed state do (Matte_ifConOt=con_ot.state)
		on con_disp changed state do (Matte_ifDisp=con_disp.state)
		on reflection_matte changed state do (Matte_refmat=reflection_matte.state)
       
    )
    rollout amb "Ambient Occlusion"
    (
        spinner SampSP "Samples" type:#integer range: [0,300,60] fieldwidth:40 across:2 offset:[10,0]
        spinner spreadSP "Spread:" type:#float range:[-999,999,0.75] fieldwidth:40
        spinner mdistSP "Max Distance:" type:#float range:[-999,999,0] fieldwidth:40 across:2 offset:[10,0]
        spinner falloffSP "Falloff:" type:#float range:[-999,999,1] fieldwidth:40
		checkbox bump "Preserve Bump Maps"
		checkbox disp "Preserve Displacement Maps"
		checkbox overAO "AO only on selected objects"
		checkbox wired "Wireframed AO for selected Objects"
		
		
        on amb open do
        (
			if AO_sample != undefined then (SampSP.value=AO_sample)
			if AO_spread != undefined then (spreadSP.value=AO_spread)
			if AO_m_dist != undefined then (mdistSP.value=AO_m_dist)
			if AO_falloff != undefined then (falloffSP.value=AO_falloff)
			if AO_ifWired != undefined then (wired.checked=AO_ifWired)
			if AO_ifBump != undefined then (bump.checked=AO_ifBump)
			if AO_ifDisp != undefined then (disp.checked=AO_ifDisp)
			if AO_selectedonly != undefined then (overAO.checked=AO_selectedonly)
			
			if overrideRENDERER ==1 then
			(
				if classof renderers.current == default_scanline_renderer then
					(
						spreadSP.enabled=false
						mdistSP.enabled=false
						falloffSP.enabled=false
						wired.enabled=false
						sampSP.range=[0,300,10]
						AO_sample=SampSP.value
					)
			
				if classof renderers.current == mental_ray_renderer then
					(
						spreadSP.enabled=true
						mdistSP.enabled=true
						falloffSP.enabled=true
						wired.enabled=true
						sampSP.range=[0,300,60]
						AO_sample=SampSP.value
					)
				if classof renderers.current == classof vr then
					(
						spreadSP.enabled=false
						mdistSP.enabled=false
						falloffSP.enabled=false
						wired.enabled=false
						sampSP.range=[0,300,16]
						AO_sample=SampSP.value
					)
			)
			else
			(
				if overrideRENDERER ==2 then
					(
						spreadSP.enabled=false
						mdistSP.enabled=false
						falloffSP.enabled=false
						wired.enabled=false
						sampSP.range=[0,300,10]
						AO_sample=SampSP.value
					)
				if overrideRENDERER ==3 then
					(
						spreadSP.enabled=true
						mdistSP.enabled=true
						falloffSP.enabled=true
						wired.enabled=true
						sampSP.range=[0,300,60]
						AO_sample=SampSP.value
					)
				if overrideRENDERER ==4 then
					(
						spreadSP.enabled=false
						mdistSP.enabled=false
						falloffSP.enabled=false
						wired.enabled=false
						sampSP.range=[0,300,16]
						AO_sample=SampSP.value
					)
					
			)
			
            AO_sample=SampSP.value
            AO_spread=spreadSP.value
            AO_m_dist=mdistSP.value
            AO_falloff=falloffSP.value
            AO_ifwired=wired.state
			AO_ifBump=bump.state
			AO_ifDisp=disp.state
			AO_selectedonly=overAO.checked

		
		)
        on SampSP changed value do (AO_sample=sampSP.value)
        on spreadSP changed value do (AO_spread=spreadSP.value)
        on mdistSP changed value do (AO_m_dist=mdistSP.value)
        on falloffSP changed value do (AO_falloff=falloffSP.value)
        on wired changed state do (AO_ifwired=wired.state)
		on bump changed state do (AO_ifBump=bump.state)
		on disp changed state do (AO_ifDisp=disp.state)
		on overAO changed state do (AO_selectedonly=overAO.state)
    )
	
    rollout refraf "Reflection"
    (
            checkbox envMap "Use current Environment Map" align:#left checked:true
            checkbox blurref_chk "Blur Reflection" align:#left
            spinner REFspreadSP "Spread:" type:#float range:[0,180,5] fieldwidth:40 across:2
            spinner REFsamplesSP "Samples:" type:#integer range:[1,999,10] fieldwidth:40
			checkbox refbumpchk "Preserve Bump Maps"
			checkbox refdispchk "Preserve Displacement Maps"
	
    on refraf open do
    (
		if REF_envmap != undefined then (envmap.state=REF_envmap)
        if REF_blurchk != undefined then (blurref_chk.state=REF_blurchk)
        if REF_spread != undefined then (REFspreadSP.value=REF_spread)
        if REF_sample !=undefined  then (REFsamplesSP.value=REF_sample)
		if REF_ifBump !=undefined then (refbumpchk.state=REF_ifBump)
		if REF_ifDisp != undefined then (refdispchk.state=REF_ifDisp)
		
		if overrideRENDERER ==1 then
			(
				if classof renderers.current == default_scanline_renderer then
					(
						blurref_chk.enabled=false
						REFspreadSP.enabled=false
						REFsamplesSP.enabled=false
						refbumpchk.enabled=false
						refdispchk.enabled=false
					)
			
				if classof renderers.current == mental_ray_renderer then
					(
						blurref_chk.enabled=true
						REFspreadSP.enabled=true
						REFsamplesSP.enabled=true
						REFspreadSP.range=[1,999,10]
						refbumpchk.enabled=true
						refdispchk.enabled=true
					)
				if classof renderers.current == classof vr then
					(
						blurref_chk.enabled=true
						REFspreadSP.enabled=true
						REFsamplesSP.enabled=true
						REFspreadSP.range=[0,1,0]
						refbumpchk.enabled=true
						refdispchk.enabled=true
					)
			)
			else
			(
				if overrideRENDERER ==2 then
					(
						blurref_chk.enabled=false
						REFspreadSP.enabled=false
						REFsamplesSP.enabled=false
						refbumpchk.enabled=false
						refdispchk.enabled=false
					)
				if overrideRENDERER ==3 then
					(
						blurref_chk.enabled=true
						REFspreadSP.enabled=true
						REFsamplesSP.enabled=true
						REFspreadSP.range=[1,999,10]
						refbumpchk.enabled=true
						refdispchk.enabled=true
					)
				if overrideRENDERER ==4 then
					(
						blurref_chk.enabled=true
						REFspreadSP.enabled=true
						REFsamplesSP.enabled=true
						REFspreadSP.range=[0,1,0]
						refbumpchk.enabled=true
						refdispchk.enabled=true
					)
			)
	
		REF_envmap = envmap.state
        REF_blurchk = blurref_chk.state
        REF_spread = REFspreadSP.value
        REF_sample = REFsamplesSP.value
		REF_ifBump =refbumpchk.state
		REF_ifDisp = refdispchk.state
    )
        on envmap changed state do (REF_envmap = envmap.state)
		on blurref_chk changed state do (REF_blurchk = blurref_chk.state)
        on REFspreadSP changed value do (REF_spread = REFspreadSP.value)
        on REFsamplesSP changed value do (REF_sample = REFsamplesSP.value)
		on refbumpchk changed state do (REF_ifBump = refbumpchk.state)
		on refdispchk changed state do (REF_ifDisp = refdispchk.state)
    )                  

    rollout sha "Shadows"
    (
        checkbox OpaqueAlpha "Opaque Alpha" across:2
        checkbox applyAtmosphere "Apply Atmoshpere"
        radiobuttons atmosphereDepth "" labels:#("At Background Depth", "At Object Depth")
		--dropdownlist shadowtype "Shadow Type" items:#("shadowMap()","raytraceShadow()")
        on sha open do
        (
			if SHA_Opaque_Alpha != undefined then (OpaqueAlpha.state=SHA_Opaque_Alpha)
            if SHA_Apply_Atmosphere != undefined then (applyAtmosphere.state=SHA_Apply_Atmosphere)
            if SHA_ATMOSTATE != undefined then (atmosphereDepth.state=SHA_ATMOSTATE)
			
			
			if overrideRENDERER ==1 then
				(
				if classof renderers.current == default_scanline_renderer then
					(
						OpaqueAlpha.enabled=true
						applyAtmosphere.enabled=true
						atmosphereDepth.enabled=true
					)
			
				if classof renderers.current == mental_ray_renderer then
					(
						OpaqueAlpha.enabled=true
						applyAtmosphere.enabled=true
						atmosphereDepth.enabled=true
					)
				if classof renderers.current == classof vr then
					(
						OpaqueAlpha.enabled=false
						applyAtmosphere.enabled=false
						atmosphereDepth.enabled=false
					)
				)
			else
			(
				if overrideRENDERER ==2 then
					(
						OpaqueAlpha.enabled=true
						applyAtmosphere.enabled=true
						atmosphereDepth.enabled=true
					)
				if overrideRENDERER ==3 then
					(
						OpaqueAlpha.enabled=true
						applyAtmosphere.enabled=true
						atmosphereDepth.enabled=true
					)
				if overrideRENDERER ==4 then
					(
						OpaqueAlpha.enabled=false
						applyAtmosphere.enabled=false
						atmosphereDepth.enabled=false
					)
					
			)

            SHA_Opaque_Alpha = OpaqueAlpha.state
            SHA_Apply_Atmosphere = applyAtmosphere.state
            SHA_ATMOSTATE = atmosphereDepth.state
			
        )
        on OpaqueAlpha changed state do (SHA_Opaque_Alpha = OpaqueAlpha.state)
        on applyAtmosphere changed state do (SHA_Apply_Atmosphere = applyAtmosphere.state)
        on atmosphereDepth changed state do (SHA_ATMOSTATE = atmosphereDepth.state)

		label def1 "Select objects which will receive shadows"
		label def2 "And Lights which will create shadows"
    )
          

  
    rollout About_roll "About" rolledup:false
    (
    label script "QuickPasses v2.15"
    label author "Arda Kutlu"
    label year "2008"
    label web "http://www.ardakutlu.com/"
    label email "ardakutlu@gmail.com"
    )

-----------------------------------------------------------------
              
Tabs_Rollouts = #(
#("Matte",#(mat)),
#("AO",#(amb)),
#("Reflection",#(refraf)),
#("Shadows",#(sha)),
#("About",#(About_roll))
)


-----------------------------------------------------------------
-----------------------------------------------------------------
rollout common "Common Properties"
(
    checkbox save_check "Save File" offset:[5,0] across:2 checked:false enabled:false
    button browse "Files" enabled:true offset:[28,0]
    edittext path_text ""  enabled:false
    on common open do
    (
        scstate = save_check.state
        )
    on save_check changed state do
        (
            scstate = save_check.state
            if save_check.state == true then
            (
            browse.enabled = true
            path_text.enabled = true
            )
            else
            (
            browse.enabled = false
            path_text.enabled = false
			--save_path_QP = undefined
            )
        )
    on browse pressed do
        (
        save_path_QP = getBitmapSaveFileName ()
        if save_path_QP != undefined do 
			(
				save_check.enabled=true
				scstate=true
				save_check.checked=true
				path_text.enabled=true
				path_text.text = save_path_QP
			)
        )
	on path_text changed state do
	(
		save_path_QP = path_text.text
	)
)

rollout Quick_Passes "Quick Passes"
(
dotNetControl dn_tabs "System.Windows.Forms.TabControl" height:20 width:250 align:#center
subRollout theSubRollout width:250 height:220 align:#center
checkbox dontrecall "Do not retrieve current settings" tooltip:"When checked, after render original materials, lights and render settings wont retrieved"
dropdownlist override "Override Renderer" items:override_ddl_array
checkbox netR "Network Render" offset:[0,7]
button rendele "Render" width:70 height:40 offset:[80,-27]
	
on netR changed state do
(if_netrender=netR.state)
	
on dn_tabs Selected itm do

(
    if LastSubRollout != (itm.TabPageIndex+1) do --do not update if the same tab clicked twice
(
for subroll in Tabs_Rollouts[LastSubRollout][2] do
removeSubRollout theSubRollout subroll
for subroll in Tabs_Rollouts[LastSubRollout = itm.TabPageIndex+1][2] do
addSubRollout theSubRollout subroll
)

)--end tabs clicked

on override selected i do
	(
	overrideRENDERER=override.selection
	for subroll in Tabs_Rollouts[LastSubRollout][2] do
	removeSubRollout theSubRollout subroll
	for subroll in Tabs_Rollouts[LastSubRollout][2] do
	addSubRollout theSubRollout subroll
	)
-------------------------------------------
on Quick_Passes open do
	(
	if_netrender=netR.state
	overrideRENDERER=override.selection

	for aTab in Tabs_Rollouts do
		(
		dn_tabs.TabPages.add aTab[1]
		)
	for subroll in Tabs_Rollouts[1][2] do
	(
	addsubrollout theSubRollout common
	addSubRollout theSubRollout subroll  
)

)

on rendele pressed do
(
if classof renderers.current != mental_ray_renderer and classof renderers.current != classof vr and classof renderers.current != default_scanline_renderer and overrideRENDERER ==1  then

(messagebox "Current Renderer is not supported")

else
(

-- RESET ARRAYS
all_array=#()
all_mat_array=#()
all_matobj_array=#()
all_no_mat_array=#()
all_visobj_array=#()
all_visval_array=#()
all_no_vis_array=#()
lights_on_array=#()
lights_temporaryon_array=#()
lights_temporarycastshadows_array=#()
vray_sun_array=#()
primvis_off_array=#()
current_selection=#()
lights_temporaryonVray_array=#()
lights_temporaryinvisibleVray_array=#()
matte_wh=undefined
temp_material=undefined
temp_skylight=undefined

	get_sceneprops()
	get_materials()
	get_visibilities()
	get_lights()
	get_cameras()

(
	case dn_tabs.selectedindex of
	(
		0: if Matte_refmat==true then
	(reflmatte REF_blurchk REF_spread REF_sample REF_envmap override if_netrender )
		else
	(mattemat Matte_ifConMat Matte_ifConOt Matte_ifDisp override if_netrender)
		
		
		1: matAO AO_sample AO_spread AO_m_dist AO_falloff AO_ifBump AO_ifDisp AO_ifwired override if_netrender
		
		
		2: matref REF_blurchk REF_spread REF_sample REF_envmap override if_netrender 


		3: matsha SHA_opaque_Alpha SHA_Apply_Atmosphere SHA_ATMOSTATE override if_netrender
		
		
		4: (Messagebox "Ok ok.. I didnt remove render button from about screen, you had to test it didnt you?")
	)
	
	if dontrecall.checked == false then
		(
		
		recall_visibilities()
		recall_lights()	
		recall_materials()	
		recall_cameras()
		)

)	


)
)
------------------------------------------------
)
createdialog Quick_Passes 250 370 style:#(#style_titlebar,#style_border,#style_sysmenu,#style_minimizebox)
)

)--end of script 