Shader Question

I’m pretty sure this will have to be done with a shader, but I’m not quite sure how to go about getting what I want it to do.

Basicly I want a black and white world, and when a object passes in front of or behind another object the overlapping part has its colors inverted. So like the image shows when there are just two objects being overlapped then you have the white in the black. Then when you get tot he point were there are more objects than that overlapped each section of over lapped would have its colors inverse.

Can those objects be in full 3d motion, or are they on separate distance “layers” from camera?
With separate layers you probably could do material that uses scene depth and some multipply with add combination for pixel color.
In situation when you cannot use distance from camera to determine their shapes (pixels) i have no idea how to get more than 2 to correctly overlap.
Thinking of it even layered distance works for 2 only. This is not trivial thing. You see if you overlap something, there is no information about pixels below it.

I am not sure but there should be pixel XOR (NOT OR) operation (is what your boxes do).
And there is topic with scene outline shader, it is kind of similar toy your problem, if i find that post i add link here.

Here is that link, maybe this will help:

The current setup does have the objects in full 3d motion. The objects are currently just particles being generated by a single plane and are moving up, however, the scale of each object is being dynamically set by an audio source. The plan was to have other objects that would also be moving around the scene as well, but not be limited like the current particles are.

I had asked a couple of tutors at my school about it, and they suggested I see about asking a teacher and posting to a forum with this question, as the only thing they could think of was using the camera position and doing a raycast from all the objects in view. Mind you they do not know much about writing shaders.

Thanks for the link, I’ll take a look at it.