Mesh masking/clipping – probably shader based?

Hi Guys,



I need some guidance on how to solve a fairly simple problem, I just can’t quite get the solution on my own.



Here is the scenario …

http://img6.imageshack.us/img6/3039/cubes.png

A - 2 Cubes of the same size, same location, one red one blue. The blue one is not visible.

B - a cube to do the masking/clipping, this cube will never be visible .



I want the green cube to hide the red cube, and reveal the blue cube, make sense ?



I’m not trying to do a boolean operation on the mesh, which is why i figure the solution lies in a shader. I think i need to somehow call discard in the vertex shader for the 2 coloured cubes, based the masker cube which needs to be passed in as a uniform … or something. That or somehow using the render queue, because I recently almost did this by using transparent materials that were no placed in the correct Bucket.



Thanks for your time.

James