Starting torroidal structure table
This commit is contained in:
+1
-1
@@ -4,4 +4,4 @@ clean:
|
||||
rm -f out/*.spv
|
||||
|
||||
%.spv: %.slang
|
||||
slangc $< -O3 -g0 -fp-mode fast -fvk-use-scalar-layout -emit-spirv-directly -fvk-use-entrypoint-name -target spirv -o out/$@
|
||||
slangc $< -O3 -g0 -fp-mode fast -emit-spirv-directly -fvk-use-entrypoint-name -target spirv -o out/$@
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,126 @@
|
||||
module toroidal_structure_table;
|
||||
|
||||
import voxel_cache;
|
||||
import voxel_tracing;
|
||||
|
||||
/// Parameters for the fixed structure table
|
||||
public struct ToroidalStructureTable
|
||||
{
|
||||
RWStructuredBuffer<StructurePointer> structure_table_pointer;
|
||||
RWStructuredBuffer<Atomic<uint32_t>> structure_table_request_buffer;
|
||||
}
|
||||
|
||||
public struct ToroidalStructureTableChunksCursor
|
||||
{
|
||||
// Offset of the block of chuks
|
||||
int32_t3 offset;
|
||||
int32_t3 current_voxel;
|
||||
float3 t_off;
|
||||
float3 t;
|
||||
|
||||
Ray r;
|
||||
}
|
||||
|
||||
int32_t imod(int32_t x, int32_t n)
|
||||
{
|
||||
int32_t r = x % n;
|
||||
return r < 0 ? r + n : r;
|
||||
}
|
||||
|
||||
/// Uses a fixed structure table as a dense array of chunks
|
||||
public struct ToroidalStructureTableTracer : IStructure
|
||||
{
|
||||
typedef ToroidalStructureTableChunksCursor Cursor;
|
||||
|
||||
public ToroidalStructureTable structure_table;
|
||||
public uint32_t3 extent;
|
||||
|
||||
public ToroidalStructureTableChunksCursor begin(Ray worldRay, Span s)
|
||||
{
|
||||
ToroidalStructureTableChunksCursor cursor;
|
||||
// Now march inside chunk bounds
|
||||
let start_position = worldRay.origin;
|
||||
|
||||
// FVT clamp to block
|
||||
cursor.current_voxel = int32_t3(floor(start_position));
|
||||
cursor.offset = cursor.current_voxel - int32_t3(this.extent) / 2;
|
||||
|
||||
cursor.t_off = abs(worldRay.invDirection);
|
||||
|
||||
// Take t of next boundary
|
||||
cursor.t = select(
|
||||
worldRay.direction > 0.,
|
||||
cursor.current_voxel + int32_t3(1) - start_position,
|
||||
start_position - cursor.current_voxel) *
|
||||
cursor.t_off;
|
||||
|
||||
// Add camera offset
|
||||
cursor.r = worldRay;
|
||||
return cursor;
|
||||
}
|
||||
|
||||
public bool next(inout Cursor c, out Cell cell)
|
||||
{
|
||||
while (all(c.current_voxel >= c.offset) && all(c.current_voxel < c.offset + int32_t3(extent)))
|
||||
{
|
||||
// Current hit
|
||||
let off = c.t - c.t_off;
|
||||
let t_adv = max(max(off.x, max(off.y, off.z)), 0.);
|
||||
let local_voxel =
|
||||
int32_t3(
|
||||
imod(c.current_voxel.x, int32_t(this.extent.x)),
|
||||
imod(c.current_voxel.y, int32_t(this.extent.y)),
|
||||
imod(c.current_voxel.z, int32_t(this.extent.z)));
|
||||
let chunk_index = local_voxel.x + local_voxel.z * this.extent.x + local_voxel.y * this.extent.x * this.extent.z;
|
||||
let position = c.r.origin + c.r.direction * t_adv;
|
||||
|
||||
var hit = false;
|
||||
if (this.structure_table.structure_table_pointer[chunk_index].subdivided_valid())
|
||||
{
|
||||
cell.cache_pointer = this.structure_table.structure_table_pointer[chunk_index].pointer();
|
||||
cell.local_ray.origin = position - float3(c.current_voxel);
|
||||
cell.local_ray.direction = c.r.direction;
|
||||
cell.local_ray.invDirection = c.r.invDirection;
|
||||
cell.t = t_adv;
|
||||
hit = true;
|
||||
}
|
||||
else if (this.structure_table.structure_table_pointer[chunk_index].subdivided())
|
||||
{
|
||||
this.structure_table.structure_table_request_buffer[chunk_index].add(1);
|
||||
hit = false;
|
||||
}
|
||||
|
||||
// Advance
|
||||
let min_mask = min_mask(c.t);
|
||||
c.t += select(min_mask, c.t_off, float3(0.));
|
||||
c.current_voxel += select(min_mask, int32_t3(sign(c.r.direction)), int32_t3(0));
|
||||
|
||||
if (hit)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool3 min_mask(float3 val)
|
||||
{
|
||||
let min_val = min(val.x, min(val.y, val.z));
|
||||
return val == min_val;
|
||||
}
|
||||
|
||||
float2 box_intersect(float3 origin, float3 ray_direction, float3 box_min, float3 box_max)
|
||||
{
|
||||
let min_ts = (box_min - origin) / ray_direction;
|
||||
let max_ts = (box_max - origin) / ray_direction;
|
||||
|
||||
let far_ts = max(min_ts, max_ts);
|
||||
let near_ts = min(min_ts, max_ts);
|
||||
|
||||
let far_t = min(far_ts.x, min(far_ts.y, far_ts.z));
|
||||
let near_t = max(near_ts.x, max(near_ts.y, near_ts.z));
|
||||
return float2(near_t, far_t);
|
||||
}
|
||||
|
||||
+6
-5
@@ -1,6 +1,7 @@
|
||||
// import ray_cast;
|
||||
import voxel_cache;
|
||||
import fixed_structure_table;
|
||||
import toroidal_structure_table;
|
||||
import voxel_tracing;
|
||||
import lod_policies;
|
||||
|
||||
@@ -38,7 +39,7 @@ public struct VertexOutput
|
||||
uniform PushConstants constants;
|
||||
|
||||
ParameterBlock<VoxelCacheParameters<2>> cache_parameters;
|
||||
ParameterBlock<FixedStructureTable> table_parameters;
|
||||
ParameterBlock<ToroidalStructureTable> table_parameters;
|
||||
|
||||
public struct ColorHit<let N : uint32_t> : IVoxelHit<N>
|
||||
{
|
||||
@@ -134,7 +135,7 @@ void ray_march_compute(uint32_t3 location: SV_DispatchThreadID, uint32_t3 local_
|
||||
cache_tracer.frame_timestamp = constants.frame_timestamp;
|
||||
cache_tracer.voxel_hit = ColorHit<2>();
|
||||
|
||||
FixedStructureTableChunks table_tracer;
|
||||
ToroidalStructureTableTracer table_tracer;
|
||||
table_tracer.structure_table = table_parameters;
|
||||
table_tracer.extent = uint32_t3(constants.chunk_width, constants.chunk_alt, constants.chunk_width);
|
||||
|
||||
@@ -147,7 +148,7 @@ void ray_march_compute(uint32_t3 location: SV_DispatchThreadID, uint32_t3 local_
|
||||
|
||||
PixelFootprintLod lod = PixelFootprintLod.create((100.f * 3.14f) / 180.f, 1080.f, 2.f);
|
||||
|
||||
Tracer<FixedStructureTableChunks, VoxelCacheTracer<2, ColorHit<2>>, PixelFootprintLod> tracer;
|
||||
Tracer<ToroidalStructureTableTracer, VoxelCacheTracer<2, ColorHit<2>>, PixelFootprintLod> tracer;
|
||||
tracer.structure = table_tracer;
|
||||
tracer.cache = cache_tracer;
|
||||
tracer.lod = lod;
|
||||
@@ -156,8 +157,8 @@ void ray_march_compute(uint32_t3 location: SV_DispatchThreadID, uint32_t3 local_
|
||||
Span s;
|
||||
bool hit = tracer.trace(stacks[stack_index], h, r, s);
|
||||
|
||||
FixedStructureTableChunks.Cursor cursor = table_tracer.begin(r, s);
|
||||
Cell cell;
|
||||
ToroidalStructureTableTracer.Cursor cursor = table_tracer.begin(r, s);
|
||||
Cell cell;
|
||||
|
||||
if (hit)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user