# Small script to quickly change vray material reflection subdivs based on glossiness

**URL:** <https://forums.chaos.com/t/small-script-to-quickly-change-vray-material-reflection-subdivs-based-on-glossiness/41242>\
**Category:** General\
**Created:** [May 1, 2012, 3:17pm UTC](https://forums.chaos.com/t/small-script-to-quickly-change-vray-material-reflection-subdivs-based-on-glossiness/41242 "2012-05-01T15:17:50Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![joconnell](https://dub1.discourse-cdn.com/chaosprd/user_avatar/forums.chaos.com/joconnell/32/36063_2.png) [@joconnell](https://forums.chaos.com/u/joconnell)\
**Post date:** [May 1, 2012, 3:17pm UTC](https://forums.chaos.com/t/small-script-to-quickly-change-vray-material-reflection-subdivs-based-on-glossiness/41242/1 "2012-05-01T15:17:50Z")

</div>

Heya folks,

Based on the discussions we’ve been having about the universal settings and what not, here’s a little utility that’ll allow you to mass change your entire scene’s refection subdivs based on how glossy you have them set. It’s only working on vray material reflections, and vray mats in multi sub reflections for now, and it’s also perhaps a little blunt in that it’s using 5 set ranges of glossiness (0.0 - 0.2, 0.2 - 0.4, 0.4 - 0.6, 0.6 - 0.8, 0.8 - 1.0) but hopefully it’ll be useful for someone!

The idea is also to change it to give options to work with Bertrand Benoit’s setup, as I bought his chicago loft scene and with a lot of carefully tweaked materials, it’d be very time consuming to try and apply the new high subdiv method that we’re currently looking at on the forum. I was trying to think of a method that’d work for lights, but since they can vary in size so much I’ll have to figure out a better way to divide them into ranges of size to drive subdiv values with. Maybe it’s not needed? Maybe refraction wold be more useful next?

Either way copy and paste this to your maxscript editor, select it all and drag it to a tool bar. It’s provided as is and hopefully uses such simple code that it won’t do any damage to a scene, but as ever it’s worth keeping a copy of a scene in case you want to get your old values back.

```auto
/*

Script to give a global control to set all material subdivs based on how glossy the material's reflections are. 
No respnsibility taken for any errors this script may cause.
Written badly by John O'Connell - http://www.joconnell.com
Stick thoughts or comments on the vray forums if you have ideas on features!

*/

try(destroydialog SetVraySamples)catch()

Function setVrayMatSubdivs TheMat glossy_02 glossy_04 glossy_06 glossy_08 glossy_10 =
(
	case of (
					(TheMat.reflection_glossiness >= 0.0 and TheMat.reflection_glossiness < 0.2): TheMat.reflection_subdivs = glossy_02
					(TheMat.reflection_glossiness >= 0.2 and TheMat.reflection_glossiness < 0.4): TheMat.reflection_subdivs = glossy_04
					(TheMat.reflection_glossiness >= 0.4 and TheMat.reflection_glossiness < 0.6): TheMat.reflection_subdivs = glossy_06
					(TheMat.reflection_glossiness >= 0.6 and TheMat.reflection_glossiness < 0.8): TheMat.reflection_subdivs = glossy_08
					(TheMat.reflection_glossiness >= 0.8 and TheMat.reflection_glossiness < 1.0): TheMat.reflection_subdivs = glossy_10
					)	
)

rollout SetVraySamples "Set VrayMat Samples"
(	
	Group "Material sample amounts" 
	(
		spinner glossy_00_to_02 "Glossiness 0.0 to 0.2" range:[00,5000,100] align:#right type:#integer
		spinner glossy_02_to_04 "Glossiness 0.2 to 0.4" range:[00,5000,80] align:#right type:#integer
		spinner glossy_04_to_06 "Glossiness 0.4 to 0.6" range:[00,5000,60] align:#right type:#integer
		spinner glossy_06_to_08 "Glossiness 0.6 to 0.8" range:[00,5000,40] align:#right type:#integer
		spinner glossy_08_to_10 "Glossiness 0.8 to 1.0" range:[00,5000,20] align:#right type:#integer

		button DoubleVraySamples "Double samples" width:180 align:#left
		button HalfVraySamples "Half samples" width:180 align:#right offset:[0,-26]
	)

	button SetVraySamples "Set Sample amounts" width:200 align:#right

	on DoubleVraySamples pressed do
	(
		glossy_00_to_02.value = glossy_00_to_02.value*2
		glossy_02_to_04.value = glossy_02_to_04.value*2
		glossy_04_to_06.value = glossy_04_to_06.value*2
		glossy_06_to_08.value = glossy_06_to_08.value*2
		glossy_08_to_10.value = glossy_08_to_10.value*2
	)

		on HalfVraySamples pressed do
	(
		glossy_00_to_02.value = glossy_00_to_02.value*0.5
		glossy_02_to_04.value = glossy_02_to_04.value*0.5
		glossy_04_to_06.value = glossy_04_to_06.value*0.5
		glossy_06_to_08.value = glossy_06_to_08.value*0.5
		glossy_08_to_10.value = glossy_08_to_10.value*0.5
	)

	on SetVraySamples pressed do
	(
		for m in scenematerials do
		(
			print m.name

			print (classof m as string)

			if (classof m == VrayMtl) then
			(
				setVrayMatSubdivs m glossy_00_to_02.value glossy_02_to_04.value glossy_04_to_06.value	glossy_06_to_08.value glossy_08_to_10.value
			) 

			-- Stupid messy bit to find multi sub mats

			theMultiMats = for o in objects where ((classof o.material) == MultiMaterial) collect o

			for obj in theMultiMats do
			(				
				for n = 1 to obj.material.numsubs do
				(
					if (classof obj.material[n] == VrayMtl) then
					(
						setVrayMatSubdivs obj.material[n] glossy_00_to_02.value glossy_02_to_04.value glossy_04_to_06.value glossy_06_to_08.value glossy_08_to_10.value
					)
				)
			)

		)
	)

)

CreateDialog SetVraySamples width: 400

```

---

<div class="post-metadata">

**Author:** ![dorham](https://dub1.discourse-cdn.com/chaosprd/user_avatar/forums.chaos.com/dorham/32/60015_2.png) [@dorham](https://forums.chaos.com/u/dorham)\
**Post date:** [May 1, 2012, 3:39pm UTC](https://forums.chaos.com/t/small-script-to-quickly-change-vray-material-reflection-subdivs-based-on-glossiness/41242/2 "2012-05-01T15:39:27Z")

</div>

Great idea, thanks!

---

<div class="post-metadata">

**Author:** ![tiw](https://avatars.discourse-cdn.com/v4/letter/t/ea5d25/32.png) [@tiw](https://forums.chaos.com/u/tiw)\
**Post date:** [May 1, 2012, 8:08pm UTC](https://forums.chaos.com/t/small-script-to-quickly-change-vray-material-reflection-subdivs-based-on-glossiness/41242/3 "2012-05-01T20:08:01Z")

</div>

You can step through every VRayMtl by doing something like this:

for m in getClassInstances VRayMtl do (

)

---

<div class="post-metadata">

**Author:** ![DanielBrew](https://dub1.discourse-cdn.com/chaosprd/user_avatar/forums.chaos.com/danielbrew/32/22952_2.png) [@DanielBrew](https://forums.chaos.com/u/DanielBrew)\
**Post date:** [May 2, 2012, 12:04pm UTC](https://forums.chaos.com/t/small-script-to-quickly-change-vray-material-reflection-subdivs-based-on-glossiness/41242/4 "2012-05-02T12:04:07Z")

</div>

I’ve just been playing with this on a scene I am working on and have to agree, it is a great idea. I’ve been using VRay for years but still just guess at what reflection/refraction subdivs would be required largely based on the glossiness but also finding very dark materials also require higher settings. Probably because of the greater contract between the diffuse and reflection.

tiw’s suggestion is a good one though, your “on SetVraySamples pressed do” code could be simplified to:```  
on SetVraySamples pressed do  
(  
vrmArr = getClassInstances vrayMtl

```
for m in vrmArr do
(
	setVrayMatSubdivs m glossy_00_to_02.value glossy_02_to_04.value glossy_04_to_06.value	glossy_06_to_08.value glossy_08_to_10.value
)

```

)

```and

```

---

<div class="post-metadata">

**Author:** ![joconnell](https://dub1.discourse-cdn.com/chaosprd/user_avatar/forums.chaos.com/joconnell/32/36063_2.png) [@joconnell](https://forums.chaos.com/u/joconnell)\
**Post date:** [May 2, 2012, 4:51pm UTC](https://forums.chaos.com/t/small-script-to-quickly-change-vray-material-reflection-subdivs-based-on-glossiness/41242/5 "2012-05-02T16:51:09Z")

</div>

Elegant! I think I might have a better approach to doing this too rather than all the spinners so I’ll do up another version soon!

Cheers for both of the revisions folks, I use MXS so infrequently it’s nice to get reminders from folks that have far more refined technique!

---

<div class="post-metadata">

**Author:** ![PIXELBOX\_SRO](https://avatars.discourse-cdn.com/v4/letter/p/97f17d/32.png) [@PIXELBOX\_SRO](https://forums.chaos.com/u/PIXELBOX_SRO)\
**Post date:** [April 7, 2014, 9:38am UTC](https://forums.chaos.com/t/small-script-to-quickly-change-vray-material-reflection-subdivs-based-on-glossiness/41242/6 "2014-04-07T09:38:33Z")

</div>

as much as i am trying to get this run, i am getting an error trying to drag it to a toolbar.  
i get an error saying:  
Compile Error:control alrady defined: SetVraySamples  
In line: button SetVraySamples

no clue what this means :)))  
Could you please John shed some light into this whats going on?  
Big thanks!

---

<div class="post-metadata">

**Author:** ![joconnell](https://dub1.discourse-cdn.com/chaosprd/user_avatar/forums.chaos.com/joconnell/32/36063_2.png) [@joconnell](https://forums.chaos.com/u/joconnell)\
**Post date:** [April 7, 2014, 11:49am UTC](https://forums.chaos.com/t/small-script-to-quickly-change-vray-material-reflection-subdivs-based-on-glossiness/41242/7 "2014-04-07T11:49:56Z")

</div>

Hmm, I’m in maya land at the minute but I’ll stick it in the todo list. There’s a version of the script with tweaks for things like the FastSSS2 material and carpaint material being included, time for an update I reckon.

---

<div class="post-metadata">

**Author:** ![AlexP](https://avatars.discourse-cdn.com/v4/letter/a/e9a140/32.png) [@AlexP](https://forums.chaos.com/u/AlexP)\
**Post date:** [April 7, 2014, 11:57am UTC](https://forums.chaos.com/t/small-script-to-quickly-change-vray-material-reflection-subdivs-based-on-glossiness/41242/8 "2014-04-07T11:57:12Z")

</div>

Would be great to have an updated version

---

<div class="post-metadata">

**Author:** ![voltron7](https://dub1.discourse-cdn.com/chaosprd/user_avatar/forums.chaos.com/voltron7/32/39008_2.png) [@voltron7](https://forums.chaos.com/u/voltron7)\
**Post date:** [April 7, 2014, 3:35pm UTC](https://forums.chaos.com/t/small-script-to-quickly-change-vray-material-reflection-subdivs-based-on-glossiness/41242/9 "2014-04-07T15:35:57Z")

</div>

> [@AlexP](#):
>
> Would be great to have an updated version

What Alex wrote 🙂 +1

---

<div class="post-metadata">

**Author:** ![MoonDoggie](https://dub1.discourse-cdn.com/chaosprd/user_avatar/forums.chaos.com/moondoggie/32/68517_2.png) [@MoonDoggie](https://forums.chaos.com/u/MoonDoggie)\
**Post date:** [April 7, 2014, 4:29pm UTC](https://forums.chaos.com/t/small-script-to-quickly-change-vray-material-reflection-subdivs-based-on-glossiness/41242/10 "2014-04-07T16:29:34Z")

</div>

I also suggest automatically having a checkbox to let the user change the Max Depth as well.

It should ideally calculate how reflective a surface is (making sure to account for a gamma’d workflow) and adjusting the max depth based on some criteria within.

---

<div class="post-metadata">

**Author:** ![Neilg](https://dub1.discourse-cdn.com/chaosprd/user_avatar/forums.chaos.com/neilg/32/7044_2.png) [@Neilg](https://forums.chaos.com/u/Neilg)\
**Post date:** [April 7, 2014, 4:57pm UTC](https://forums.chaos.com/t/small-script-to-quickly-change-vray-material-reflection-subdivs-based-on-glossiness/41242/11 "2014-04-07T16:57:53Z")

</div>

> [@MoonDoggie](#):
>
> I also suggest automatically having a checkbox to let the user change the Max Depth as well.
> 
> It should ideally calculate how reflective a surface is (making sure to account for a gamma’d workflow) and adjusting the max depth based on some criteria within.

i’d use this. probably better to go based of glossiness though - calculating how reflective a surface is would be difficult when you add maps and if something is just barely reflective but the glossiness is set to 1, you’re going to notice it only doing one bounce.

---

<div class="post-metadata">

**Author:** ![vlado](https://avatars.discourse-cdn.com/v4/letter/v/779978/32.png) [@vlado](https://forums.chaos.com/u/vlado)\
**Post date:** [April 7, 2014, 5:10pm UTC](https://forums.chaos.com/t/small-script-to-quickly-change-vray-material-reflection-subdivs-based-on-glossiness/41242/12 "2014-04-07T17:10:23Z")

</div>

> [@MoonDoggie](#):
>
> It should ideally calculate how reflective a surface is (making sure to account for a gamma’d workflow) and adjusting the max depth based on some criteria within.

Nononono don’t do that; V-Ray does that automatically and it’s a bit smarter than what you can do about it. Glossiness is the only thing that we don’t currently take into account.

Best regards,  
Vlado

---

<div class="post-metadata">

**Author:** ![MoonDoggie](https://dub1.discourse-cdn.com/chaosprd/user_avatar/forums.chaos.com/moondoggie/32/68517_2.png) [@MoonDoggie](https://forums.chaos.com/u/MoonDoggie)\
**Post date:** [April 7, 2014, 5:12pm UTC](https://forums.chaos.com/t/small-script-to-quickly-change-vray-material-reflection-subdivs-based-on-glossiness/41242/13 "2014-04-07T17:12:29Z")

</div>

Good to know? We’ve all on the forums recently seen much improved render times based on lowering the max depth for all of our materials.

Personally, I was seeing 3hr 30m render times with my scene and lowering all materials reflection max depth to 1 and adjusting my metals and very glossy materials to 2 gave me now 1hr 10m render times. What should we do for this?

---

<div class="post-metadata">

**Author:** ![glorybound](https://dub1.discourse-cdn.com/chaosprd/user_avatar/forums.chaos.com/glorybound/32/53992_2.png) [@glorybound](https://forums.chaos.com/u/glorybound)\
**Post date:** [April 7, 2014, 5:20pm UTC](https://forums.chaos.com/t/small-script-to-quickly-change-vray-material-reflection-subdivs-based-on-glossiness/41242/14 "2014-04-07T17:20:41Z")

</div>

When you brainiacs figure it out, let us know 🙂

---

<div class="post-metadata">

**Author:** ![Neilg](https://dub1.discourse-cdn.com/chaosprd/user_avatar/forums.chaos.com/neilg/32/7044_2.png) [@Neilg](https://forums.chaos.com/u/Neilg)\
**Post date:** [April 7, 2014, 5:22pm UTC](https://forums.chaos.com/t/small-script-to-quickly-change-vray-material-reflection-subdivs-based-on-glossiness/41242/15 "2014-04-07T17:22:22Z")

</div>

> [@MoonDoggie](#):
>
> Personally, I was seeing 3hr 30m render times with my scene and lowering all materials reflection max depth to 1 and adjusting my metals and very glossy materials to 2 gave me now 1hr 10m render times. What should we do for this?

Do it based on glossiness - just not reflection amount. vray already stops the reflections being traced when it decides that there’s not enough reflection - it just doesn’t take into account the reflection being so blurry you cant tell either way.

It’s an easier script to write and the ones in this thread could be modified to do it easily. i’ll have a go when i get time later if nobody else does it (i am bad, but could probably figure this out - the hard works been done already).

---

<div class="post-metadata">

**Author:** ![MoonDoggie](https://dub1.discourse-cdn.com/chaosprd/user_avatar/forums.chaos.com/moondoggie/32/68517_2.png) [@MoonDoggie](https://forums.chaos.com/u/MoonDoggie)\
**Post date:** [April 7, 2014, 5:42pm UTC](https://forums.chaos.com/t/small-script-to-quickly-change-vray-material-reflection-subdivs-based-on-glossiness/41242/16 "2014-04-07T17:42:13Z")

</div>

Yeah I’ve been using one similar for a while and it’s helped a ton. Thanks for the info Cubicle.

---

<div class="post-metadata">

**Author:** ![leo.surrealismo](https://dub1.discourse-cdn.com/chaosprd/user_avatar/forums.chaos.com/leo.surrealismo/32/26139_2.png) [@leo.surrealismo](https://forums.chaos.com/u/leo.surrealismo)\
**Post date:** [April 7, 2014, 6:11pm UTC](https://forums.chaos.com/t/small-script-to-quickly-change-vray-material-reflection-subdivs-based-on-glossiness/41242/17 "2014-04-07T18:11:55Z")

</div>

( Crtrl + E ) o (evaluate all) before dragging to a toolbar

---

<div class="post-metadata">

**Author:** ![Morne](https://dub1.discourse-cdn.com/chaosprd/user_avatar/forums.chaos.com/morne/32/11335_2.png) [@Morne](https://forums.chaos.com/u/Morne)\
**Post date:** [April 8, 2014, 8:27am UTC](https://forums.chaos.com/t/small-script-to-quickly-change-vray-material-reflection-subdivs-based-on-glossiness/41242/18 "2014-04-08T08:27:06Z")

</div>

The max depth creates havoc for the type of scenes we work on nowdays  
If we lower it, the render does go quicker but it looks real bad

We have a ton of glass and metal overlapping like balustrades, lift shafts etc

---

<div class="post-metadata">

**Author:** ![joconnell](https://dub1.discourse-cdn.com/chaosprd/user_avatar/forums.chaos.com/joconnell/32/36063_2.png) [@joconnell](https://forums.chaos.com/u/joconnell)\
**Post date:** [April 8, 2014, 11:08am UTC](https://forums.chaos.com/t/small-script-to-quickly-change-vray-material-reflection-subdivs-based-on-glossiness/41242/19 "2014-04-08T11:08:10Z")

</div>

Yeah that’s what I do - I’ve a second script that does max depth based on glossiness - if you’ve something really soft you won’t get much difference beyond the first bounce save for a little bit of brightness.

---

<div class="post-metadata">

**Author:** ![Neilg](https://dub1.discourse-cdn.com/chaosprd/user_avatar/forums.chaos.com/neilg/32/7044_2.png) [@Neilg](https://forums.chaos.com/u/Neilg)\
**Post date:** [April 8, 2014, 2:41pm UTC](https://forums.chaos.com/t/small-script-to-quickly-change-vray-material-reflection-subdivs-based-on-glossiness/41242/20 "2014-04-08T14:41:16Z")

</div>

> [@Morne](#):
>
> We have a ton of glass and metal overlapping like balustrades, lift shafts etc

Render with the glass off and drop it in as a separate pass. your render times will speed up a shitload more doing this too.

[Next page](https://forums.chaos.com/t/small-script-to-quickly-change-vray-material-reflection-subdivs-based-on-glossiness/41242.md?page=2)
