public int Compare(object x, object y) { if (x == null || y == null) { return(0); } // if they are the same, return 0 if (x == y) { return(0); } RenderablePass a = x as RenderablePass; RenderablePass b = y as RenderablePass; float adepth = a.renderable.GetSquaredViewDepth(camera); float bdepth = b.renderable.GetSquaredViewDepth(camera); if (adepth == bdepth) { if (a.pass.GetHashCode() < b.pass.GetHashCode()) { return(1); } else { return(-1); } } else { // sort descending by depth, meaning further objects get drawn first if (adepth > bdepth) { return(1); } else { return(-1); } } }