55 lines
1.1 KiB
Plaintext
55 lines
1.1 KiB
Plaintext
struct Ray
|
|
{
|
|
float3 origin;
|
|
float3 direction;
|
|
float3 invDirection;
|
|
}
|
|
|
|
struct Span
|
|
{
|
|
float t0;
|
|
float t1;
|
|
}
|
|
|
|
struct Cell
|
|
{
|
|
/// Entry pointer into the cache
|
|
uint32_t cache_pointer; // entry into the cache
|
|
|
|
/// Ray to be traced inside the cache
|
|
Ray local_ray;
|
|
}
|
|
|
|
interface IStructure
|
|
{
|
|
/// A cursor structure to keep ray state
|
|
associatedtype Cursor;
|
|
|
|
/// Begins tracing a certain ray, with a span
|
|
Cursor begin(Ray worldRay, Span s);
|
|
|
|
/// Returns whether it hits, updating the state, and returning a cell structure if hit.
|
|
bool next(inout Cursor c, out Cell cell); // next populated cell along the ray
|
|
}
|
|
|
|
interface ILodPolicy
|
|
{
|
|
/// cone / pixel-footprint termination
|
|
bool shouldStop(float t, float nodeSize);
|
|
}
|
|
|
|
interface IVoxelCache
|
|
{
|
|
associatedtype Voxel;
|
|
bool trace<L : ILodPolicy>(uint32_t root, Ray r, L lod, out float t, out Voxel v);
|
|
}
|
|
|
|
struct Tracer<S : IStructure, C : IVoxelCache>
|
|
{
|
|
S structure;
|
|
C cache;
|
|
|
|
Hit<C.Voxel> trace(Ray r, Span s) { /* loop: next cell -> cache.trace -> early out */ }
|
|
}
|
|
|