问题描述
他们是否有任何可以帮助我增强"纹理颜色的GLSL着色器?如何编写这样的着色器?我想做类似下面的图片:
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 :
推荐答案
似乎它们在这里主要是提高饱和度,因此这就是您在片段着色器中需要执行的操作.
It seems they are mostly boosting saturation here, so that's what you'd need to do in your fragment shader.
要提高饱和度,您需要将数据从RVB颜色空间移至HSL(色相饱和度亮度)空间.然后您需要执行以下操作:
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);
当然,您实际上需要进入正确的色彩空间.这不是一个真正的openGL问题,我发现这个网站可以进行转换:
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')
Cmax = max(R', G', B')
Cmin = min(R',G',B')
Cmin = min(R', G', B')
Δ= Cmax-Cmin
Δ = Cmax - Cmin
L =(Cmax + Cmin)/2
L = (Cmax + Cmin) / 2
通过这种方式,您可以从RVB获取HSL.完成饱和度提升后,您需要将颜色恢复到RVB色彩空间
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
好消息是,同一网站似乎提供相同的功能! https://www.rapidtables.com/convert/color/hsl- to-rgb.html
it'ssa good news that the same website seem to offer the same capabilities!https://www.rapidtables.com/convert/color/hsl-to-rgb.html
当0≤H< 360,0≤S≤1和0≤L≤1:
When 0 ≤ H < 360, 0 ≤ S ≤ 1 and 0 ≤ L ≤ 1:
C =(1-| 2L-1 |)×S
C = (1 - |2L - 1|) × S
X = C×(1-|(H/60°)mod 2-1 |)
X = C × (1 - |(H / 60°) mod 2 - 1|)
m = L-C/2
m = L - C/2
(R,G,B)=((R'+ m),(G'+ m),(B'+ m))
(R,G,B) = ((R'+m), (G'+m),(B'+m))
我从他们的公式中删除了255,因为通常您在GLSL中使用[0,1].
I removed the 255 from their formulas because usually you work on [0,1] in GLSL.
借助此功能,您应该能够对颜色进行各种转换,以类似于photoshop简易工具的方式来操纵它们.
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.
编辑,应该注意的是,我主要谈论的是提高饱和度,但是在您的例子中,他们可能所做的事情要复杂得多.但是,如果您要使用颜色来编辑照片,那么在HSL中工作仍然是一件好事.
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.
这篇关于GLSL着色器可增强色彩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!