//////////////////////////////////////////////////////////////////////////////////////////// // // // Script: mmFalloffLight.mel // // Version: 1.0 // // Author: Manuel Macha // // Contact: manuel@manuelmacha.de // //________________________________________________________________________________________ // Description: // // Creates a spotlight that gives you precise control over it's brightness in relation to it's // distance. Regions can be intuitively adjusted in Maya's viewport by using the light's standard // decay-region manipulators. The light will give you control over 5 different regions. // Works both with Mental Ray and Maya Software Renderer. // // * Max Brightness Region: The shines with the highest, constant intensity in this area. // * Near Fallof & Far Falloff Cone: Area in which the light;s intensity will be defined by // a linear falloff, ranging from it's maxBrightness to it's near- or farBrightness region. // * Near Brigthess & Far Brightness Region: In this area the light shines with a constant // intensity (which is in all cases must be less or equal to it's maxBrightness). // // Instructions: // // * Copy the mel-file into Maya's script directory and // source the script (source "mmFalloffSpotLight.mel";) // * To create a light, type the following command mmFalloffSpotlight(); // // or assign it to a shelf-button. // // // //////////////////////////////////////////////////////////////////////////////////////////////////////// global proc mmFalloffSpotLight() { float $coneAngle = 40; float $penumbra = 20; ///--- CREATE THE SPOTLIGHT ---/// string $spotLight = `spotLight -coneAngle $coneAngle -penumbra $penumbra -rgb 1.0 1.0 1.0 -useRayTraceShadows false`; ///--- SET SPOTLIGHT'S DECAY REGIONS ---/// setAttr ($spotLight + ".useDecayRegions") 1; setAttr ($spotLight + ".startDistance1") 0; setAttr ($spotLight + ".endDistance1") 0; setAttr ($spotLight + ".endDistance3") 25; setAttr ($spotLight + ".startDistance3") 20; setAttr ($spotLight + ".endDistance2") 10; setAttr ($spotLight + ".startDistance2") 5; setAttr ($spotLight + ".useDecayRegions") 0; ///--- ADD NEAR-, FAR- AND MAX-BRIGHTNESS ATTRIBUTE TO SPOTLIGHT ---/// addAttr -longName "maxBrightness" -attributeType double -defaultValue 1 $spotLight; setAttr -edit -keyable true ($spotLight + ".maxBrightness"); addAttr -longName "nearBrightness" -attributeType double -min 0 -max 1 -defaultValue 0 $spotLight; setAttr -edit -keyable true ($spotLight + ".nearBrightness"); addAttr -longName "nearValue" -attributeType double -defaultValue 0 $spotLight; setAttr -edit -keyable true ($spotLight + ".nearValue"); addAttr -longName "farBrightness" -attributeType double -min 0 -max 1 -defaultValue 0 $spotLight; setAttr -edit -keyable true ($spotLight + ".farBrightness"); addAttr -longName "farValue" -attributeType double -defaultValue 0 $spotLight; setAttr -edit -keyable true ($spotLight + ".farValue"); ///--- CREATE SHADING NODES ---/// string $lightInfo = `shadingNode -asUtility lightInfo`; string $setRange = `shadingNode -asUtility setRange`; string $nearCondition = `shadingNode -asUtility condition`; string $farCondition = `shadingNode -asUtility condition`; string $multiplyDivide1 = `shadingNode -asUtility multiplyDivide`; string $multiplyDivide2 = `shadingNode -asUtility multiplyDivide`; ///--- SET SHADING NODES' ATTRIBUTES ---/// setAttr ($setRange + ".minX") 0; setAttr ($setRange + ".maxX") 1; setAttr ($setRange + ".minY") 1; setAttr ($setRange + ".maxY") 0; setAttr ($nearCondition + ".operation") 4; setAttr ($farCondition + ".operation") 4; ///--- INTERCONNECT SPOTLIGHT WITH SHADING NODES ---/// connectAttr -force ($spotLight + ".worldMatrix[0]") ($lightInfo + ".worldMatrix"); connectAttr -force ($spotLight + ".endDistance2") ($setRange + ".oldMaxX"); connectAttr -force ($spotLight + ".endDistance3") ($setRange + ".oldMaxY"); connectAttr -force ($spotLight + ".startDistance2") ($setRange + ".oldMinX"); connectAttr -force ($spotLight + ".startDistance3") ($setRange + ".oldMinY"); connectAttr -force ($spotLight + ".startDistance2") ($nearCondition + ".secondTerm"); connectAttr -force ($spotLight + ".startDistance3") ($farCondition + ".secondTerm"); connectAttr -force ($spotLight + ".maxBrightness") ($multiplyDivide1 + ".input2X"); connectAttr -force ($lightInfo + ".sampleDistance") ($setRange + ".valueX"); connectAttr -force ($lightInfo + ".sampleDistance") ($setRange + ".valueY"); connectAttr -force ($lightInfo + ".sampleDistance") ($nearCondition + ".firstTerm"); connectAttr -force ($lightInfo + ".sampleDistance") ($farCondition + ".firstTerm"); connectAttr -force ($setRange + ".outValueX") ($nearCondition + ".colorIfFalseR"); connectAttr -force ($setRange + ".outValueY") ($farCondition + ".colorIfFalseR"); connectAttr -force ($nearCondition + ".outColorR") ($farCondition + ".colorIfTrueR"); connectAttr -force ($farCondition + ".outColorR") ($multiplyDivide1 + ".input1X"); connectAttr -force ($multiplyDivide1 + ".outputX") ($spotLight + ".intensity"); connectAttr -force ($spotLight + ".nearBrightness") ($setRange + ".minX"); connectAttr -force ($spotLight + ".farBrightness") ($setRange + ".maxY"); connectAttr -force ($spotLight + ".maxBrightness") ($multiplyDivide2 + ".input1Y"); connectAttr -force ($spotLight + ".maxBrightness") ($multiplyDivide2 + ".input1Z"); connectAttr -force ($spotLight + ".nearBrightness") ($multiplyDivide2 + ".input2Y"); connectAttr -force ($spotLight + ".farBrightness") ($multiplyDivide2 + ".input2Z"); connectAttr -force ($multiplyDivide2 + ".outputY") ($spotLight + ".nearValue"); connectAttr -force ($multiplyDivide2 + ".outputZ") ($spotLight + ".farValue"); connectAttr -force ($multiplyDivide2 + ".outputY") ($nearCondition + ".colorIfTrueR"); setAttr -lock true ($spotLight + ".nearValue"); setAttr -lock true ($spotLight + ".farValue"); ///--- RENAME THE CREATED NODES ---/// $spotLight = `rename $spotLight "mmSpotLightShape"`; rename `pickWalk -direction "up" $spotLight` "mmSpotLight"; $lightInfo = `rename $lightInfo "mmSpotLightInfo"`; $setRange = `rename $setRange "mmSpotLightSetRange"`; $nearCondition = `rename $nearCondition "mmSpotLightNearCondition"`; $farCondition = `rename $farCondition "mmSpotLightFarCondition"`; $multiplyDivide1 = `rename $multiplyDivide1 "mmSpotLightMultiplyDivideBrightness"`; $multiplyDivide2 = `rename $multiplyDivide2 "mmSpotLightMultiplyDivideDecay"`; } mmFalloffSpotLight();