Awesome
<a href="https://www.nuget.org/packages/TinyEmbree/"> </a>
TinyEmbree
A very simple C# wrapper around the Embree ray tracing kernels. Currently only supports simple triangle meshes with no motion blur etc. Embree and our wrapper are automatically compiled for x86-64 Windows, Linux, and macOS with support for AVX and AVX2, and for arm64 macOS. On these platforms, you can directly use the Nuget package. Other platforms need to compile both Embree and our C++ wrapper code from source, instructions are below.
Usage example
The following creates a trivial scene consisting of a single quad and intersects it with a ray:
Raytracer rt = new();
rt.AddMesh(new(
new Vector3[] { // vertices
new(-1, 0, -1),
new( 1, 0, -1),
new( 1, 0, 1),
new(-1, 0, 1)
}, new int[] { // indices
0, 1, 2,
0, 2, 3
}
));
rt.CommitScene(); // builds the acceleration structures
// Trace a single ray
Hit hit = rt.Trace(new Ray {
Origin = new(-0.5f, -10, 0),
Direction = new(0, 1, 0),
MinDistance = 1.0f
});
if (hit) {
Console.WriteLine($"Hit: {hit.PrimId}, {hit.Distance}");
}
Dependencies
- .NET 5.0 (or newer)
- a C++11 (or newer) compiler
- CMake
Building from source
There is a PowerShell script that downloads the prebuilt binaries for Embree and TBB (RenderLibs). It currently supports x64 Windows and Linux, and x64 and arm64 OSX. You can run it via
pwsh ./make.ps1
provided that PowerShell is installed. The script is rather simple (download and extract zip, run CMake, copy binaries) and you can also manually perform the same steps.
If compilation was successful, the C# wrapper is also automatically built and tested by the script.