z-buffering with RAM megafunction