PDA

View Full Version : Change gamma value?


zeme
02-01-2008, 03:33 PM
Hi, first time here. :)

I am a begginer in maxscript (mostly modeling, texture, lighting guy), but i am trying to get into it as it seams very nice way to save time on some repetitive tasks. The only script i have made is a code that changes the default render engine in max to Vray (just one line of code).

Anyhow, we recently moved from linear color space to logarithmic so sometimes we need to change texture input gamma from its default to 2.2, like here: http://img147.imageshack.us/img147/9046/gamma01ga6.th.png (http://img147.imageshack.us/my.php?image=gamma01ga6.png)
Btw, we use this gamma setup:
http://www.aversis.be/tutorials/vray/essential_gamma_01.htm

If a file has several thousand objects and you have to change each texture...you see the problem. So i thought i would write a script that goes only into Diffuse bitmap (as far as i know, only diffuse map needs to be gamma corrected) and changes its gamma. Material after material.
Plus, it could test and correct textures that somebody just forgot to gamma correct.

I found out that you can't do this directly, because help says:
It is not possible to change the gamma or pixel aspect of a bitmap once created, though you can copy one bitmap into a newly created one that has a different gamma or pixel aspect to achieve this effect.


I tried to create a temp variable that would store the bitmap and change its gamma and than overwrite the original bitmap, but right now its beyond my skills. :(

So it would really rock if someone could point me in right direction. :)

Sorry for my English. ;)

Bobo
02-02-2008, 12:55 AM
The quote from the help applies to MAXScript Bitmap Values, not to the Open Bitmap dialog's override gamma settings which are, AFAIK, NOT accessible to MAXScript.
Even if you would save a new bitmap with a new gamma setting saved with the file, the open bitmap dialog is currently set to "Override" and not "Use Bitmap's Own Gamma", so it would change nothing.
This file picker was written before there was MAXScript to worry about and I am afraid none of its options are scriptable :(
Of course, I could be wrong.

zeme
02-02-2008, 01:27 PM
Thanks for reply Bobo. :)

Ok, will have to do it manually or think of other gamma setup.
Anyhow, will try to learn maxscript to do some of "my" work. :)

JHN
02-02-2008, 01:55 PM
I don't know which version of max you use, but maybe you can add a "mr Gamma & Gain" map between the diffuse and the texture map? Providing you use mental ray...
Or when not using MR then using the colorcorrect plugin to do the gamma for you..

Any help!?

Johan

zeme
02-02-2008, 08:25 PM
Yeah, colourcorrect plugin is great, but its still additional stuff you have to do. We use vray and it has its own colour correct plugin, but again, that is even more work than just typing that 2.2 in that dialog box. Ok its not much, but i just want to get more efficient and it looks like it isn't possible. :/
Anyhow, thanks for reply.

Gravey
02-02-2008, 09:31 PM
Yeah, colourcorrect plugin is great, but its still additional stuff you have to do. We use vray and it has its own colour correct plugin, but again, that is even more work than just typing that 2.2 in that dialog box. Ok its not much, but i just want to get more efficient and it looks like it isn't possible. :/
Anyhow, thanks for reply.How is it more work if you're intending on writing a script? It should save time because you wont have to worry about typing the 2.2 anymore

zeme
02-02-2008, 09:59 PM
I guess i didn't type it correctly (my lousy english :)). I meant that its not a big difference to type 2,2 in a dialog box for diffuses, or just use a new shader. Its all the same - a bit of hassle.
I hoped that there was a way to automatically type that number there.
btw guys, any idea how to add it via some utilities from windows or something like that? Just ''shooting'' in the darkness here.

Kameleon
02-02-2008, 10:47 PM
Hi there, I started scripting this on Friday and I achieved something but it's not yet finished. I created a new bitmap with the same width, height and added the gamma:0.4545(Inverse 2.2 gamma) then copied the current bitmap to the newly created and used "display thenewbitmap" and it worked ok if the current bitmap is loaded with a bitmap of 1.0 (other gamma would imply calculating the inverse gamma of that bitmap) but then I had to go home and I still havent finished, but it seems that after that I have to save the bitmap with a new name or overwrite the current one and then apply the new bitmap to the current diffusemap.

I hope I was clear, sorry about my english too :D Monday I'll try posting what I have so we can talk about it and maybe someone comes with some better solution. Cyas!

Kameleon
02-04-2008, 09:51 AM
Well I just proved Bobo is right lol I've made the gamma change, applied the new bitmap but Max overrides it :|


freescenebitmaps()
mtls=scenematerials
for i=1 to mtls.count do
(
themat=mtls[i]
case classof themat of
(
Standard:
(
thebitmap=themat.diffuseMap.bitmap
if thebitmap.gamma==1 then
(
newgamma=1/2.2
)
else
(
newgamma=1/thebitmap.gamma
)
thenewbitmap=bitmap thebitmap.width thebitmap.height filename:thebitmap.filename gamma:newgamma

rendermap themat.diffuseMap into:thenewbitmap
thebitmap=copy thenewbitmap
thebitmap.filename=getfilenamepath(thenewbitmap.filename)+getfilenamefile(thenewbitmap.filename)+"_gamma"+getfilenametype(thenewbitmap.filename)
save thebitmap
display thebitmap

print thebitmap.gamma
themat.diffuseMap.bitmap=thebitmap
)
)
)

zeme
02-04-2008, 11:07 AM
Thanks Kameleon for your effort, pitty it doesn't work. :/
Will have to think of something else. :)

Kameleon
02-04-2008, 11:16 AM
No problem... But anyway I thought of another solution... why dont you do a macro in photoshop to change the gamma in all your images ? It could work... but it would be better to save a copy of the maps first.

zeme
02-04-2008, 01:11 PM
Well it would be one of the ways, but the problem is that these files are on server and there are quite many + they will look a bit different and not natural. I just like how max handles them - temporarily adjusting them when they are needed, i just don't like that i have to check checkboxes over and over.
I have an idea that there are those utilities that allow you to customize Open/Save/Load dialogs. They ad new features like - last used files, remembering some of the settings and so on. I hope that it could work with this - save particular settings for particular dialogbox.

Hope i was clear. :)

CGTalk Moderation
02-04-2008, 01:11 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.