I have a CIKernal of a threshold filter in GLSL like this:
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)); " +
"} "
)”
I want to check if pixel is white. Is there a simple command in GLSL to do this without extra computations?
Update** I want to get rid of luma calculation. So is there a way to check pixel being white without doing above luma calculation?
Th oixel is "white" if each of the the tree color channels is
>= 1.0
. This can be checked by testing if the sum of the color channels is 3.0. Of course it has to be ensured that the three color channels are limited to 1.0 first:or
In ths case
min(vec3(1.0), lightCol.rgb)
can be used instead ofclamp(lightCol.rgb, 0.0, 1.0)
too.If it is well known, that each of the three color channels is
<= 1.0
, then the expression can be simplified:Note, in this case the
dot
product calculates:and
luma
can be calculated as follows: