{"id":34983160,"url":"https://github.com/samchenyu/bvh-tree","last_synced_at":"2026-05-21T18:01:44.402Z","repository":{"id":288589776,"uuid":"968344362","full_name":"SamChenYu/BVH-Tree","owner":"SamChenYu","description":"Bounding Volume Hierarchy Implementation","archived":false,"fork":false,"pushed_at":"2025-04-26T12:10:13.000Z","size":29,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-26T12:29:01.149Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SamChenYu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-17T23:30:48.000Z","updated_at":"2025-04-26T12:10:17.000Z","dependencies_parsed_at":"2025-04-19T00:50:13.135Z","dependency_job_id":null,"html_url":"https://github.com/SamChenYu/BVH-Tree","commit_stats":null,"previous_names":["samchenyu/bvh-tree"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/SamChenYu/BVH-Tree","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamChenYu%2FBVH-Tree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamChenYu%2FBVH-Tree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamChenYu%2FBVH-Tree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamChenYu%2FBVH-Tree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SamChenYu","download_url":"https://codeload.github.com/SamChenYu/BVH-Tree/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SamChenYu%2FBVH-Tree/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28067209,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-26T02:00:06.189Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2025-12-27T01:09:27.752Z","updated_at":"2025-12-27T01:09:28.186Z","avatar_url":"https://github.com/SamChenYu.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BVH-Tree\n\nA Bounding Volume Hierarchy Tree is a data structure used to accelerate ray casting intersections in graphics. Instead of looping through each geometry in linear time, a BVH Tree groups each primitive via their bounding boxes. As the BVH Tree is traversed, the bounding volumes get tighter allowing groups of objects to be culled from the intersection tests.\n\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/user-attachments/assets/7c15511b-ba37-4412-9c80-5400afcffc62\" /\u003e\n  \u003cp\u003ehttps://pbr-book.org/3ed-2018/Primitives_and_Intersection_Acceleration/Bounding_Volume_Hierarchies \u003c/p\u003e\n\u003c/div\u003e\n\n\n\n\n## BVH Building Process\n\n1. ```List\u003cTriangle\u003e primitives ``` is initialised, containing all geometry data.\n2. ```List\u003cPrimitiveInfo\u003e primitiveInfo ``` is computed =\u003e calculating the bounding boxes, centroid of the bounding box and recording the indices of each entry in```primitives```.\n3. ```BVHNode BuildRecursive() ``` Partitioning is done on ```primitiveInfo``` - which Triangles go left or right in the split. Once a Leaf Node is created, you copy triangles from ```primitives``` into ```orderedPrimitives``` list in the order dictated by ```primitiveInfo```. ```orderedPrimitives``` becomes the new reordered list in the BVH =\u003e each leaf node only stores an offset and count in the array so it knows which triangles exactly to check during traversal. \n4. BVH Tree computation can now begin, with 3 SplitMethods - EqualCounts, Middle and SAH (Surface Area Heuristics)\n\n### Equal Counts (Todo)\n1. Pick the axis with the largest centroid extent, then sort all primitives by their centroid's coordinate on that axis, then split the list in half by number of primitives\n\n\n### Middle\n\n1. Compute the midpoint of the centroid's bounding box along the split axis (X, Y, Z)\n2. Loop through ```primitiveInfo``` and move all the primitives with centroids less than the midpoint to one side\n\n### SAH (Todo)\n\n## Tree Traversal\nOnce the BVH Tree has been computed, a depth first search + ray intersection is used for traversal.\nThe currently implemented ray intersection only tests for the primitive's bounding box, not the actual geometry itself.\n\n\n## Sample Output\n```\nTriangle 1 at (0, 1, 0), (3, 2, 0), (1, 4, 0)\nTriangle 2 at (2, 5, 0), (4, 6, 0), (5, 7, 0)\nTriangle 3 at (5, 7, 0), (6, 7, 0), (7, 6, 7)\nTriangle 4 at (4, 6, 0), (5, 8, 0), (6, 9, 0)\nTriangle 5 at (10, 15, 1), (11, 14, 0), (12, 13, 0)\n\nRay cast at Origin(11,15,1) Direction (0,0,1)\n\n\nDepth: 0 :  \u003c\u003c(Interior [Axis: 1, Bounds: Min: (0, 1, 0), Max: (12, 15, 7)])\u003e\u003e \nDepth: 1 :  \u003c\u003c(Interior [Axis: 1, Bounds: Min: (0, 1, 0), Max: (5, 7, 0)])\u003e\u003e  \u003c\u003c(Interior [Axis: 1, Bounds: Min: (4, 6, 0), Max: (12, 15, 7)])\u003e\u003e \nDepth: 2 :  \u003c\u003c(Leaf [0 - 1] [Bounds: Min: (0, 1, 0), Max: (3, 4, 0)]])\u003e\u003e  \u003c\u003c(Leaf [1 - 2] [Bounds: Min: (2, 5, 0), Max: (5, 7, 0)]])\u003e\u003e  \u003c\u003c(Leaf [2 - 3] [Bounds: Min: (5, 6, 0), Max: (7, 7, 7)]])\u003e\u003e  \u003c\u003c(Interior [Axis: 1, Bounds: Min: (4, 6, 0), Max: (12, 15, 1)])\u003e\u003e \nDepth: 3 :  \u003c\u003cNULL\u003e\u003e  \u003c\u003cNULL\u003e\u003e  \u003c\u003cNULL\u003e\u003e  \u003c\u003cNULL\u003e\u003e  \u003c\u003cNULL\u003e\u003e  \u003c\u003cNULL\u003e\u003e  \u003c\u003c(Leaf [3 - 4] [Bounds: Min: (4, 6, 0), Max: (6, 9, 0)]])\u003e\u003e  \u003c\u003c(Leaf [4 - 5] [Bounds: Min: (10, 13, 0), Max: (12, 15, 1)]])\u003e\u003e \n\nHits:\nRay Hit with Triangle 5\n\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamchenyu%2Fbvh-tree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamchenyu%2Fbvh-tree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamchenyu%2Fbvh-tree/lists"}