Not a solution to your problem, but I have an alternative method for the cartoon shader.
It’s not really finished, but I won’t do much on it, because I just did this for fun on the side. Maybe someone can improve on it or gain some ideas with this.
The basic Idea was to take the Scene and the Base Color of the Scene and divide them so that you can get a multiplicator for the base color.
everything below 1 is darker than the base color (shadows), everything above 1 is lighter (highlights, emissive)
So the first step is
(PostProcessingInput0 / Base Color)
This output now needs to be modified. I seperate the shadow and Highlight components of this output by having one branch go through a Clamp (Min=0, Max = 1) node. Then I multiply it by the number ob bands I want to have for shadows, use Ceil and then Divide them to undo the Multiplication. This would create your Multiplier for the toon shadows. I also didn’t like to have completly black shadows so I used a Max (0.1) node to make everything below 0.1 to 0.1. You can change that number untill the really dark shadows are the way you like them.
For the Highlight part I subtracted 1 from the output of the division and then used Max (,0) to remove the negative part. So now he highlights go from 0 to 1. This way I can later just add them to the shadow multiplier before I multiply it back to the base color. This Highlight part also needs to be modified. The way you do this is similar to the shadows. Multiply (this time make this number below 1 because the highlight multiplier can have high values, just tweak it untill you like it) and them convert them to int using Ceil or Floow, then divide with the same number you used for the multiplication to undo the previous Multiplication. I then use a upper limit for the Highlights using Min.
Since the Highlights add color I had some strange looking behaviour, so I had to desaturate the output before I combined the shadows and highlights.
The last step is to add the two components and then Multiply them with the Base Color. This is your toon shader.
Just to give it more plasticity I also added a Lerp so I can blend the original shading and the toon shader, so get some of the more detailed shadows for edges. And finally I also used Custom Depth to be able to control which Assets should use the toon shader.
The result looks like this:
http://91.228.52.204/~Tomura/images/ue4/toonshader03.png
Problems:
I think for the shadows this works very good, but the emissive part definetly has problems since I had to desaturate in order to keep the colors from going crazy. If someone can figure out a way to keep that from happening while still keeping the color information that would be great. Another problem would be parts that are completly Black in their base color since this would mean a 0/0 division. Clamping can help to make this look ok, but the is a loss in information. Maybe using addition instead of Multiplication could be a better way for the highlights/emissive parts.
Another solution to make a toon shader might also be to just limit the color palette and use the nearest color. I haven’t tried this, yet.
Another solution I’m thinking of could be converting the colors into HSV format. With this RGB solution regardless of additive or multiplicative there were problems when I had different colored Highlights (e.g. white highlight on Red surface means it just adds blue and green). With HSV you’d have the lighter or darker than Base Color information in the V component. So you could just modify that then use the toon V and convert it back to RGB.
This way there could be way less problems with new colors being added in a strange way after using ceil or floor.
I hope this approach that is a bit different to the other one that was posted here is helpful. Maybe someone an find a good solution for this.