Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
314 views
in Technique[技术] by (71.8m points)

opengl - GLSL shader to boost the color

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 :

enter image description here

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

enter image description here

enter image description here

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

enter image description here

(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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...