//////////////////////////////////////////////////////// // //Procedural Softbox Light. v Alpha B //Written By Oliver Wolfson // //email oliverwolfson@gmail.com // // // //This MEL script creates a rigged light and a procedurally textured reflector card, simulating a studio style soft box light. //The rig is intended to be used for reflection or IBL when rendering using Mental Ray in Maya. // // // //////////////////////////////////////////////////////// proc CreateSoftBoxProcedure() { //Create softbox string $mySoftboxTMP[] = `polyPlane -name "softBox" -ch on -o on -sw 1 -sh 1 -cuv 2` ; scale -r 5 5 5; setAttr "|softBox.rotateX" 90; move 0 10 1; makeIdentity -apply true -t 1 -r 1 -s 1 -n 0; string $mySetAttr[] = `ls -sl -dag -shapes`; setAttr ($mySetAttr[0] + ".castsShadows") 0; setAttr ($mySetAttr[0] + ".primaryVisibility") 0; setAttr ($mySetAttr[0] + ".receiveShadows") 0; setAttr ($mySetAttr[0] + ".motionBlur") 0; setAttr ($mySetAttr[0] + ".smoothShading") 0; //Create and assign shader string $material = `shadingNode -asShader surfaceShader -name "softBoxMaterial"`; string $SG = `sets -renderable true -noSurfaceShader true -empty -name ($material + "SG")`; connectAttr -f ( $material + ".outColor" ) ( $SG + ".surfaceShader" ); select $mySoftboxTMP[0]; sets -e -forceElement $SG; //create first ramp string $fileNode = `shadingNode -asTexture ramp`; connectAttr -f ( $fileNode + ".outColor" ) ( $material + ".outColor" ); removeMultiInstance -break true ( $fileNode + ".colorEntryList[1]"); setAttr ($fileNode + ".colorEntryList[0].color") -type double3 2.5 2.5 2.5 ; setAttr ($fileNode + ".colorEntryList[0].position") 0; setAttr ($fileNode + ".colorEntryList[2].color") -type double3 1 1 1 ; setAttr ($fileNode + ".type") 4; setAttr ($fileNode + ".colorEntryList[2].position") 1; setAttr ($fileNode + ".interpolation") 4; //create second ramp string $fileNode2 = `shadingNode -asTexture ramp`; connectAttr -f ( $fileNode2 + ".outColor" ) ( $fileNode + ".colorGain" ); removeMultiInstance -break true ( $fileNode2 + ".colorEntryList[1]"); removeMultiInstance -break true ( $fileNode2 + ".colorEntryList[2]"); setAttr ($fileNode2 + ".colorEntryList[0].color") -type double3 1 1 1; // create Mult Devide string $myMultDevide2 = `shadingNode -asUtility multiplyDivide`; connectAttr -f ($fileNode2 + ".outColor") ($myMultDevide2 + ".input1"); setAttr ($myMultDevide2 + ".input2X") 100; setAttr ($myMultDevide2 + ".input2Y") 100; setAttr ($myMultDevide2 + ".input2Z") 100; //Create Spot Light string $mySoftBoxSpotlight = `spotLight`; move 0 10 0.65; rotate 180 0 0; setAttr ($mySoftBoxSpotlight + ".emitSpecular") 0; setAttr ($mySoftBoxSpotlight + ".coneAngle") 105; setAttr ($mySoftBoxSpotlight + ".penumbraAngle") 10; setAttr ($mySoftBoxSpotlight + ".dropoff") 6; setAttr ($mySoftBoxSpotlight + ".dropoff") 6; setAttr ($mySoftBoxSpotlight + ".useRayTraceShadows") 1; setAttr ($mySoftBoxSpotlight + ".lightRadius") 3; setAttr ($mySoftBoxSpotlight + ".shadowRays") 20; setAttr ($mySoftBoxSpotlight + ".intensity") 1; setAttr ($mySoftBoxSpotlight + ".decayRate") 2; connectAttr -f ($myMultDevide2 + ".outputX") ($mySoftBoxSpotlight + ".intensity"); select $mySoftBoxSpotlight; setAttr ($mySoftBoxSpotlight + ".areaLight") 1; select $mySoftBoxSpotlight; select -tgl $mySoftboxTMP[0]; parent; select $mySoftboxTMP[0]; rotate -r -ws 90 0 0 ; move -rpr -z 0 ; makeIdentity -apply true -t 1 -r 1 -s 1 -n 0; string $arrw = `curve -d 1 -p 0 9 -1 -p 0 9 1 -p 0 2 1 -p 0 2 2 -p 0 0 0 -p 0 2 -2 -p 0 2 -1 -p 0 9 -1 -k 0 -k 1 -k 2 -k 3 -k 4 -k 5 -k 6 -k 7` ; scale 0.3 0.3 0.3; string $LocatorTMP[] = `spaceLocator -p 0 0 0`; setAttr ($LocatorTMP[0]+ ".translateY") 10; setAttr ($LocatorTMP[0] + ".scaleX") 4; setAttr ($LocatorTMP[0] + ".scaleY") 4; setAttr ($LocatorTMP[0] + ".scaleZ") 4; setAttr -k off ($LocatorTMP[0] + ".scaleX"); setAttr -k off ($LocatorTMP[0] + ".scaleY"); setAttr -k off ($LocatorTMP[0] + ".scaleZ"); //Aim and orient constrain select $arrw; select -tgl $LocatorTMP[0]; aimConstraint -offset 0 0 0 -weight 1 -aimVector 0 -1 0 -upVector 0 1 0 -worldUpType "vector" -worldUpVector 0 1 0; select $LocatorTMP[0]; select -tgl $arrw; orientConstraint -offset 0 0 0 -weight 1; //create color attributes for the locator select $LocatorTMP[0]; addAttr -ln "color" -uac -at "float3"; addAttr -ln "red" -at "float" -parent "color"; addAttr -ln "green" -at "float" -parent "color"; addAttr -ln "blue" -at "float" -parent "color"; addAttr -ln "rayTracedShadows" -at bool $LocatorTMP[0]; setAttr -e -keyable true ($LocatorTMP[0] + ".rayTracedShadows"); addAttr -ln intensity -at double -min 0 -dv 1 $LocatorTMP[0]; setAttr -e -keyable true ($LocatorTMP[0] + ".intensity"); connectAttr -f ($LocatorTMP[0] + ".color") ($fileNode2 + ".colorEntryList[0].color"); connectAttr -f ($LocatorTMP[0] + ".color") ($mySoftBoxSpotlight + ".color"); setAttr -k on ($LocatorTMP[0] + ".blue") 1; setAttr -k on ($LocatorTMP[0] + ".green") 1; setAttr -k on ($LocatorTMP[0] + ".red") 1; string $myMultDev = `shadingNode -asUtility multiplyDivide`; print $myMultDev; connectAttr -f ($LocatorTMP[0] + ".intensity") ($myMultDev + ".input1X"); connectAttr -f ($LocatorTMP[0] + ".intensity") ($myMultDev + ".input1Y"); connectAttr -f ($LocatorTMP[0] + ".intensity") ($myMultDev + ".input1Z"); connectAttr -force ($myMultDev + ".output") ($fileNode2 + ".colorGain"); //connect Renderable attr //connect Shadow attributes setAttr ($LocatorTMP[0] + ".rayTracedShadows") 0; connectAttr -f ($LocatorTMP[0] + ".rayTracedShadows") ($mySoftBoxSpotlight+ ".useRayTraceShadows"); // select $mySoftBoxSpotlight; move -r 0 -.35 0 ; rename "softBoxSpot"; select -tgl $LocatorTMP[0]; parent; select $mySoftboxTMP[0]; rename "softBox"; select -tgl $LocatorTMP[0]; parent; select $LocatorTMP[0]; select -tgl $arrw; group -n "softBoxLightGroup"; xform -os -piv 0 0 0; scale -r 3 3 3; select $arrw; rename "softBoxARROW"; select $LocatorTMP[0]; rename "softBoxLightControl"; } CreateSoftBoxProcedure;