Revamped shader arch
This commit is contained in:
+62
-23
@@ -1,54 +1,93 @@
|
||||
struct Ray
|
||||
module voxel_tracing;
|
||||
|
||||
public struct Ray
|
||||
{
|
||||
float3 origin;
|
||||
float3 direction;
|
||||
float3 invDirection;
|
||||
public float3 origin;
|
||||
public float3 direction;
|
||||
public float3 invDirection;
|
||||
}
|
||||
|
||||
struct Span
|
||||
public struct Span
|
||||
{
|
||||
float t0;
|
||||
float t1;
|
||||
public float t0;
|
||||
public float t1;
|
||||
}
|
||||
|
||||
struct Cell
|
||||
public struct Cell
|
||||
{
|
||||
/// Entry pointer into the cache
|
||||
uint32_t cache_pointer; // entry into the cache
|
||||
public uint32_t cache_pointer; // entry into the cache
|
||||
|
||||
/// Ray to be traced inside the cache
|
||||
Ray local_ray;
|
||||
public Ray local_ray;
|
||||
|
||||
/// How much distance from the camera
|
||||
public float t;
|
||||
}
|
||||
|
||||
interface IStructure
|
||||
public interface IStructure
|
||||
{
|
||||
/// A cursor structure to keep ray state
|
||||
associatedtype Cursor;
|
||||
public associatedtype Cursor;
|
||||
|
||||
/// Begins tracing a certain ray, with a span
|
||||
Cursor begin(Ray worldRay, Span s);
|
||||
public 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
|
||||
public bool next(inout Cursor c, out Cell cell); // next populated cell along the ray
|
||||
}
|
||||
|
||||
interface ILodPolicy
|
||||
public interface ILodPolicy
|
||||
{
|
||||
/// cone / pixel-footprint termination
|
||||
bool shouldStop(float t, float nodeSize);
|
||||
public bool shouldStop(float t, float nodeSize);
|
||||
}
|
||||
|
||||
interface IVoxelCache
|
||||
public struct Hit
|
||||
{
|
||||
associatedtype Voxel;
|
||||
bool trace<L : ILodPolicy>(uint32_t root, Ray r, L lod, out float t, out Voxel v);
|
||||
public bool hit;
|
||||
|
||||
// Cache location
|
||||
public uint32_t node_index;
|
||||
public uint32_t child_index;
|
||||
public float3 hit_location;
|
||||
}
|
||||
|
||||
struct Tracer<S : IStructure, C : IVoxelCache>
|
||||
public interface IVoxelCache
|
||||
{
|
||||
S structure;
|
||||
C cache;
|
||||
// The voxel cache tracer needs to store a small stack.
|
||||
// Keeping it in registers is wastefull thus using groupshared memory is the best option
|
||||
associatedtype GroupSharedData;
|
||||
public bool trace<L : ILodPolicy>(uint32_t root, inout GroupSharedData data, Ray r, L lod, float offset_t, out Hit v);
|
||||
}
|
||||
|
||||
Hit<C.Voxel> trace(Ray r, Span s) { /* loop: next cell -> cache.trace -> early out */ }
|
||||
public struct Tracer<S : IStructure, C : IVoxelCache, L : ILodPolicy>
|
||||
{
|
||||
|
||||
public S structure;
|
||||
public C cache;
|
||||
public L lod;
|
||||
|
||||
public bool trace(inout C.GroupSharedData gsData, out Hit h, Ray r, Span s)
|
||||
{
|
||||
/* loop: next cell -> cache.trace -> early out */
|
||||
S.Cursor cursor = this.structure.begin(r, s);
|
||||
Cell cell;
|
||||
|
||||
h.hit = false;
|
||||
h.hit_location = float3(0.f);
|
||||
h.child_index = 0;
|
||||
h.node_index = 0;
|
||||
|
||||
while (this.structure.next(cursor, cell))
|
||||
{
|
||||
if (cache.trace(cell.cache_pointer, gsData, cell.local_ray, lod, cell.t, h))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user