I have some code to separate shadows, mids and highlights based on intensity... now normally one would say this will work 100%...
grey=saturate(dot(color.xyz, 0.33333333))
highlights=grey*grey
shadows=(1-grey)*(1-grey)
midtones=1-highlights-shadows
then I do some multiplicative tinting on shadow and midtones layers and recombine them as
result=midtones+shadows+highlights
now this should work, shouldn't it? Guess not.
In the higher intensities one gets some pixels pure black as if they have been skipped. The missing pixels are so selective that it has to be 1 certain intensity value being missed.
Now if I change the math to
highlights=grey
shadows=1-grey
and keep everything else the same, no such issue exists.
I can also do
highlights=grey*grey
shadows=1-highlights
and also fine.
Im pretty puzzled why doing the first method creates those black dots, besides using 1 more layer there's nothing different. Every math I throw against that formula gives the correct output, yet in game I get some black pixels.
Is this some precision/rounding error? if so, does anyone know a fix that doesn't cause other bugs, or should I consider recoding the whole thing with using the results of shadows, mids, highlights as interpolation factors on a lerp?
I rather keep the code as it is now as the results are pretty
![Wink ;)](./images/smilies/wink.gif)
Here's a shot where you see clearly the black pixels
![Image](https://farm8.staticflickr.com/7551/16087320070_1f86cf7dfe_o.jpg)