Wednesday, April 7, 2010

Color blend mode that used in photoshop and gimp

chatting with my colleague one day regarding skin color selection for avatar creation and customization in rpg game. one of the solution is to create 1 skin color per texture which is obviously very labor intensive. one of my artist colleague suggested to use photoshop color blend mode to create different skin tone. so artist only need to create a gray scale image for the skin tone and the game is client enough to tint color to the grayscale texture. great idea, it works perfectly in photoshop, but how to do it in game client in realtime? after much reading the internet, most of the algorithm were very hard to understand my programmer, because those algorithms were based on HSV (hue, saturation and value) or HSL (hue, saturation and luminance). but for us programmer, all we had is RGB!

after googling awhile i found a great article, it shown the operation in term of rgb, and it is easier to understand than the algorithm based on HSV or HSL.

the basic steps for color blend mode
1) assign 2 textures to the program, a base and a source texture
2) calculate grayscale (luminance) value of both base and source textures
3) base illuminace minus away source luminance to get delta luminance
4) result color will be source color's rgb = source color's rgb + delta luminance.

that's all!

No comments: