Skip to content

Add BVH acceleration for mesh intersection in CUDA path tracer - #1

Open
jichumao wants to merge 1 commit into
mainfrom
codex/add-bvh-support-to-cuda-path-tracer
Open

Add BVH acceleration for mesh intersection in CUDA path tracer#1
jichumao wants to merge 1 commit into
mainfrom
codex/add-bvh-support-to-cuda-path-tracer

Conversation

@jichumao

@jichumao jichumao commented Apr 7, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Reduce expensive per-mesh brute-force triangle traversal during ray intersections by adding a CPU-built BVH per mesh and using it in device intersection code.
  • Provide data structures and device buffers to upload a flattened BVH to CUDA so the path tracer can traverse the hierarchy on the GPU.

Description

  • Introduce BVH data structures and per-geom root index by adding bvhRootNodeIdx to Geom and a compact BVHNode layout suitable for device use (src/sceneStructs.h).
  • Add scene-level storage for flattened BVH arrays (std::vector<BVHNode> bvhNodes and std::vector<int> bvhTriIndices) and build a per-mesh BVH during glTF loading (src/scene.h, src/scene.cpp).
  • Replace linear triangle scanning with BVH stack traversal in meshIntersectionTest, and replace the previous AABB test with a robust slab-based implementation; update the function signature to accept BVH buffers (src/intersections.h, src/intersections.cu).
  • Upload BVH buffers to device memory and wire them into the intersection kernel and computeIntersections call, and free them on shutdown; enable BVH_ENABLED by default (src/pathtrace.cu, src/utilities.h).

Testing

  • Attempted a full build with cmake -S . -B build && cmake --build build -j4, which failed due to the environment lacking the CUDA toolkit / nvcc (so compilation could not be validated here).
  • No other automated tests were present or executed in this environment.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant