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

本文介绍了一种在Photoshop中调整图片亮度的方法,并提供了一个用于实现亮度调节功能的shader代码示例。该方法适用于不同原始亮度级别的图片,并能够根据所需的亮度偏移进行调整。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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_ES
precision mediump float;
#endif

#ifdef GL_ES
varying mediump vec2 v_texCoord;
#else
varying vec2 v_texCoord;
#endif

float 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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值