Home Technical Talk

MaxScript to automate rgb color conversion to gamma 2.2?

hi, I was wondering if there is a plugin to do so, but couldn't find, so I started to script my own.

decided to do so because I have many old models wich I use to populate my scenes at work, and these models have materials made on a 1.0 gamma environment, and everytime I want to use one of them, I have to manually convert all colors to match a 2.2 gamma equivalent.

to convert their colors, I use this formula on each color channel: 255*((old/255)^2.2), it's based on a tutorial by mintviz, but having to manually correct all colors is a tedious and time consuming process, and I'm assuming it could be 100% automated.

what I'm thinking is a simple button that when you press, uses that formula on all RGB channels from all color map slots set on all existing materials on selected objects only.

I don't have much experience with maxscript, but I did a few control interfaces and such, and I can google my way around. I just need some help because this can start getting too specific to google everything, and it also shouldn't be hard for someone with experience on maxscript.

I've got it working with diffuse and reflection maps for vray materials, and diffuse map for standard materials, the problem starts when I have a multi/sub-object material, and also when colors are set in sub maps, as if I wanted to convert the 2 colors set on a falloff map inside the diffuse slot. those are the two situations I wasn't able to figure out.

code looks like this so far:

[code]
function StdDiffuseRGBtoLinear =
(
oldr = $.material.diffuseColor.r
oldg = $.material.diffuseColor.g
oldb = $.material.diffuseColor.b
$.material.diffuseColor.r = 255*((oldr/255)^2.2)
$.material.diffuseColor.g = 255*((oldg/255)^2.2)
$.material.diffuseColor.b = 255*((oldb/255)^2.2)
)

function VrayDiffuseRGBtoLinear =
(
oldr = $.material.diffuse.r
oldg = $.material.diffuse.g
oldb = $.material.diffuse.b
$.material.diffuse.r = 255*((oldr/255)^2.2)
$.material.diffuse.g = 255*((oldg/255)^2.2)
$.material.diffuse.b = 255*((oldb/255)^2.2)
)

function VrayReflectRGBtoLinear =
(
oldr = $.material.reflection.r
oldg = $.material.reflection.g
oldb = $.material.reflection.b
$.material.reflection.r = 255*((oldr/255)^2.2)
$.material.reflection.g = 255*((oldg/255)^2.2)
$.material.reflection.b = 255*((oldb/255)^2.2)
)

for obj in selection do 
(
if classof $.material == StandardMaterial do 
(
StdDiffuseRGBtoLinear ()
)
if classof $.material == VRayMtl do 
(
VrayDiffuseRGBtoLinear ()
VrayReflectRGBtoLinear ()
)
)
[/code]

what can I do to make it work with multi material, and sub maps?

thanks in advance,
Rafael

Replies

Sign In or Register to comment.