Perhaps you could use a cube mask to change the material where it intersects a cube. This sort of idea: