Announcement

Collapse
No announcement yet.

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

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

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

    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.

    Code:
    /*
    
    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

  • #2
    Great idea, thanks!
    Shop | Work | Blog

    Comment


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

      for m in getClassInstances VRayMtl do (

      )

      Comment


      • #4
        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:
        Code:
        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 it will find ALL VRay materials whether they are hidden inside VRayOverride, VRayBlend etc.
        Dan Brew

        Comment


        • #5
          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!

          Comment


          • #6
            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!
            Martin
            http://www.pixelbox.cz

            Comment


            • #7
              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.

              Comment


              • #8
                Would be great to have an updated version

                Comment


                • #9
                  Originally posted by AlexP View Post
                  Would be great to have an updated version
                  What Alex wrote +1

                  Comment


                  • #10
                    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.
                    Colin Senner

                    Comment


                    • #11
                      Originally posted by MoonDoggie View Post
                      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.

                      Comment


                      • #12
                        Originally posted by MoonDoggie View Post
                        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
                        I only act like I know everything, Rogers.

                        Comment


                        • #13
                          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?
                          Colin Senner

                          Comment


                          • #14
                            When you brainiacs figure it out, let us know
                            Bobby Parker
                            www.bobby-parker.com
                            e-mail: info@bobby-parker.com
                            phone: 2188206812

                            My current hardware setup:
                            • Ryzen 9 5900x CPU
                            • 128gb Vengeance RGB Pro RAM
                            • NVIDIA GeForce RTX 4090
                            • ​Windows 11 Pro

                            Comment


                            • #15
                              Originally posted by MoonDoggie View Post
                              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).
                              Last edited by Neilg; 07-04-2014, 10:25 AM.

                              Comment

                              Working...
                              X