PDA

View Full Version : Modify Color Channel with Expression


WesMcDermott
01-29-2008, 05:41 PM
HI,

I am trying to write an expression to modify the color channel of a blinn shader. I am new to using MEL, so I'd appreciate some help. I am trying to linearize the color values that were chosen with the color picker. Using this formula

x = 255 * (x / 255) ^ gamma

where gamma = 2.2 for my monitor space

I have added an expression to the Color channel and I'm trying to change the formula to work in mel. Here is what I have.

$cR = 255*pow((blinn1.colorR/255),2.2);
$cG = 255*pow((blinn1.colorG/255),2.2);
$cB = 255*pow((blinn1.colorB/255),2.2);

setAttr "blinn1.color" -type double3 $cR $cBG $cB;

When I create the expression, the color channel is modified but it's turned black 0,0,0.
I know this formula is correct since I've used it in other 3D applications with perfect results.

If I manually use the forumula with a calculator and type in my color values from the blinn color channel, I get the corrected color value which appears as a darker green.

Original color values 40,119,13 after using formula on each RGB channel I get 4,48,0.

I don't understand why I'm getting 0,0,0 instead of 4,48,0 when using the above mel expression. Can someone please help me to understand what I'm missing?

thanks,

Wes

tbaypaul
01-29-2008, 07:55 PM
255 = 1.0....
so......pow(1.0/255,2.2) = 0.........

WesMcDermott
01-29-2008, 08:09 PM
Yes, that is correct, but I'm not using 1.0. I am using the RGB of the blinn1.colorR. blinn1.colorG, blinn1.colorB which is 40,119,13. For example the red channel would be
255*pow((40/255),2.2) = 4 for the red channel;

tbaypaul
01-30-2008, 01:56 AM
colors are doubles.....

WesMcDermott
01-30-2008, 12:04 PM
I'm sorry, I'm not sure what you mean. I'm new at this.

thanks,

Wes

tbaypaul
01-30-2008, 04:14 PM
open the script editor and watch maya echo your commands when you change the blinn color....so those are the numbers maya really uses for color...the color picker is just giving you the option to pick colors in a way that might be more familiar.

WesMcDermott
01-30-2008, 04:32 PM
Thanks for the clarification! It makes sense now why my numbers are incorrect. I'm not sure how to make the linear formula work for double float values. Anyways, I have been using the mult/div node to simulate the gammaCorrect node for use in RenderMan for Maya. This is working correctly. I think I'll just drop the idea of creating the expression.


Thanks for your help!

Wes

CGTalk Moderation
01-30-2008, 04:33 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.