thread sorting for ray tracing