前言:才想起写一个这个文档,前期内容较少,其他内容,我也只会想起来加一加!
材质功能大全
- 竖直百分比进度
- HSV To RGB
- RGB转灰度值
- AlphaComosote(Premultiplied Alpha)预乘 转 Translucent (sRGB与Pre-Multiplied Alpha)
竖直百分比进度
HSV To RGB
// H, S, V
H = H * 360;
float C = V * S;
float X = C * (1 - abs((H/60)%2 - 1));
float m = V - C;
float RR = 0;
float GG = 0;
float BB = 0;
if (H >= 0 && H < 60)
{
RR = C;
GG = X;
BB = 0;
}
else if (H >= 60 && H < 120)
{
RR = X;
GG = C;
BB = 0;
}
else if (H >= 120 && H < 180)
{
RR = 0;
GG = C;
BB = X;
}
else if (H >= 180 && H < 240)
{
RR = 0;
GG = X;
BB = C;
}
else if (H >= 240 && H < 300)
{
RR = X;
GG = 0;
BB = C;
}
else
{
RR = C;
GG = 0;
BB = X;
}
return float3(RR+m, GG+m, BB+m);
RGB转灰度值
float red = color.r * 0.299f;
float green = color.g * 0.587f;
float blue = color.b * 0.114f;
return red + green + blue;
AlphaComosote(Premultiplied Alpha)预乘 转 Translucent (sRGB与Pre-Multiplied Alpha)
注:RetainBox输出颜色是AlphaComosote(Premultiplied Alpha类型的,直接用它计算颜色透明度,有问题)
国外文档参考
国内文档参考
转换原理:
假设画布为B,前景图层为A,A的不透明度为alpha,融合后输出图像为C,那么alpha blending公式如下
C_r = A_r * alpha + B_r * (1 - alpha)
C_g = A_g * alpha + B_g * (1 - alpha)
C_b = A_b * alpha + B_b * (1 - alpha)
推导得我们需要的结果: