Kelvin T to Light Color

18 votes
Version: 
1.0
Date Updated: 
09/14/2009
Author Name: 
Dimitar Nenov

Hi,this is my first script so I will be happy to get some comments. With this script you can check the rgb color that match any Kelvin temperature from 1000 K to 10000 K. Also you can set that color to all selected lights.
The script can be found in Lights category of the user interface.

Video URL: 

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Letniq's picture

@woby I know the alghorithm

@woby

I know the alghorithm that I need to make It But I don't see the point why to have a massive array and formulas to calculate when I can use only one array of precalculated values. In that way I think I'm getting much better performance.

 

@Anubis 

What really helps is

 obj in lights where obj.isSelected

 

I didn't know how to refer only to the lights in selection :) 

 

 

Anubis's picture

Hi, again. Let me guess, now

Hi, again.
Let me guess, now you seek how to add support for VR lights to the code, right?
I don't use vray, so you should consult with the VR documentation, and finaly add it
as case in the code. Here's an example method:

for obj in lights where obj.isSelected do
(
	if <your_VR_check_here> then
	(obj.color = rgbcolor.color)
	else
	(if isProperty obj #rgb do obj.rgb = rgbcolor.color)
)

my recent MAXScripts RSS (archive here)

wobi's picture

Hi,   Nice script man. But

Hi,

 

Nice script man. But what about actually rendering the appropriate color instead of pulling the value from a pre-defined array? Just a thought.

You might wanna have a look at the mib_blackbody-Shader (mental ray base lib) which does exactly this. It renders the color based on the actual XYZ-Values of the spectral wavelenghts...

 

Find the code here:

ftp://ftp.mentalimages.com/pub/shaders/

(Download the "public-shaders-3.5.7.10.zip". Look into "shaders/public-baseshaders/" and open "baselight.cpp". There you will find the "mib_blackbody_init"-function which holds the necessary alghorithm along with the array which holds the CIE-XYZ-Values for the wavelengths from 380-780 NM)

 

Would be a cool script, wouldn't it? Of course, just a suggestion....

 

Greetz Ben

Letniq's picture

I call the "color" property

I call the "color" property because the vray lights use it instead of rgb.
I can use your way of checking the properties and make a performance update. I just didn't know that "try/ catch" is slow. :)
Thanks :)

Anubis's picture

Ok, about optimization, 1st

Ok, about optimization, 1st about storing data in your multi-dimentional array, I'm not sure, maybe you have somthing in mind, else I think you can store color as one item instead to separate it to R, G and B (3 items) and call at once, ie:

-- for exaple: #(1000, 255, 51, 0) will become:
#(1000, (color 255 51 0))
-- and assign will become:
rgbcolor.color = contentarray[kelvinslider.value][2] 

Also I always avoid "try/catch" for better performance. So the 2nd hint is about applying color to lights. Here needed some filter check to exclude non lights objects form selection. Also I see you call "rgb" and "color" properties at the same time. All Max built lights has both properties and they are equal, but for photometric is not. Here needed only rgb. But if the user has third party plugins, for example Brazil renderer, well, is not bad to exclude them too by checking for "rgb" property.

on applybutton pressed do
(
	for obj in lights where obj.isSelected do
		if isProperty obj #rgb do
			obj.rgb = rgbcolor.color
)

Now the code is compatible with Max built lights and debbuged :)
So, what's next? Someone, to say me (for example), wish to use the script with Brazil lights, I'll just extend it myself for my needs. Ok, I hope you like my ideas.

my recent MAXScripts RSS (archive here)

Letniq's picture

Hi, Panayot It will be great

Hi, Panayot
It will be great to give me some ideas for optimizing the code.

I spent two days searching the net for the best way of color matching the wavelenth to rgb. There were some formulas to calculate it but the result was bad. Finally It turns out that to get the correct rgb color for some light temperature I must use some array of values from CIE so I decided instead of having formulas and array to have just array.

Regards, Dimitar Nenov

Anubis's picture

Hi Dimitar, I am glad to see

Hi Dimitar,
I am glad to see fellow citizen here!

Good job for the first script. I did a quick search in Google and I found many results with hard coded Kelvin to RGB references, but maybe it will not be easy to find a conversion formula. It's very strange, right? I would say that you will come in a lot of trouble with this script :) In the meantime I found so you convert Kelvin (CIE 1931 2 degree CMFs) to sRGB. As a result of that there is a lot different RGB standards, would be nice if there was a formula, instead of they are all hard coded. Because you're interested, maybe you'll find something about.

As to your code, I have little idea of optimizing its and
If you're interested I'll post it here.

Regards, Anubis(Panayot)!

my recent MAXScripts RSS (archive here)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.