Shaders to regulate image lightness like in PhotoShop(shader实现Photoshop的亮度调节效果,按钮变暗效果)

来源:互联网 发布:传奇npc算法 编辑:程序博客网 时间:2024/06/10 12:56

We can regulate image lightness in photoshop like this (Ctrl+U):


I find it results in different end lightness for different original lightness and for different lighness offset you want to regulate.

And I make a formula which I have described in previous article here.

And the ratio of three channels of rgb is fixed when we only ajust lightness.

so here is the shader implement the lightness regulation function(image dim effect):

#ifdef GL_ESprecision mediump float;#endif#ifdef GL_ESvarying mediump vec2 v_texCoord;#elsevarying vec2 v_texCoord;#endiffloat L(float l, float x){return clamp((x + abs(x)) * 0.5 + l * (1.0 - abs(x)), 0.0, 1.0);}vec3 adjustLightness(vec3 rgb, float offset){float l = max(rgb.r, max(rgb.g, rgb.b));float e = 1.0e-6;return clamp(rgb*L(l,offset)/(l+e), 0.0, 1.0);}void main(){vec4 color = texture2D(CC_Texture0, v_texCoord);color.rgb = adjustLightness(color.rgb,-0.2);gl_FragColor = color;}


0 0
原创粉丝点击