亮度饱和度和对比度的计算
Unity Shader入门精要学习记录
灰度像素的值计算为相应的红色,绿色和蓝色像素的加权总和,如下所示:
Y = 0.2125 R + 0.7154 G + 0.0721 B
固定值参考
http://poynton.ca/PDFs/ColorFAQ.pdf](http://poynton.ca/PDFs/ColorFAQ.pdf) ColorFAQ.pdf
sampler2D _MainTex;
half _Brightness;
half _Saturation;
half _Contrast;
fixed4 frag(v2f i) : SV_Target
{
//获取原屏幕图像的采样结果
fixed4 renderTex = tex2D(_MainTex,i.uv);
//调整亮度乘以系数即可
fixed3 finalCol = renderTex.rgb * _Brightness;
//计算该像素对应的亮度值,通过对每个颜色分量乘以一个特定的系数相加得到
fixed luminance = 0.2125 * renderTex.r + 0.7154 * renderTex.g + 0.0721 * renderTex.b;
//使用亮度值创建一个饱和度为0的颜色值
fixed3 luminanceCol = fixed3(luminance,luminance,luminance);
//颜色之间进行插值,从而得到希望的饱和度颜色
finalCol = lerp(luminanceCol,finalCol,_Saturation);
//创建一个对比度为0的颜色值(各分量均为0.5)
fixed3 avgCol = fixed3(0.5,0.5,0.5);
//使用饱和度属性对颜色进行插值得到最终的结果
finalCol = lerp(avgCol,finalCol,_Contrast);
return fixed4(finalCol,renderTex.a);
}
MSDN YUV To RGB
https://docs.microsoft.com/en-us/previous-versions/windows/embedded/ms893078(v=msdn.10)?redirectedfrom=MSDN