Mark~
HSV and HLS color systems are problematic for a number of reasons. I talked with a color scientist about this recently, and his recommendation was to convert to YIQ or YCbCr space and adjust the the chroma channels (I&Q, or Cb&Cr) accordingly. (You can learn how to do that here and here.)
Once in one of those spaces, you can get the hue from the angle formed by the chroma channels, by doing hue = atan(cr/cb) (watching for cb == 0). This gives you a value in radians. Simply rotate it by adding the hue rotation amount. Once you've done that, you can calculate the magnitude of the chroma with chroma = sqrt(cr*cr+cb*cb). To get back to RGB, calculate the new Cb and Cr (or I & Q) using Cr = chroma * sin (hue), Cb = chroma * cos (hue). Then convert back to RGB as described on the above web pages.
EDIT: Here's a solution that I've tested and seems to give me the same results as your reference. You can probably collapse some of the dot products into matrix multiplies:
uniform sampler2DRect inputTexture;
uniform float hueAdjust;
void main ()
{
const vec4 kRGBToYPrime = vec4 (0.299, 0.587, 0.114, 0.0);
const vec4 kRGBToI = vec4 (0.596, -0.275, -0.321, 0.0);
const vec4 kRGBToQ = vec4 (0.212, -0.523, 0.311, 0.0);
const vec4 kYIQToR = vec4 (1.0, 0.956, 0.621, 0.0);
const vec4 kYIQToG = vec4 (1.0, -0.272, -0.647, 0.0);
const vec4 kYIQToB = vec4 (1.0, -1.107, 1.704, 0.0);
// Sample the input pixel
vec4 color = texture2DRect (inputTexture, gl_TexCoord [ 0 ].xy);
// Convert to YIQ
float YPrime = dot (color, kRGBToYPrime);
float I = dot (color, kRGBToI);
float Q = dot (color, kRGBToQ);
// Calculate the hue and chroma
float hue = atan (Q, I);
float chroma = sqrt (I * I + Q * Q);
// Make the user's adjustments
hue += hueAdjust;
// Convert back to YIQ
Q = chroma * sin (hue);
I = chroma * cos (hue);
// Convert back to RGB
vec4 yIQ = vec4 (YPrime, I, Q, 0.0);
color.r = dot (yIQ, kYIQToR);
color.g = dot (yIQ, kYIQToG);
color.b = dot (yIQ, kYIQToB);
// Save the result
gl_FragColor = color;
}
引用
http://stackoverflow.com/questions/9234724/how-to-change-hue-of-a-texture-with-glsl
分享到:
相关推荐
高斯模糊是一种图像模糊滤波器,它用正态分布计算图像中每个像素的变换。
cocos2d-x实战项目 01.cocos2d-x原理及环境配置.rar 03.cocostudio使用方法及UI控制.rar 04.XML文件读取与骨骼动画.rarcocos2d-x实战项目 01.cocos2d-x原理及环境配置.rar 03.cocostudio使用方法及UI控制.rar 04.XML...
cocos2d-x进阶教程1_1搭建和配置Lua开发...cocos2d-x进阶教程1_7LuaTable使用2.mp4 cocos2d-x进阶教程1_8LuaTable使用3.mp4 cocos2d-x进阶教程1_9LuaTable读写数据文件.mp4 cocos2d-x进阶教程1_10在Lua中实现串行化.mp4
Cocos2d-x 2.X实现的一基于CCLabelTTF + Shader的字体描边效果,具体可以参考这篇博客,http://blog.csdn.net/oktears/article/details/43200757
cocos2dx3.x_shader仅供学习
iOS实例开发源码——lhunath-Cocos2D-iPhone.old-9ab3d34.zip
cocos2d-0.99.4-x-0.7.1.zip
原文地址:http://blog.csdn.net/teng_ontheway/article/details/39190919
kbengine-cocos2dx-cocos2dx-consoft.zip.针对kbengine引擎的cocos端 官方demo
精通COCOS2D-X游戏开发 精通COCOS2D-X游戏开发 精通COCOS2D-X游戏开发 精通COCOS2D-X游戏开发 精通COCOS2D-X游戏开发
cocos2dx游戏实例源码,大概有三十种游戏
iOS游戏应用源代码——lhunath-Cocos2D-iPhone.old-9ab3d34.zip
cocos2d-js 开发插件,idea插件 cocos-intellij-plugin-2.0.0-beta.zip
│ cocos2dx-3.10-api.lua │ cocos2dx-3.11-api.lua │ cocos2dx-3.12-api.lua │ cocos2dx-3.6-api.lua │ cocos2dx-3.7-api.lua │ cocos2dx-3.7.1-api.lua │ cocos2dx-3.8-api.lua │ cocos2dx-3.8.1-api.lua ...
cocos2d-x权威指南前三章-第三章.Cocos2D-x_中的核心类.pdf
基于libqrencode实现的显示二维码的控件,使用DrawNode绘制显示区。
Get a gentle introduction to the Cocos2d-JS framework to begin working with sprite manipulations, animations, and other 2d game development topics. This book covers environment setup and getting ...
cocos2d接口说明-0.99.4-x-0.7.0-api-reference
方头像裁剪为圆头像,cocos2dx中,使用shader实现该功能~
cocos2dx-CCHttpClient网络编程实例 VS2010 cocos2d-x v2.2.0