Author Topic: Setting RGB baseColor values with maxscript defaulting to linear input?  (Read 1315 times)

2024-05-15, 01:18:37

Jpjapers

  • Active Users
  • **
  • Posts: 1716
    • View Profile
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

 
« Last Edit: 2024-05-15, 15:05:03 by Jpjapers »

2024-05-17, 11:18:30
Reply #1

Frood

  • Active Users
  • **
  • Posts: 2002
    • View Profile
    • Rakete GmbH
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



Never underestimate the power of a well placed level one spell.

2024-05-20, 13:00:41
Reply #2

Jpjapers

  • Active Users
  • **
  • Posts: 1716
    • View Profile