script to automate rgb color conversion to gamma 2.2

script to automate rgb color conversion to gamma 2.2

fael097
Advocate Advocate
2,073 Views
2 Replies
Message 1 of 3

script to automate rgb color conversion to gamma 2.2

fael097
Advocate
Advocate

hi, I was wondering if there is a plugin to do so?

If so great, but since I haven't found one yet, I was thinking of something like this:

basically, I have many old models, with 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.

the formula I use is 255*((old/255)^2.2), based on a tutorial by mintviz, but having to manually correct all colors is a tedious and time consuming process, and at least theoretically could be heavily automated.

what I'm thinking is a simple button that when you press, converts all existing colors, from the selected object only, to it's 2.2 equivalent.

I've done a little custom attributes interfacing in maxscript, but that's all, so I don't have a large experience with it, so I need some help here.

the script would verify if there's an object or objects selected, then it would pick all of their materials, check each of them for existing colors assigned to the map slots, sub maps, etc, and apply the formula to all of them.

what you think?

it should be simple enough, I just don't even know where to start

0 Likes
2,074 Views
2 Replies
Replies (2)
Message 2 of 3

fael097
Advocate
Advocate

so this is what I've got so far:

 

 

function RGBtoLinear =
(
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)
)
for obj in selection do
(
RGBtoLinear ()
)

it works, but only for the diffuse slot. Also fails to call multi/sub-object materials.

 

I wanted to make it work for every slot that has a color assigned, specially if for example, the specular slot (or in the case of a vray material, the Reflect slot) has a falloff map with 2 colors, I want it to convert those colors aswell.

will keep digging, but any suggestions and corrections are highly appreciated.

0 Likes
Message 3 of 3

fael097
Advocate
Advocate

got it to work with standard material diffuse slot, and vraymtl diffuse and reflection slots. here's what I've got so far:

 

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 ()
	)
)

the problem is 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.

 

how can I get it to work?

0 Likes