The main problem was with the hue. Hue shift is a 3D-vector rotation. Creating quaternion and converting them to the matrix is much heavier than Rodrigues rotation formula.
Use this shader and be happy.
There are just shader functions. I use this effect for NGUI sprites. Sprite color (tint) is used for passing Hue, brightness, contrast, saturation. But this is my situation. Functions can be used in any other shader.
Here is an example:
Note: you can do all that using a single operation.
Build a 3x3 matrix (color transform) and apply it to your vec3 RGB color.
colorRGB *= _Transform3x3;
The matrix can concatenate any number of operation in any order.
And is not llimited hue (luminance preserving or not), levels, contrast, saturation, etcā¦
Matrix applying is one operation. But creation of this matrix is not. I used matrix for hue transformation. Creation of transform matrix had too many operations. I converted quaternion to matrix. Shader didnāt work on some android devices.
Yes, but the good part is that building the matrix is done outside the pixel shader.
This saves a tremendous amount of pixel shader computation. Build matrix once, apply to all pixel.
You are right, sschaem. Iāll try to implement this for NGUI sprites. It should be a good challenge. Itās much easier to use already existed tint color for passing hsb parameters. But easiest is not always the best.
I did a contrast shader a while back that had the advantage of being less destructive. You current solution should clamp very quickly. A simple workaround is to apply a āSā curve like you would in photoshop, with a simple remap of the range and a power 3 (valvalval), then to modulate the intensity (at the time I used the lerp() like you did for saturation).
@Andrey-Postelzhuk Contrast degradation is when the contrast of an image/surface becomes darker the greater the viewing angle is from the center of the object.
So if youāre viewing a tv straight on youāll see 100% contrast, but as you move to an angle letās say a 45 degree angle, then the contrast drops (degrades) to 50%. I guess really I need a shader that changes the contrast of the colors on the surface of an object based on the camera viewing angle.