Announcement

Collapse
No announcement yet.

About noise in general

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

  • Here's a quick script that'll give you a way to set reflection subdivs based on how glossy a material is, I'll also be trying to figure out a way to do this based on how bertrand is using his map slots (should be fine once his glossiness is always 1.0 and he's using the map to add his small amounts of glossy) as I bought his chicago loft scene and I want it to render quicker!

    Anyway, to the code!

    This is tested on a very simple scene in max 2012 on objects that have vray materials, and an object with a multi sub material containing vray materials. Hope it might be useful to someone!

    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

    Comment


    • Hi Joconnell, thanks for this post !
      Sounds interesting way, so i've improved a bit your material parsing algorithm with the latest i just rewrote for SolidRocks parsing(will be in V1 incoming build)
      note : Refractions subdivs are now also modified depending of Refraction glossiness value.

      Many thanks to Wilfried Peypoudat for helping in recursive methodology.
      This time your script can find and modify :
      - any VrayMaterial located into a deep material tree (VrayMat into a vrayblend into a multimat, for example).
      - VrayMaterials located into Vray2Sidedmaterials, Shellac, VrayBlendMAterial, VrayMaterialWrapper, and VrayOverrideMaterial.
      - VrayCarPaint material subdivs based on base_glossiness value, Vrayfastsss2 based on specular_glossiness value, FLAKESMTL based on flake_glossiness value.
      - VrayMaterials located into other standard max materials : Multi, Blend, composite, topbottom, and Shell, at any level of the material tree.

      Hope it helps !

      here's the modified script :
      Code:
      try(destroydialog SetVraySamples)catch()
      
      
      Function setVrayMatSubdivs ActualGlossy glossy_02 glossy_04 glossy_06 glossy_08 glossy_10 = (
      	
      	case of (
      					(ActualGlossy >= 0.0 and ActualGlossy < 0.2): ActualGlossys = glossy_02
      					(ActualGlossy >= 0.2 and ActualGlossy < 0.4): ActualGlossy = glossy_04
      					(ActualGlossy >= 0.4 and ActualGlossy < 0.6): ActualGlossy = glossy_06
      					(ActualGlossy >= 0.6 and ActualGlossy < 0.8): ActualGlossy = glossy_08
      					(ActualGlossy >= 0.8 and ActualGlossy <= 1.0): ActualGlossy = 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
      	
      	Function ProcessMaterial m =
      	(
      		if (classof m) == VRayMtl then 
      		(
      			m.reflection_subdivs = setVrayMatSubdivs m.reflection_glossiness 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
      			m.refraction_subdivs = setVrayMatSubdivs m.refraction_glossiness 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
      		)
      		-- ============================ VRay2SidedMtl =============================================
      		else if (classof m) == VRay2SidedMtl then
      		(
      			ProcessMaterial m.frontmtl
      			ProcessMaterial m.backmtl
      		)
      		-- ============================ SHELLAC =============================================
      		else if (classof m) == SHELLAC then
      		(
      			ProcessMaterial m.shellacMtl1
      			ProcessMaterial m.shellacMtl2
      		)
      		-- ============================ VRayBlendMtl =============================================
      		else if (classof m) == VRayBlendMtl then
      		(
      			ProcessMaterial m.baseMtl
      			for i = 1 to 9 do ProcessMaterial m.coatMtl[i]
      		)
      		-- ============================ VrayMtlWrapper =============================================
      		else if  (classof m) == VrayMtlWrapper then ProcessMaterial  m.baseMtl
      		
      		-- ============================ VrayOverrideMtl =============================================
      		else if  (classof m) == VrayOverrideMtl then
      		(
      			ProcessMaterial  m.baseMtl
      			ProcessMaterial  m.GIMtl
      			ProcessMaterial  m.reflectmtl
      			ProcessMaterial  m.refractmtl
      			ProcessMaterial  m.shadowmtl
      		)
      		-- ============================= Vray CArPaint =====================================================
      		else if  (classof m) == Vraycarpaintmtl then
      		(
      			m.subdivs = setVrayMatSubdivs m.base_glossiness 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
      		)
      		-- ============================= Vray FAST SSS2 =====================================================
      		else if  (classof m) == Vrayfastsss2 then
      		(
      			m.specular_subdivs = setVrayMatSubdivs m.specular_glossiness 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
      			
      		)
      		-- ============================= Vray FLAKESMTL =====================================================
      		else if  (classof m) == VrayFlakesmtl then
      		(
      			m.subdivs = setVrayMatSubdivs m.flake_glossiness 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
      		)
      		-- ======================================================================================
      		-- ============================ MULTIMAT =============================================
      		-- ======================================================================================
      		else if (classof m) == Multimaterial then for i = 1 to m.count do ProcessMaterial m[i]
      		
      		-- ============================= blend (fusion) =====================================================
      		else if (classof m) == blend then
      		(
      			ProcessMaterial  m.MAP1
      			ProcessMaterial  m.MAP2
      		)
      		-- ============================= composite =====================================================
      		else if (classof m) == compositematerial then
      		(
      			ProcessMaterial m.baseMaterial
      			for i = 1 to m.materiallist.count do ProcessMaterial m.materiallist[i]
      		)
      		-- ============================= top-bottom =====================================================
      		else if (classof m) == topbottom then
      		(
      			ProcessMaterial  m.topmaterial
      			ProcessMaterial  m.bottomMaterial
      		)
      		-- ============================= SHELL (coque) =====================================================
      		else if (classof m) == shell_material then
      		(
      			ProcessMaterial  m.originalMaterial
      			ProcessMaterial  m.bakedMaterial
      		)
      	)
      	
      	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 with undo off ProcessMaterial m
      	)
      
      )
      
      CreateDialog SetVraySamples width: 400
      Jérôme Prévost.
      SolidRocks, the V-Ray Wizard.
      http://solidrocks.subburb.com

      Comment


      • Hi Jérôme,

        I'm trying your script, seems to works fine as a standalone script but trying it as macro it returns a compile error, any idea?
        I would like to suggest a forth button to reset to default values without exiting the ui and also a way to remember user setting (I've no idea if that could be done easly or not)

        thanks for sharing
        Alessandro

        Comment


        • Hi Alessandro,

          Paste the text into a new maxscript window, then select all the code and drag and drop it to a tool bar, should work then! I'm looking into remembering settings and a few other things

          Jérôme that's a lovely solution to the problem of nested maps! I'll add a few more bits to this in terms of methods and we'll see where we're at then!

          Comment


          • Originally posted by joconnell View Post
            Paste the text into a new maxscript window, then select all the code and drag and drop it to a tool bar, should work then!
            hi joconnell, thanks for your suggestion ...I've already tried as you said but it returned the compile error; maybe I've done something wrong; toworrow I'll try again, right now I'm away from my 3dsmax

            UPD1
            no way, here is the error returned trying to drag and drop the code from maxscript window to toolbar
            Attached Files
            Last edited by zeronove; 04-05-2012, 09:54 AM.
            Alessandro

            Comment


            • Same error here.
              www.francescolegrenzi.com

              VRay - THE COMPLETE GUIDE - The book
              Corona - THE COMPLETE GUIDE - The book


              --- FACEBOOK ---

              Comment


              • I got same error. Fixed by running the script once, and then using the paste/drag/drop...HTH
                Thanks for the script joconnell and Jérôme!

                edit: Not quite fixed; I installed the button fine and it worked. The next day after a max restart, it does not, but I can still run the script manually.
                Last edited by voltron7; 07-05-2012, 03:52 AM.

                Comment


                • Hi, i've solved the bug. One control had the same name than the rollout itself. It' ok now, you can drag the code into a max toolbar.

                  here's the code :
                  Code:
                  try(destroydialog SetVraySamples)catch()
                  
                  
                  Function setVrayMatSubdivs ActualGlossy glossy_02 glossy_04 glossy_06 glossy_08 glossy_10 = (
                  	
                  	case of (
                  					(ActualGlossy >= 0.0 and ActualGlossy < 0.2): ActualGlossys = glossy_02
                  					(ActualGlossy >= 0.2 and ActualGlossy < 0.4): ActualGlossy = glossy_04
                  					(ActualGlossy >= 0.4 and ActualGlossy < 0.6): ActualGlossy = glossy_06
                  					(ActualGlossy >= 0.6 and ActualGlossy < 0.8): ActualGlossy = glossy_08
                  					(ActualGlossy >= 0.8 and ActualGlossy <= 1.0): ActualGlossy = glossy_10
                  					)	
                  )
                  
                  rollout RollSetVraySamples "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
                  	
                  	Function ProcessMaterial m =
                  	(
                  		if (classof m) == VRayMtl then 
                  		(
                  			m.reflection_subdivs = setVrayMatSubdivs m.reflection_glossiness 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
                  			m.refraction_subdivs = setVrayMatSubdivs m.refraction_glossiness 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
                  		)
                  		-- ============================ VRay2SidedMtl =============================================
                  		else if (classof m) == VRay2SidedMtl then
                  		(
                  			ProcessMaterial m.frontmtl
                  			ProcessMaterial m.backmtl
                  		)
                  		-- ============================ SHELLAC =============================================
                  		else if (classof m) == SHELLAC then
                  		(
                  			ProcessMaterial m.shellacMtl1
                  			ProcessMaterial m.shellacMtl2
                  		)
                  		-- ============================ VRayBlendMtl =============================================
                  		else if (classof m) == VRayBlendMtl then
                  		(
                  			ProcessMaterial m.baseMtl
                  			for i = 1 to 9 do ProcessMaterial m.coatMtl[i]
                  		)
                  		-- ============================ VrayMtlWrapper =============================================
                  		else if  (classof m) == VrayMtlWrapper then ProcessMaterial  m.baseMtl
                  		
                  		-- ============================ VrayOverrideMtl =============================================
                  		else if  (classof m) == VrayOverrideMtl then
                  		(
                  			ProcessMaterial  m.baseMtl
                  			ProcessMaterial  m.GIMtl
                  			ProcessMaterial  m.reflectmtl
                  			ProcessMaterial  m.refractmtl
                  			ProcessMaterial  m.shadowmtl
                  		)
                  		-- ============================= Vray CArPaint =====================================================
                  		else if  (classof m) == Vraycarpaintmtl then
                  		(
                  			m.subdivs = setVrayMatSubdivs m.base_glossiness 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
                  		)
                  		-- ============================= Vray FAST SSS2 =====================================================
                  		else if  (classof m) == Vrayfastsss2 then
                  		(
                  			m.specular_subdivs = setVrayMatSubdivs m.specular_glossiness 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
                  			
                  		)
                  		-- ============================= Vray FLAKESMTL =====================================================
                  		else if  (classof m) == VrayFlakesmtl then
                  		(
                  			m.subdivs = setVrayMatSubdivs m.flake_glossiness 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
                  		)
                  		-- ======================================================================================
                  		-- ============================ MULTIMAT =============================================
                  		-- ======================================================================================
                  		else if (classof m) == Multimaterial then for i = 1 to m.count do ProcessMaterial m[i]
                  		
                  		-- ============================= blend (fusion) =====================================================
                  		else if (classof m) == blend then
                  		(
                  			ProcessMaterial  m.MAP1
                  			ProcessMaterial  m.MAP2
                  		)
                  		-- ============================= composite =====================================================
                  		else if (classof m) == compositematerial then
                  		(
                  			ProcessMaterial m.baseMaterial
                  			for i = 1 to m.materiallist.count do ProcessMaterial m.materiallist[i]
                  		)
                  		-- ============================= top-bottom =====================================================
                  		else if (classof m) == topbottom then
                  		(
                  			ProcessMaterial  m.topmaterial
                  			ProcessMaterial  m.bottomMaterial
                  		)
                  		-- ============================= SHELL (coque) =====================================================
                  		else if (classof m) == shell_material then
                  		(
                  			ProcessMaterial  m.originalMaterial
                  			ProcessMaterial  m.bakedMaterial
                  		)
                  	)
                  	
                  	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 with undo off ProcessMaterial m
                  	)
                  
                  )
                  
                  CreateDialog RollSetVraySamples width: 400
                  Jérôme Prévost.
                  SolidRocks, the V-Ray Wizard.
                  http://solidrocks.subburb.com

                  Comment


                  • Thank you
                    www.francescolegrenzi.com

                    VRay - THE COMPLETE GUIDE - The book
                    Corona - THE COMPLETE GUIDE - The book


                    --- FACEBOOK ---

                    Comment


                    • I'm having a request for guys wich are at ease with maths... :

                      I'm trying to simplify this tool, allowing the user to enter only 2 values : subdivs for gloss 0.0 and subdivs for gloss 1.0.
                      All the other values will be computed by the script, in different manners.

                      for example, the user entered 8 subdivs for gloss=1.0 and 64 subdivs for gloss = 0.0
                      In linear method, that's quite easy : ((max - min)+1) * glossyvalue or something like that.
                      in this case, glossy with 0.5 value will have ((64 - 8 ) + 1) * 0.5 = 28 subdivs.

                      but it would be nice to have also other methods, like log, expo, power, etc.. to compute the intermediate values...
                      Someone have an interesting formula here ?
                      Jérôme Prévost.
                      SolidRocks, the V-Ray Wizard.
                      http://solidrocks.subburb.com

                      Comment


                      • Ha ha ha Jerome, I thought of the exact same thing as you can't add enough spinners for accuracy - I was thinking of getting it to do it based on the minimum gloss value in the scene rather than 0.0 to 1.0 but you're quite right - if you change your materials and add more outside of the range I was thinking of and run the tool again it'll change your values.

                        Great minds

                        Comment


                        • I work with SR and if you chose the interior (or exterior) preset without retrace everything works fine without noise. I think the noise is coming from retrace option.
                          the script is great, but I am working with fallof maps for glossies a lot and then no script is taking this into account, I mean the subdivs will not be optimized. is there a way to evaluate the glossy amount from a falloff map? I now I can set the glossy value to something like 0.7 for all materials with a falloff map in the refl.glossy to get a optimized glossy value... (maybe somebody can make a little script to convert all values with a map to a glossy value below one)

                          thanks.

                          best regards
                          themaxxer
                          Pixelschmiede GmbH
                          www.pixelschmiede.ch

                          Comment


                          • Thanks Jérôme,

                            I would like to suggest adding options to target the whole operation:

                            - all scene materials
                            - selected objects only
                            - all material editor slots
                            - active slot only
                            Alessandro

                            Comment


                            • Maxxer since falloff is view dependant and calculated at render time it's not possible at present, Chaos would have to implement a map channel for subdivs too :/

                              Comment


                              • apologies if this has already been raised.. there are several extremely long threads on this subject, but... since the subdivs represent only the -maximum- number of samples vray can use on a given effect to achieve the given noise threshold, in theory there should be no advantage to setting different subdivs based on glossyness.

                                since, if i understand correctly, even if you set all of the materials to 256 subdivs, the less glossy ones will naturally use less samples since it will take less to achieve a clean result, i.e. reach the noise threshold.

                                in fact, taken to its logical conclusion, why isnt the noise threshold the only important setting? i.e. why not set -all- scene subdivs to 1000 and let the noise threshold and adaptive sampling simply stop adding samples when necessary...? in theory this will add no more sampling than setting them all to different, but sufficiently high values.

                                i know this isnt the case, but why?

                                Comment

                                Working...
                                X