1.效果图

2.shader
"precision highp float;\n" +
"\n" +
"varying vec2 textureCoordinate;\n" +
"\n" +
"uniform sampler2D inputImageTexture;\n" +
"\n" +
"const highp vec3 W = vec3(0.2125, 0.7154, 0.0721);\n" +
"\n" +
"void main()\n" +
"{\n" +
" lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" +
" float luminance = dot(textureColor.rgb, W);\n" +
"\n" +
" gl_FragColor = vec4(vec3(luminance), textureColor.a);\n" +
"}";
3.原理
dot()函数
dot(x, y): 点积,各分量分别相乘 后 相加;
给定两个n维向量a=(a1,a2,…,an)和b=(b1,b2,…,bn),求点积a·b=a1b1+a2b2+…+anbn
该文介绍了一段GLSLshader代码,用于计算图像像素的亮度。通过点积运算求得每个像素的亮度值,使用向量W(0.2125,0.7154,0.0721)作为权重,然后设置gl_FragColor为亮度向量和原alpha值的组合。
273

被折叠的 条评论
为什么被折叠?



