{ ///////////////////////////////////////////////////////////////////// ///////// MENTAL RAY UTILITIES /// /// This is a simple script developed to simplify the creation of some Mental Ray Shaders. /// Save this as a .mel file in your default scripts directory. /// In the script editor, type mrUtils; and the window should pop up. /// You can select the command and middle-click + drag it to your shelf for easy access. scriptEditorInfo -ch; //////////////////////////////////////////////////// // FAST SIMPLE SSS SHADER //////////////////////////////////////////////////// global proc fastSimple(string $fsName) { setCurrentRenderer mentalRay; unifiedRenderGlobalsWindow; window -e -vis 0 unifiedRenderGlobalsWindow; select -cl; // Create the shader node mrCreateCustomNode -asShader "" misss_fast_simple_maya; rename $fsName; string $temp[] = `ls -sl`; string $shader = $temp[0]; string $SG = ($shader + "_SG"); setAttr ($shader + ".samples") 256; string $SGList[] = `lsType shadingEngine`; int $SGnum = (`size($SGList)` - 2); string $SG1 = ($SGList[$SGnum]); rename $SG1 $SG; print ("=====>>>>>The Shading Engine is " + $SG + "\n"); // Create the LightMap mentalrayTextureNodeCreate ( ($shader + ".lightmap") ); rename ($shader + "_lightMapTxNode"); string $temp[] =`ls -sl`; string $ltMapTx = $temp[0]; // Set the image name and location for the light map setAttr ($ltMapTx + ".miWritable") 1; setAttr ($ltMapTx + ".miWidth") 512; setAttr ($ltMapTx + ".miHeight") 512; setAttr ($ltMapTx + ".miDepth") 4; setAttr -type "string" ($ltMapTx + ".fileTextureName") ("C:\\" + $shader + "_Lightmap"); /* THIS IS ONLY OFF TO PREVENT FALSE HIGHLIGHTING IN CUTTER TURN ON TO RUN SCRIPT */ // Connect the light map to the shading engine mrCreateCustomNode -asUtility "" misss_fast_lmap_maya; rename ($shader + "_LightMap"); string $z[] =`ls -sl`; string $ltMap = $z[0]; select -r $ltMap; connectAttr -f ($ltMap + ".message") ($SG + ".miLightMapShader"); // Connect the MI Shader to the LightMap select -r $ltMap ; connectAttr -f ($ltMapTx + ".message") ($ltMap + ".lightmap"); select -r $shader; } //_______________________________________________ //////////////////////////////////////////////////// // MISS_PHYSICAL SHADER //////////////////////////////////////////////////// global proc createPhysical(string $pName) { setCurrentRenderer mentalRay; unifiedRenderGlobalsWindow; window -e -vis 0 unifiedRenderGlobalsWindow; if (`objExists miDefaultOptions`) { print "exists\n"; } else { print"nothing\n"; } setAttr "miDefaultOptions.caustics" 1; select -cl; mrCreateCustomNode -asShader "" misss_physical; rename $pName; string $temp[] =`ls -sl`; string $shader = $temp[0]; string $SG = ($shader + "_SG"); setAttr ($shader + ".transmission") -type double3 0.258 0.5 0.274 ; setAttr ($shader + ".ior") 1.3; setAttr ($shader + ".absorption_coeffX") 0.00053; setAttr ($shader + ".absorption_coeffY") 0.00123; setAttr ($shader + ".absorption_coeffZ") 0.00213; setAttr ($shader + ".scattering_coeffX") 0.657; setAttr ($shader + ".scattering_coeffY") 0.786; setAttr ($shader + ".scattering_coeffZ") 0.9; setAttr ($shader + ".scale_conversion") 10; setAttr ($shader + ".scattering_anisotropy") 0.75; setAttr ($shader + ".depth") 10; setAttr ($shader + ".max_samples") 10; setAttr ($shader + ".max_photons") 2000; setAttr ($shader + ".max_radius") 20; string $SGList[] = `lsType shadingEngine`; int $SGnum = (`size($SGList)` - 2); string $SG1 = ($SGList[$SGnum]); rename $SG1 $SG; // Connect miss_physical to the Photon Shader connectAttr -f ($shader + ".outValue") ($SG + ".miPhotonShader"); } //_______________________________________________ global proc shaderMod( float $sX, float $sY, float $sZ, float $aX, float $aY, float $aZ, float $ior, float $transR, float $transG, float $transB, float $matR, float $matG, float $matB) { string $temp[] = `ls -sl`; string $shader = $temp[0]; setAttr ($shader + ".scattering_coeffX") $sX; setAttr ($shader + ".scattering_coeffY") $sY; setAttr ($shader + ".scattering_coeffZ") $sZ; setAttr ($shader + ".absorption_coeffX") $aX; setAttr ($shader + ".absorption_coeffY") $aY; setAttr ($shader + ".absorption_coeffZ") $aZ; setAttr ($shader + ".ior") $ior; setAttr ($shader + ".transmission") -type double3 $transR $transG $transB; setAttr ($shader + ".material") -type double3 $matR $matG $matB; } //_______________________________________________ //////////////////////////////////////////////////// // MENTAL RAY BUMP MAP //////////////////////////////////////////////////// global proc mrBump(string $bName) { setCurrentRenderer mentalRay; unifiedRenderGlobalsWindow; window -e -vis 0 unifiedRenderGlobalsWindow; select -cl; mrCreateCustomNode -asShader "" dgs_material; rename $bName; string $temp[] =`ls -sl`; string $shader = $temp[0]; // Set names for everything string $SG = ($shader + "_SG"); string $bmpPassThrough = ($shader + "_bmpPassThrough"); string $bmpBasis = ($shader + "_bmpBasis"); string $bmpTxtrVector = ($shader + "_bmpTxtrVector"); string $bmpTxtrRemap = ($shader + "_bmpTxtrRemap"); string $bmpTxtrFile = ($shader + "_bmpTxtrFile"); string $bmpColorMix = ($shader + "_ColorMix"); createNode mib_passthrough_bump_map; rename $bmpPassThrough; createNode mib_bump_basis; rename $bmpBasis; connectAttr ($bmpBasis + ".u") ($bmpPassThrough + ".u"); connectAttr ($bmpBasis + ".v") ($bmpPassThrough + ".v"); createNode mib_texture_vector; rename $bmpTxtrVector; setAttr ($bmpTxtrVector + ".selspace") 1; createNode mib_texture_remap; rename $bmpTxtrRemap; connectAttr ($bmpTxtrVector + ".outValue") ($bmpTxtrRemap + ".input"); connectAttr ($bmpTxtrRemap + ".outValue") ($bmpPassThrough + ".coord"); createNode mentalrayTexture; rename $bmpTxtrFile; connectAttr ($bmpTxtrFile + ".message") ($bmpPassThrough + ".tex"); createNode mib_color_mix; rename $bmpColorMix; connectAttr ($bmpPassThrough + ".outValue") ($bmpColorMix + ".color_base"); setAttr ($bmpColorMix + ".num") 1; setAttr ($bmpColorMix + ".mode_0") 1; setAttr ($bmpColorMix + ".weight_0") 1; connectAttr ($bmpColorMix + ".outValue") ($shader + ".specular"); } //_______________________________________________ // |||||||||||||| // |||||||| // |||||||||||||| //// UI PROCEDURES // - - - - - - - - - - - - global proc pDialogBox() { string $buttonResponse = `promptDialog -title "MISSS Physical" -message "Shader Name" -button "OK" -button "Cancel" -defaultButton "OK" -cancelButton "Cancel" -dismissString ""`; string $textResponse = `promptDialog -q`; print ("SSS Physical Shader name is " + $textResponse + "\n"); if ($buttonResponse == "OK" && $textResponse != "") { createPhysical($textResponse); } } // - - - - - - - - - - - - // - - - - - - - - - - - - global proc fsDialogBox() { string $buttonResponse = `promptDialog -title "Fast Simple" -message "Shader Name" -button "OK" -button "Cancel" -defaultButton "OK" -cancelButton "Cancel" -dismissString ""`; string $textResponse = `promptDialog -q`; print ("Fast Simple Shader name is " + $textResponse + "\n"); if ($buttonResponse == "OK" && $textResponse != "") { fastSimple($textResponse); } } // - - - - - - - - - - - - // - - - - - - - - - - - - global proc bmpDialogBox() { string $buttonResponse = `promptDialog -title "DGS With Bump" -message "Shader Name" -button "OK" -button "Cancel" -defaultButton "OK" -cancelButton "Cancel" -dismissString ""`; string $textResponse = `promptDialog -q`; print ("DGS Bump Map Shader name is " + $textResponse + "\n"); if ($buttonResponse == "OK" && $textResponse != "") { mrBump($textResponse); } } // - - - - - - - - - - - - ///////////////////////////////////// //////////////////////////////////// ////// BUILD THE UI //========================================================= global proc mrUtils() { setCurrentRenderer mentalRay; unifiedRenderGlobalsWindow; window -e -vis 0 unifiedRenderGlobalsWindow; string $mrUtilities = `window -title "Mental Ray Utilities (beta)" -menuBar true -rtf true mrUtils`; string $form = `formLayout mainForm`; string $tabs = `tabLayout -innerMarginWidth 5 -innerMarginHeight 5 mainTab`; formLayout -edit -attachForm $tabs "top" 0 -attachForm $tabs "left" 0 -attachForm $tabs "bottom" 0 -attachForm $tabs "right" 0 $form; //----------------------------- /////////////////////// // RENDER SETTINGS MENU //////////............. menu -label "Render Settings" -tearOff true renderSettingsMenu; menuItem -label "Use Mental Ray" -checkBox off -command "setCurrentRenderer mentalRay;" checkBox1 ; menuItem -label "Enable Caustics" -checkBox off -command "setAttr miDefaultOptions.caustics 1;" checkBox2; //----------------------------- ///////////////////////// // SSS SHADERS TAB ///////////----- string $child1 = `columnLayout "SSS Shader Utilities"`; //+++++++++++++++++++++++++ // PHYSICAL SHADER SECTION //===== frameLayout -w 460 -collapsable true -label "Create Physical SSS Shader" physicalCreateFrame; columnLayout physicalCreateColumn; rowColumnLayout -nc 4 physicalCreateRow; button -label "Make Shader" -command "pDialogBox()" Button_createPhysical; setParent ..; frameLayout -w 460 -collapsable true -label "Physical SSS Shader Settings" physicalSettingsFrame; columnLayout physicalSettingsColumn; string $group1 = `radioButtonGrp -numberOfRadioButtons 3 -label "Presets" -labelArray3 "Jade" "Marble" "Ketchup" -select 1 // SCATTERING COEFF ABSORPTION COEFF IOR TRANSMISSION MATERIAL -onCommand1 "shaderMod(0.657, 0.786, 0.9, 0.00053, 0.00123, 0.00213, 1.3, 0.141, 0.504, 0.165, 0.0, 0.084, 0.04);" //Jade -onCommand2 "shaderMod(2.19, 2.62, 3.00, 0.0021, 0.0041, 0.0071, 1.55, 0.795, 0.808, 0.617, 0.1, 0.1, 0.1);" //Marble -onCommand3 "shaderMod(0.18, 0.07, 0.03, 0.061, 0.97, 1.45, 1.5, 0.5, 0.0, 0.00, 0.12, 0.0, 0.0);"`; //Ketchup radioButtonGrp -numberOfRadioButtons 2 -shareCollection $group1 -label "" -labelArray2 "Whole Milk" "Skim Milk" -onCommand1 "shaderMod(0.70, 1.22, 1.90, 0.0014, 0.0025, 0.0142, 1.3, 0.2, 0.2, 0.2, 0.5, 0.5, 0.5);" //WholeMilk -onCommand2 "shaderMod(2.55, 3.21, 3.77, 0.0011, 0.0024, 0.014, 1.3, 0.2, 0.2, 0.2, 0.5, 0.5, 0.5);"; //SkimMilk setParent SSS_Shader_Utilities; //+++++++++++++++++++++++++ // FAST SIMPLE SECTION //===== frameLayout -w 430 -collapsable true -label "Create Fast Simple SSS Shader"; columnLayout; rowColumnLayout -nc 4; button -label "Make Shader" -command "fsDialogBox()"; setParent mainTab; //----------------------------- ///////////////////////// // MR BUMP MAPPING TAB ///////////----- string $child2 = `columnLayout "Mental Ray Bump Mapping Utilities"`; frameLayout -w 460 -collapsable true -label "Create Mental Ray DGS Bump Map"; columnLayout; rowColumnLayout -nc 4; button -label "Make Shader" -command "bmpDialogBox()"; setParent mainTab; showWindow $mrUtilities; } ///////////////////////////////////////////////////////// //======================================================= ///////// ///////////////////////////////////////////////////////////////////// }