问题
Is their any GLSL shader that can help me to "boost" the color of a texture ? How to write such shader ? I would like to do something like the picture below :
回答1:
It seems they are mostly boosting saturation here, so that's what you'd need to do in your fragment shader.
To boost saturation, you need to take your data from the RVB color space to the HSL (hue saturation lightness) space. you then need to do:
hslColor = vec3(hslCOlor.x, hslColor.y * **boost**, hslCOlor.z);
Of course to do that you actually need to get into the right color space. This isn't really an openGL issue, I found this website that does the convertion:
https://www.rapidtables.com/convert/color/rgb-to-hsl.html
They also give formulas for the conversion:
R' = R
G' = G
B' = B
Cmax = max(R', G', B')
Cmin = min(R', G', B')
Δ = Cmax - Cmin
L = (Cmax + Cmin) / 2
THat way you can get HSL from RVB. Once you've done your saturation boost, you need to take your colros back to RVB colorspace
it'ssa good news that the same website seem to offer the same capabilities! https://www.rapidtables.com/convert/color/hsl-to-rgb.html
When 0 ≤ H < 360, 0 ≤ S ≤ 1 and 0 ≤ L ≤ 1:
C = (1 - |2L - 1|) × S
X = C × (1 - |(H / 60°) mod 2 - 1|)
m = L - C/2
(R,G,B) = ((R'+m), (G'+m),(B'+m))
I removed the 255 from their formulas because usually you work on [0,1] in GLSL.
With this you should be able to do all sort of transformations on the colors to manipulate them in a way that is similar to the simple tools of photoshop.
EDIT it should be noted that I mostly talked about boosting saturation, but they might be doing stuffs significantly more complex in your exemple. But working in HSL will still be a good thing to do if you are working with colors to edit photographs.
来源:https://stackoverflow.com/questions/50965644/glsl-shader-to-boost-the-color