Chaos Corona Forum

Chaos Corona for 3ds Max => [Max] I need help! => Topic started by: Jpjapers on 2024-05-15, 01:18:37

Title: Setting RGB baseColor values with maxscript defaulting to linear input?
Post by: Jpjapers on 2024-05-15, 01:18:37
Hi,

Whenever i try to change the baseColor of corona materials via maxscript, the values end up being input in linear by default. Im assuming this is because of the way max internally handles colors and the conversion between rgb 255 and rgb 0-1. How can i ensure theyre added in sRGB or how can i convert the values correctly?

for instance color 250,200,10. If i manually add it into the picker in srgb mode the colour is correct.
However when i add it via maxscript it adds it in linear mode and so the resulting srgb colour is 254,228,59

How can i fix this? Is there a formula i need to implement in my script or do i need a different approach?
I tried using the max standard color map but the same thing happens even if i set the gamma to 1.0. It has to be to do with the way maxscript handles the (color R G B) values internally.

Thanks!

EDIT: The solution was to gamma correct the sRGB colours

Heres a function

Code: [Select]

 fn adjustColorGamma _inputColor _maxVal _gammaVal _doInverse =
 (
 if _doInverse then
 (
 outputR = _maxVal * ((_inputColor.r/_maxVal)^(1.0/_gammaVal))
 outputG = _maxVal * ((_inputColor.g/_maxVal)^(1.0/_gammaVal))
 outputB = _maxVal * ((_inputColor.b/_maxVal)^(1.0/_gammaVal))
 
 (color outputR outputG outputB)
 ) else
 (
 outputR = _maxVal * ((_inputColor.r/_maxVal)^_gammaVal)
 outputG = _maxVal * ((_inputColor.g/_maxVal)^_gammaVal)
 outputB = _maxVal * ((_inputColor.b/_maxVal)^_gammaVal)
 
 (color outputR outputG outputB)
 )
 )

adjustColorGamma (color 255 255 255) 255 2.2 false

 
Title: Re: Setting RGB baseColor values with maxscript defaulting to linear input?
Post by: Frood on 2024-05-17, 11:18:30
Hi,

depending on your needs you could consider using the accurate formula I think. Just the gamma value as exponent is a quick approximation afaik and you end up with a deviation of about 6 (using 0 to 255) at values around 130. See chart: blue is simple gamma, green graph is what you can find everywhere as formula to convert (the low value cutoffs seem to depend on color space but I think using 0-255 does not resolve enough anyway in that range and I have not used them here).


Good Luck



Title: Re: Setting RGB baseColor values with maxscript defaulting to linear input?
Post by: Jpjapers on 2024-05-20, 13:00:41
This is good info thank you frood