Use a depth buffer :)