这个其实挺简单的直接取平均就好了
void main()
{
color = texture(screenTexture, TexCoords);
float average = (color.r + color.g + color.b) / 3.0;
color = vec4(average, average, average, 1.0);
}
但是人眼趋向于对绿色更敏感,对蓝色感知比较弱,所以我们对颜色的g、b 通道进行调整以更符合人眼对色彩的感知
void main()
{
color = texture(screenTexture, TexCoords);
float average =
0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b;
color = vec4(average, average, average, 1.0);
}