{"id":44947861,"url":"https://github.com/acfr/gpu-ray-surface-intersection-in-cuda","last_synced_at":"2026-02-18T10:01:07.737Z","repository":{"id":143494560,"uuid":"533527554","full_name":"acfr/gpu-ray-surface-intersection-in-cuda","owner":"acfr","description":"A GPU-based ray-surface intersection test implemented in CUDA","archived":false,"fork":false,"pushed_at":"2024-04-08T23:12:02.000Z","size":3434,"stargazers_count":11,"open_issues_count":2,"forks_count":11,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-09-08T23:29:25.977Z","etag":null,"topics":["cuda","gpu"],"latest_commit_sha":null,"homepage":"https://arxiv.org/abs/2209.02878","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/acfr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2022-09-06T22:59:32.000Z","updated_at":"2025-08-02T13:16:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"2afdacd6-c4cd-4e61-aa7f-74ad9b9a86b9","html_url":"https://github.com/acfr/gpu-ray-surface-intersection-in-cuda","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/acfr/gpu-ray-surface-intersection-in-cuda","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acfr%2Fgpu-ray-surface-intersection-in-cuda","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acfr%2Fgpu-ray-surface-intersection-in-cuda/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acfr%2Fgpu-ray-surface-intersection-in-cuda/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acfr%2Fgpu-ray-surface-intersection-in-cuda/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/acfr","download_url":"https://codeload.github.com/acfr/gpu-ray-surface-intersection-in-cuda/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/acfr%2Fgpu-ray-surface-intersection-in-cuda/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29575343,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-18T08:38:15.585Z","status":"ssl_error","status_checked_at":"2026-02-18T08:38:14.917Z","response_time":162,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cuda","gpu"],"created_at":"2026-02-18T10:01:03.121Z","updated_at":"2026-02-18T10:01:07.732Z","avatar_url":"https://github.com/acfr.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GPU implementation of a ray-surface intersection algorithm in CUDA\r\n\r\nThis repository provides an open-source, GPU-based implementation of a ray-surface intersection algorithm in CUDA. The basic problem it solves is that given a set of rays (line segments) and a triangular mesh surface, it identifies the rays that cross the surface. For our use case, we are primarily interested in knowing whether an intersection has occured. However, the program can be configured to return the intersecting point and triangle for each intersecting ray. In our application, ray segments can point in arbitrary directions and do not originate from shared light sources.\r\n\r\nThis contribution is not geared towards game development or computer graphics per se. The motivation for writing this code is to speed up the solver relative to CPU-based implementations to increase productivity in an R\u0026D project, rather than achieving real-time rendering performance.\r\n\r\n\u003cimg src=\"doc/illustration.png\" alt=\"Rays in red intersect with the triangular mesh surface\" width=\"360\"/\u003e\u003cimg src=\"doc/code_snippet.png\" alt=\"Code snippet: a device function in bvh_structure.h\" width=\"360\"/\u003e\r\n\r\n\r\n### Key words\r\n\r\nMoller-Trumbore algorithm, ray-triangle intersection, linear bounding volume\r\nhierarchy, LBVH construction, binary radix tree, BVH traversal,\r\nbounding box collision detection, parallel computing, GPGPU, CUDA.\r\n\r\n\r\n## Audience\r\n\r\n- This post would offer little to experienced programmers who are already\r\n  skilled in general-purpose GPU computing, parallel algorithms and real-time ray tracing.\r\n- It might be of interest to people with limited CUDA programming\r\n  experience, and perhaps researchers/engineers looking for a \"ready-made\"\r\n  working implementation of a ray-surface intersection algorithm that\r\n  runs on Nvidia GPU devices.\r\n\r\n\r\n## Background\r\n\r\nThere are two technical components to the code. An exact algorithm for finding\r\nray-triangle intersections (such as the Moller-Trumbore algorithm) and\r\naccelerating data structures (such as bounding volume hierarchy or BVH [1])\r\nthat spares us from having to evaluate bounding box collision for every\r\npossible triangle and line-segment combination.\r\n\r\nIn regard to ray-triangle intersection tests, Jimenez et al. have analysed\r\nhalf a dozen algorithms, and determined the Moller-Trumbore to be the most\r\nefficient in a general setting. Those findings are reported in [2]. In\r\nregard to BVH, our implementation is inspired by the approaches described\r\nby Robbin Marcus [3] and Tero Kerras [4]. Their blog entries provide\r\npractical guidance and the necessary background for understanding this code.\r\nInterested readers are referred to these online resources for bridging material.\r\n\r\n\r\n## Usage\r\n\r\nThe three supported use cases are\r\n\r\n- \u003cb\u003eStandard usage (`mode=boolean`)\u003c/b\u003e\r\n  - This returns a boolean indicating whether or not each ray intersects with the surface.\r\n- \u003cb\u003eExtended usage (`mode=barycentric`)\u003c/b\u003e\r\n  - This returns the intersecting triangle and nearest intersecting point\r\n    for each surface intersecting ray.\r\n- \u003cb\u003eExperimental feature (`mode=intercept_count`)\u003c/b\u003e\r\n  - This returns the number of unique intersections with the surface for each ray. \r\n\r\nThe code is compiled with\r\n\u003cpre\u003e\u003ccode\u003e\u003cspan style=\"color:gray\"\u003e/usr/local/cuda/bin/\u003c/span\u003envcc gpu_ray_surface_intersect.cu -o gpu_ray_surface_intersect\r\n\u003c/code\u003e\u003c/pre\u003e\r\n\r\nand executed using\r\n\u003cpre\u003e\u003ccode\u003egpu_ray_surface_intersect \u003cspan style=\"color:blue\"\u003e\u0026lt;vertices\u0026gt; \u0026lt;triangles\u0026gt; \u0026lt;rayFrom\u0026gt; \u0026lt;rayTo\u0026gt;\u003c/span\u003e \u0026lt;feedback\u0026gt; \u0026lt;mode\u0026gt;\r\n\u003c/code\u003e\u003c/pre\u003e\r\n\r\nSetting `feedback=silent` suppresses terminal output.\r\nCommand line arguments for the three use cases are described in [Section 2.3](doc/gpu-rsi-doc.pdf#subsection.2.3) and [2.4](doc/gpu-rsi-doc.pdf#subsection.2.4).\r\n\r\nFor convenience, `scripts/py_gpu_ray_surface_intersect.py` implements a wrapper\r\nclass `PyGpuRSI` that encapsulates the functionality of `gpu_ray_surface_intersect.cu`.\r\nThe notebook `scripts/demo.ipynb` shows how data manipulation, compilation, run and\r\nclean-up steps can be managed using a `with` statement. To produce results in the\r\nform of `(intersecting_rays, distances, intersecting_triangles, intersecting_points)`\r\nin lieu of a `crossing_detected` binary array, please refer to Part B of `scripts/demo.ipynb`.\r\nExample of the last use case is shown in Part C of `scripts/experimental_feature.ipynb`.\r\n\r\n\r\n## Documentation\r\n\r\nThe [PDF document](doc/gpu-rsi-doc.pdf) provides an overall description of the\r\nimplementation and discusses issues such as collision buffer management.\r\nThe aim is to shed light on the more obscure parts of the code, and\r\nprovide some clarity on certain practical considerations that are sometimes\r\nomitted in discussion. Compilation instruction, usage command, CPU/GPU\r\nspecifications and run time measurements are also included for reference.\r\n\r\n\u003e A self-contained PyCUDA implementation is also available. PyCUDA provides a Python scripting approach to GPU Run-Time Code Generation. Refer to [pycuda/README.md](https://github.com/raymondleung8/gpu-ray-surface-intersection-in-cuda/tree/main/pycuda) for more information.\r\n\r\n\r\n## References\r\n\r\n- [1] Wikipedia, Bounding volume hierarchy. URL https://en.wikipedia.org/wiki/Bounding_volume_hierarchy\r\n- [2] Juan J Jiménez, Carlos J Ogáyar, José M Noguera, and Félix Paulano.\r\n    Performance analysis for GPU-based ray-triangle algorithms. In 2014\r\n    International Conference on Computer Graphics Theory and Applications,\r\n    pages 1–8. IEEE, 2014.\r\n- [3] Robbin Marcus. Real-time raytracing part 2.1. Published on 2015-10-29.\r\n    Available at http://robbinmarcus.blogspo.com/2015/12/real-time-raytracing-part-21.html.\r\n- [4] Tero Kerras. Thinking Parallel, Part II: Tree Traversal on the GPU.\r\n    Published on 2012-11-26. Available at https://developer.nvidia.com/blog/thinking-parallel-part-ii-tree-traversal-gpu.\r\n\r\n\r\n## License\r\n\r\n\u003e📋  This project is licensed under the terms of the [BSD 3-Clause](LICENSE.md) license.\r\n\r\nIf you find this code useful, you are welcome to cite this in your work:\r\n- Raymond Leung, GPU implementation of a ray-surface intersection algorithm in CUDA, arXiv e-print 2209.02878, 2022.  Source code available at: https://github.com/raymondleung8/gpu-ray-surface-intersection-in-cuda under a BSD 3 license.\r\n- The BibTeX entry may be copied from [here](doc/citation.bib).\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facfr%2Fgpu-ray-surface-intersection-in-cuda","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Facfr%2Fgpu-ray-surface-intersection-in-cuda","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Facfr%2Fgpu-ray-surface-intersection-in-cuda/lists"}