cocos2d / cocos2d-objc

Cocos2d for iOS and OS X, built using Objective-C
http://www.cocos2d-objc.org
Other
4.07k stars 1.16k forks source link

CCEffectHue doesn't work as expected? #1038

Closed iMobCoding closed 10 years ago

iMobCoding commented 10 years ago

Noticed that CCEffectHue doesn't give me the same results as photoshop. So I checked with plane red color sprite (255,0,0) and set the hue to 120. It should produce the green sprite (0,255,0) but instead it produces (0,187,0) green color. Also with hue -120 it produces (24,42,255) instead of pure blue

slembcke commented 10 years ago

The CCEffectHue performs the hue rotation in the YIQ color space (which is linear) while Photoshop uses the HSV color space (which is non-linear).

Both are valid methods, but they do have different results. YIQ preserves luminance, HSV has simplex output and avoids over-saturation. The main reason why the YIQ method was chosen was because it's a simple linear transform and is very GPU friendly. Conversion to HSV and back in a fragment shader would probably be an order of magnitude less efficient.

iMobCoding commented 10 years ago

Ok got it, but the reason why I am using Hue Effect is to reduce final app size by re-using same backgrounds/sprites with different hues. Now I have a problem as most designers use photoshop, so my designer too, and he gave me precise instructions on hue alterations, which definitely differ from what he intended to achieve. Do you have any suggestion how to simulate YIQ in photoshop so I can give him instructions about correct hue values I could actually use in the game?