{"id":13732053,"url":"https://github.com/lighttransport/nanort","last_synced_at":"2025-05-14T19:02:41.821Z","repository":{"id":1938979,"uuid":"43081015","full_name":"lighttransport/nanort","owner":"lighttransport","description":"NanoRT, single header only modern ray tracing kernel.","archived":false,"fork":false,"pushed_at":"2025-03-08T19:36:26.000Z","size":91982,"stargazers_count":1096,"open_issues_count":9,"forks_count":92,"subscribers_count":60,"default_branch":"release","last_synced_at":"2025-04-06T08:08:49.154Z","etag":null,"topics":["bdpt","bvh","pathtracing","ray","raytracing"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lighttransport.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2015-09-24T17:08:21.000Z","updated_at":"2025-04-03T07:59:23.000Z","dependencies_parsed_at":"2023-02-19T07:30:40.323Z","dependency_job_id":"f0149ae1-5819-4282-b866-5485d90abcc9","html_url":"https://github.com/lighttransport/nanort","commit_stats":{"total_commits":451,"total_committers":24,"mean_commits":"18.791666666666668","dds":0.270509977827051,"last_synced_commit":"0bb8ab5284ee8ab7e75705aaedeaea7d7e63e1fe"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lighttransport%2Fnanort","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lighttransport%2Fnanort/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lighttransport%2Fnanort/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lighttransport%2Fnanort/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lighttransport","download_url":"https://codeload.github.com/lighttransport/nanort/tar.gz/refs/heads/release","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248710348,"owners_count":21149185,"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","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":["bdpt","bvh","pathtracing","ray","raytracing"],"created_at":"2024-08-03T02:01:44.939Z","updated_at":"2025-04-13T11:45:08.149Z","avatar_url":"https://github.com/lighttransport.png","language":"C++","funding_links":[],"categories":["Geometry, Graphics Processing, and Game Development","C++","Graphics"],"sub_categories":[],"readme":"# NanoRT, single header only modern ray tracing kernel.\n\n[![Travis Build Status](https://travis-ci.org/lighttransport/nanort.svg)](https://travis-ci.org/lighttransport/nanort)\n[![AppVeyor Build status](https://ci.appveyor.com/api/projects/status/k7j5d9v81qjm69j6?svg=true)](https://ci.appveyor.com/project/syoyo/nanort)\n\n![](images/render_path_traced.png)\n\nPath tracing example contributed by https://github.com/daseyb\n\n`NanoRT` is simple single header only ray tracing kernel.\n\n## Features\n\n* Portable C++\n  * Only use C++-03 features by default.\n  * C++11 feature(threads) is also available\n  * There is experimental C89 port of NanoRT in `c89` branch https://github.com/lighttransport/nanort/tree/c89\n* BVH spatial data structure for efficient ray intersection finding.\n  * Should be able to handle ~10M triangles scene efficiently with moderate memory consumption\n* Custom geometry \u0026 intersection\n  * Built-in triangle mesh gemetry \u0026 intersector is provided.\n* Cross platform\n  * MacOSX, Linux, Windows, iOS, Android, ARM, x86, SPARC, (maybe) MIPS, (will be) RISC-V, etc.\n  * For example, NanoRT works finely on Raspberry Pi 2 (arm 32bit) and Raspberrry Pi 3!(AARCH64 kernel)\n* GPU efficient data structure\n  * Built BVH tree from `NanoRT` is a linear array and does not have pointers, thus it is suited for GPU raytracing (GPU ray traversal).\n* OpenMP multithreaded BVH build.\n* Robust intersection calculation.\n  * Robust BVH Ray Traversal (using up to 4 ulp version): http://jcgt.org/published/0002/02/02/\n  * Watertight Ray/Triangle Intesection: http://jcgt.org/published/0002/01/05/\n* Double precision support\n  * Beneficial for HPC and scientific visualization.\n\n## Applications\n\n* Test renderer for your light transport algorithm development.\n* Test renderer for your shader language development.\n* Collision detection (ray casting).\n* BVH builder for GPU/Accelerator ray traversal.\n* Add 2D/3D rendering feature for non-GPU system.\n  * [ ] ImGui backend? https://github.com/syoyo/imgui/tree/nanort\n  * [ ] Nano SVG backend? https://github.com/syoyo/nanovg-nanort\n\n## Projects using NanoRT\n\n* lightmetrica https://github.com/hi2p-perim/lightmetrica-v2\n* OSPRay NanoRT module https://github.com/jeffamstutz/module_nanort/\n* Your project here!\n\n## Projects similar/related to NanoRT\n\n* bvh: C++17 BVH Construction and Traversal Library https://github.com/madmann91/bvh\n* BlazeRT: double precision ray tracer for scientific or engineering applications https://github.com/cstatz/blazert\n\n## API\n\n`nanort::Ray` represents ray. The origin `org`, the direction `dir` (not necessarily normalized), the minimum hit distance `min_t`(usually 0.0) and the maximum hit distance `max_t` (usually too far, e.g. 1.0e+30) must be filled before shooting ray.\n\n`nanort::BVHAccel` builds BVH data structure from geometry, and provides the function to find intersection point for a given ray.\n\n`nanort::BVHBuildOptions` specifies parameters for BVH build. Usually default parameters should work well.\n\n`nanort::BVHTraceOptions` specifies ray traverse/intersection options.\n\n```c\ntemplate\u003ctypename T\u003e\nclass {\n  T org[3];        // [in] must set\n  T dir[3];        // [in] must set\n  T min_t;         // [in] must set\n  T max_t;         // [in] must set\n  unsigned int type;  // optional. ray type.\n} Ray;\n\nclass BVHTraceOptions {\n  // Trace rays only in face ids range. faceIdsRange[0] \u003c faceIdsRange[1]\n  // default: 0 to 0x3FFFFFFF(2G faces)\n  unsigned int prim_ids_range[2];\n  bool cull_back_face; // default: false\n};\n\nnanort::BVHBuildOptions\u003cfloat\u003e build_options; // BVH build option(optional)\n\nconst float *vertices = ...;\nconst unsigned int *faces = ...;\n\n// Need to specify stride bytes for `vertices`.\n// When vertex is stored XYZXYZXYZ... in float type, stride become 12(= sizeof(float) * 3).\nnanort::TriangleMesh\u003cfloat\u003e triangle_mesh(vertices, faces, /* stride */sizeof(float) * 3);\nnanort::TriangleSAHPred\u003cfloat\u003e triangle_pred(vertices, faces, /* stride */sizeof(float) * 3);\n\nnanort::BVHAccel\u003cfloat\u003e accel;\nret = accel.Build(mesh.num_faces, triangle_mesh, triangle_pred, build_options);\n\nnanort::TriangleIntersector\u003c\u003e triangle_intersecter(vertices, faces, /* stride */sizeof(float) * 3);\n\nnanort::Ray\u003cfloat\u003e ray;\n// fill ray org and ray dir.\n...\n// fill minimum and maximum hit distance.\nray.min_t = 0.0f;\nray.max_t = 1.0e+30f;\n\nnanort::TriangleIntersection\u003cfloat\u003e isect;\n\n// Store nearest hit point to `isect` and returns true if the hit point found.\nBVHTraceOptions trace_options; // optional\nbool hit = accel.Traverse(ray, triangle_intersecter, \u0026isect, trace_options);\n```\n\nApplication must prepare geometric information and store it in linear array.\n\nFor a builtin Triangle intersector,\n\n* `vertices` : The array of triangle vertices (e.g. xyz * numVertices)\n* `faces` : The array of triangle face indices (3 * numFaces)\n* `stride` : Byte stride of each vertex data\n\nare required attributes.\n\n\n## Usage\n\n```c\n// NanoRT defines template based class, so no NANORT_IMPLEMENTATION anymore.\n#include \"nanort.h\"\nMesh mesh;\n// load mesh data...\nnanort::BVHBuildOptions\u003cfloat\u003e options; // Use default option\nnanort::TriangleMesh\u003cfloat\u003e triangle_mesh(mesh.vertices, mesh.faces, /* stride */sizeof(float) * 3);\nnanort::TriangleSAHPred\u003cfloat\u003e triangle_pred(mesh.vertices, mesh.faces, /* stride */sizeof(float) * 3);\nnanort::BVHAccel\u003cfloat\u003e accel;\nret = accel.Build(mesh.vertices, mesh.faces, mesh.num_faces, options);\nassert(ret);\nnanort::BVHBuildStatistics stats = accel.GetStatistics();\nprintf(\"  BVH statistics:\\n\");\nprintf(\"    # of leaf   nodes: %d\\n\", stats.num_leaf_nodes);\nprintf(\"    # of branch nodes: %d\\n\", stats.num_branch_nodes);\nprintf(\"  Max tree depth   : %d\\n\", stats.max_tree_depth);\n\nstd::vector\u003cfloat\u003e rgb(width * height * 3, 0.0f);\nconst float tFar = 1.0e+30f;\n// Shoot rays.\n#ifdef _OPENMP\n#pragma omp parallel for\n#endif\nfor (int y = 0; y \u003c height; y++) {\n  for (int x = 0; x \u003c width; x++) {\n    BVHTraceOptions trace_options;\n    // Simple camera. change eye pos and direction fit to .obj model.\n    nanort::Ray\u003cfloat\u003e ray;\n    ray.min_t = 0.0f;\n    ray.max_t = tFar;\n    ray.org[0] = 0.0f;\n    ray.org[1] = 5.0f;\n    ray.org[2] = 20.0f;\n    float3 dir;\n    dir[0] = (x / (float)width) - 0.5f;\n    dir[1] = (y / (float)height) - 0.5f;\n    dir[2] = -1.0f;\n    dir.normalize();\n    ray.dir[0] = dir[0];\n    ray.dir[1] = dir[1];\n    ray.dir[2] = dir[2];\n\n    nanort::TriangleIntersector\u003c\u003e triangle_intersecter(mesh.vertices, mesh.faces, /* stride */sizeof(float) * 3);\n    nanort::TriangleIntersection\u003c\u003e isect,\n    bool hit = accel.Traverse(ray, triangle_intersector, \u0026isect, trace_options);\n    if (hit) {\n      // Write your shader here.\n      float3 normal;\n      unsigned int fid = triangle_intersector.intersect.prim_id;\n      normal[0] = mesh.facevarying_normals[3*3*fid+0]; // @todo { interpolate normal }\n      normal[1] = mesh.facevarying_normals[3*3*fid+1];\n      normal[2] = mesh.facevarying_normals[3*3*fid+2];\n      // Flip Y\n      rgb[3 * ((height - y - 1) * width + x) + 0] = fabsf(normal[0]);\n      rgb[3 * ((height - y - 1) * width + x) + 1] = fabsf(normal[1]);\n      rgb[3 * ((height - y - 1) * width + x) + 2] = fabsf(normal[2]);\n    }\n  }\n}\n```\n\n## Defines\n\n```\nNANORT_USE_CPP11_FEATURE : Enable C++11 feature\nNANORT_ENABLE_PARALLEL_BUILD : Enable parallel BVH build(OpenMP version is not yet fully tested).\n```\n\n## More example\n\nSee `examples` directory for example renderer using `NanoRT`.\n\n* [x] [examples/path_tracer](examples/path_tracer) Path tracer example by https://github.com/daseyb\n  * [x] Better ortho basis generation: Building an Orthonormal Basis, Revisited http://jcgt.org/published/0006/01/01/\n* [x] [examples/bidir_path_tracer](examples/bidir_path_tracer) Bi-directional path tracer example by https://github.com/tatsy\n* [x] [examples/gui](examples/gui) Simple renderer with GUI(using ImGui)\n* [x] [examples/vrcamera](examples/vrcamera) Stereo VR Camera\n* [x] [examples/objrender](examples/objrender) Render wavefront .obj model using NanoRT.\n* [x] [examples/par_msquare](examples/par_msquare) Render heightfield by converting it to meshes using par_msquare(marching squares)\n* [x] [examples/las](examples/las) Visualize LiDAR(LAS) point cloud as sphere geometry.\n* [x] [examples/double_precision](examples/double_precision) Double precision triangle geometry and BVH.\n* [x] [examples/embree-api](examples/embree-api) NanoRT implementation of Embree API.\n* [x] [examples/ptex](examples/ptex) Ptex texturing.\n\n\u003c!--\n### Screenshots\nRaytracing allows to implement different camera models quite easily. See [examples/gui](examples/gui) for different camera\nmodels which can be set via the `config.json` or the GUI itself:\n* `perspective`\\\n  ![](examples/gui/screenshot/00_camera_perspective_fov45.png)\n* `orthographic`\\\n  ![](examples/gui/screenshot/01_camera_orthographic.png)\n* `spherical` FoV 120 \u0026 180:\\\n  ![](examples/gui/screenshot/02_camera_spherical_fov120.png)\n  ![](examples/gui/screenshot/02_camera_spherical_fov180.png)\n* `spherical-panorama` FoV 120 \u0026 180:\\\n  ![](examples/gui/screenshot/03_camera_spherical-panorama_fov120.png)\n  ![](examples/gui/screenshot/03_camera_spherical-panorama_fov180.png)\n* `cylindrical`: FoV 90 \u0026 120:\\\n  ![](examples/gui/screenshot/04_camera_cylindrical_90.png)\n  ![](examples/gui/screenshot/04_camera_cylindrical_120.png)\n* `fish-eye`: FoV 120 \u0026 180:\\\n  ![](examples/gui/screenshot/05_camera_fish-eye_120.png)\n  ![](examples/gui/screenshot/05_camera_fish-eye_180.png)\n* `fish-eye MKX22`: nonlinear fish-eye lens \"iZugar MKX22 Fisheye Lens\" with fixed FoV 220:\\\n  ![](examples/gui/screenshot/06_camera_fish-eye_MKX22.png)\n\n--\u003e\n\n### Custom geometry\n\nHere is an example of custom geometry.\n\n* [x] Spheres(particles) `examples/particle_primitive/`\n* Cubic Bezier Curves\n  * [x] Approximate as lines `examples/curves_primitive/`\n  * [ ] Recursive Ray-Bezier intersection.\n* [x] Cylinders `examples/cylinder_primitive/`\n\nAnd plesae see API at wiki: https://github.com/lighttransport/nanort/wiki/API\n\n## License\n\n`nanort.h` is licensed under MIT license.\n\n`NanoRT` uses `stack_container.h` which is licensed under:\n\n    // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.\n    // Use of this source code is governed by a BSD-style license that can be\n    // found in the LICENSE file.\n\n`NanoRT` examples use some external third party libraries. Licenses for such third party libraries obey their own license.\n\nLucy statue model is from The Stanford 3D Scanning Repository http://graphics.stanford.edu/data/3Dscanrep/\n\n## TODO\n\nPR are always welcome!\n\n* [ ] Optimize ray tracing kernel\n  * [ ] Efficient Ray Tracing Kernels for Modern CPU Architectures http://jcgt.org/published/0004/04/05/\n  * [ ] ARM NEON SIMD\n  * [ ] Intel SSE SIMD\n* [ ] Better cmake build.\n* [ ] Implement more Embree compatible API.\n* [ ] Scene graph support.\n  * [x] NanoSG, Minimal scene graph library. [examples/nanosg](examples/nanosg)\n  * [ ] Instancing support.\n* [ ] Fix multi-hit ray traversal.\n* [ ] Optimize Multi-hit ray traversal for BVH.\n  * [ ] http://jcgt.org/published/0004/04/04/\n* [ ] Ray traversal option.\n  * [x] FaceID range.\n  * [x] Double sided on/off.\n  * [ ] Ray offset.\n  * [x] Avoid self-intersection(BVHTraceOptions.skip_prim_id).\n  * [x] Custom intersection filter through C++ template.\n* [ ] Fast BVH build\n  * [ ] Bonsai: Rapid Bounding Volume Hierarchy Generation using Mini Trees http://jcgt.org/published/0004/03/02/\n* [ ] Efficient BVH build\n  * [ ] Spatial split BVH\n* [ ] Motion blur\n  * [ ] STBVH: A Spatial-Temporal BVH for Efficient Multi-Segment Motion Blur http://www.highperformancegraphics.org/2017/program/\n* [ ] Fast, Accurate ray curve intersection\n  * [ ] Phantom Ray-Hair Intersector\n* [x] Example bi-directional path tracing renderer by @tatsy.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flighttransport%2Fnanort","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flighttransport%2Fnanort","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flighttransport%2Fnanort/lists"}