我在 GLSL 中有一个阈值过滤器的 CIKernal,如下所示:
let thresholdKernel = CIColorKernel(string:
"kernel vec4 thresholdFilter(__sample pixel, float threshold)" +
"{ " +
" float luma = (pixel.r * 0.2126) + " +
" (pixel.g * 0.7152) + " +
" (pixel.b * 0.0722); " +
" return vec4(step(threshold, luma)); " +
"} "
)”
我想检查 像素 是白色的。 GLSL 中是否有一个简单的命令可以在没有额外计算的情况下执行此操作?
更新**
我想摆脱亮度计算。那么有没有办法在不进行上述亮度计算的情况下检查像素是否为白色?
最佳答案
如果每个树颜色 channel 为 >= 1.0
,则像素为“白色” .这可以通过测试颜色 channel 的总和是否为 3.0 来检查。当然首先要确保三个颜色 channel 限制在 1.0:
bool is_white = dot(vec3(1.0), clamp(lightCol.rgb, 0.0, 1.0)) > 2.999;
或者
float white = step(2.999, dot(vec3(1.0), clamp(lightCol.rgb, 0.0, 1.0)));
在这种情况下
min(vec3(1.0), lightCol.rgb)
可以用来代替clamp(lightCol.rgb, 0.0, 1.0)
也。如果众所周知,三个颜色 channel 中的每一个都是
<= 1.0
,则表达式可以简化为:dot(vec3(1.0), lightCol.rgb) > 2.999
注意,在这种情况下
dot
产品计算:1.0*lightCol.r + 1.0*lightCol.g + 1.0*lightCol.b
和
luma
可以计算如下:float luma = dot(vec3(0.2126, 0.7152, 0.0722), lightCol.rgb);
关于ios - 带有 GLSL 的 CIKernel 白色像素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50105716/