refactor: cleaner request path + raytracing code
This commit is contained in:
+25
-20
@@ -46,15 +46,8 @@ ParameterBlock<VoxelCacheParameters<2>> cache_parameters;
|
||||
// ParameterBlock<ToroidalStructureTable> table_parameters;
|
||||
ParameterBlock<BvhParameters> table_parameters;
|
||||
|
||||
public struct ColorHit<let N : uint32_t> : IVoxelHit<N>
|
||||
{
|
||||
public __init() {};
|
||||
|
||||
public bool shouldHit(VoxelCacheParameters<N> cache, uint32_t node_index, uint32_t child_index)
|
||||
{
|
||||
return ByteColor(cache.attributes_pool[0][node_index * 64 + child_index]).byte_a != 0;
|
||||
}
|
||||
}
|
||||
// ColorHit<2> (the demo hit predicate) lives in voxel_cache.slang so the
|
||||
// primary and secondary front-ends share one definition.
|
||||
|
||||
// [[vk::binding(0, 0)]]
|
||||
// RWStructuredBuffer<StructurePoolElement> structure_pool;
|
||||
@@ -122,22 +115,32 @@ void gi_march(uint32_t3 location: SV_DispatchThreadID, uint32_t3 local_location:
|
||||
|
||||
[shader("compute")]
|
||||
[numthreads(16, 16, 1)]
|
||||
void ray_march_compute(uint32_t3 location: SV_DispatchThreadID, uint32_t3 local_location: SV_GroupThreadID)
|
||||
void ray_march_compute(uint32_t3 location: SV_DispatchThreadID)
|
||||
{
|
||||
if (location.x >= constants.width || location.y >= constants.height)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
let stack_index = local_location.x + local_location.y * 16;
|
||||
|
||||
VoxelCacheTracer<2, ColorHit<2>> cache_tracer;
|
||||
cache_tracer.parameters = cache_parameters;
|
||||
cache_tracer.report_usage = true;
|
||||
cache_tracer.report_requests = true;
|
||||
cache_tracer.frame_timestamp = constants.frame_timestamp;
|
||||
cache_tracer.voxel_hit = ColorHit<2>();
|
||||
|
||||
// Per-ray trace state. Local storage keeps the tracer independent of the
|
||||
// workgroup shape; swap this for a groupshared-backed ITraceStack if the
|
||||
// primary pass needs groupshared memory back.
|
||||
LocalTraceStack stack;
|
||||
|
||||
TraceSettings settings;
|
||||
settings.t_min = 0.;
|
||||
settings.t_max = asfloat(0x7f7fffff); // FLT_MAX
|
||||
settings.max_cells = 0xFFFFFFFF;
|
||||
settings.max_steps = 500;
|
||||
settings.any_hit = false;
|
||||
settings.report_usage = true;
|
||||
settings.report_requests = true;
|
||||
|
||||
let ray_direction = get_ray_direction(location.xy);
|
||||
|
||||
Ray r;
|
||||
@@ -146,7 +149,7 @@ void ray_march_compute(uint32_t3 location: SV_DispatchThreadID, uint32_t3 local_
|
||||
|
||||
Bvh bvh;
|
||||
bvh.parameters = table_parameters;
|
||||
bvh.thread_index = stack_index;
|
||||
bvh.max_t = asfloat(0x7f7fffff); // FLT_MAX: unbounded primary rays
|
||||
// BvhCursor c = bvh.begin(r);
|
||||
Cell cell;
|
||||
|
||||
@@ -176,19 +179,21 @@ void ray_march_compute(uint32_t3 location: SV_DispatchThreadID, uint32_t3 local_
|
||||
|
||||
Hit h;
|
||||
// Closest hit at or past tMin. Re-trace past a hit with:
|
||||
// t_min = h.t + 1e-4;
|
||||
// hit = tracer.trace(stack_index, t_min, h, r);
|
||||
bool hit = tracer.trace(stack_index, 0., h, r);
|
||||
// settings.t_min = h.t + 1e-4;
|
||||
// hit = tracer.trace(h, r, settings, stack);
|
||||
bool hit = tracer.trace(h, r, settings, stack);
|
||||
|
||||
// ToroidalStructureTableTracer.Cursor cursor = table_tracer.begin(r);
|
||||
// Cell cell;
|
||||
|
||||
if (hit)
|
||||
{
|
||||
// Gather
|
||||
// `Hit` is already in world space; only the local attribute normal
|
||||
// still needs rotating into world space.
|
||||
let hit_pos = h.hit_location;
|
||||
|
||||
let hit_normal = fetch_normal(h.node_index, h.child_index);
|
||||
let local_normal = mul(h.normal_to_world, fetch_normal(h.node_index, h.child_index));
|
||||
let hit_normal = local_normal / max(length(local_normal), 1e-6);
|
||||
var hit_albedo = float4(0.);
|
||||
hit_albedo = fetch_color(h.node_index, h.child_index).float_color;
|
||||
// let hit_albedo = hit.color;
|
||||
|
||||
Reference in New Issue
Block a user