copy ray tracing algorithm from reference