Maya Gamma Node MEL Script

Posted by on Jul 5, 2010 in code, Maya, MEL | 3 Comments

If you are working linear in Maya, you probably add gamma correct nodes between each texture and it’s material.

This MEL script will add a gamma correct node (set to gamma .45) between a selected texture and it’s selected target material, and it will attach the network to the material’s color attribute.

Before you run the script:
first select the material and the texture that you want to attach to it.

string $mySel[] = `ls -sl`;
string $myMaterial[] = `ls -mat $mySel`;
string $myTex[] = `ls -tex $mySel`;
string $myGamma = `shadingNode -asUtility gammaCorrect`;
setAttr ($myGamma + ".gammaX") 0.45;
setAttr ($myGamma + ".gammaY") 0.45;
setAttr ($myGamma + ".gammaZ") 0.45;
connectAttr -force ($myTex[0] + ".outColor") ($myGamma + ".value");
connectAttr -force ($myGamma + ".outValue") ($myMaterial[0] + ".color");

Email this to someoneTweet about this on TwitterShare on FacebookShare on Google+Share on LinkedInShare on StumbleUponShare on RedditDigg this


  1. Hugo Baptista
    January 19, 2011

    In 3Dsmax you can control input and output gamma of textures globally. there’s no such thing in Maya? It’s been something like 5 years since I last used Maya…

  2. Oliver
    January 19, 2011

    In fact you may be able to do that, but I m not aware of the procedure to do it correctly. I know you can change the gamma setting in the frame buffer, but the result is not what I expected.

  3. Oliver
    February 2, 2011

    Note: Maya 2011 now has color management that makes this setup unnecessary.

Leave a Reply