feat: Starting bvh raytracing
This commit is contained in:
+60
-38
@@ -2,6 +2,7 @@
|
||||
import voxel_cache;
|
||||
// import fixed_structure_table;
|
||||
import toroidal_structure_table;
|
||||
import bvh;
|
||||
import voxel_tracing;
|
||||
import lod_policies;
|
||||
|
||||
@@ -42,7 +43,8 @@ public struct VertexOutput
|
||||
uniform PushConstants constants;
|
||||
|
||||
ParameterBlock<VoxelCacheParameters<2>> cache_parameters;
|
||||
ParameterBlock<ToroidalStructureTable> table_parameters;
|
||||
// ParameterBlock<ToroidalStructureTable> table_parameters;
|
||||
ParameterBlock<BvhParameters> table_parameters;
|
||||
|
||||
public struct ColorHit<let N : uint32_t> : IVoxelHit<N>
|
||||
{
|
||||
@@ -136,52 +138,72 @@ 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>();
|
||||
|
||||
ToroidalStructureTableTracer table_tracer;
|
||||
table_tracer.structure_table = table_parameters;
|
||||
table_tracer.extent =
|
||||
uint32_t3(constants.chunk_width, constants.chunk_alt, constants.chunk_height);
|
||||
table_tracer.base_slot = uint32_t3(
|
||||
constants.table_base_slot_x,
|
||||
constants.table_base_slot_y,
|
||||
constants.table_base_slot_z);
|
||||
|
||||
let ray_direction = get_ray_direction(location.xy);
|
||||
|
||||
Ray r;
|
||||
r.origin = constants.cam_pos;
|
||||
r.direction = ray_direction;
|
||||
|
||||
PixelFootprintLod lod = PixelFootprintLod.create((100.f * 3.14f) / 180.f, 1080.f, 2.f);
|
||||
Bvh bvh;
|
||||
bvh.parameters = table_parameters;
|
||||
bvh.thread_index = local_location.x;
|
||||
BvhCursor c = bvh.begin(r);
|
||||
Cell cell;
|
||||
|
||||
Tracer<ToroidalStructureTableTracer, VoxelCacheTracer<2, ColorHit<2>>, PixelFootprintLod> tracer;
|
||||
tracer.structure = table_tracer;
|
||||
tracer.cache = cache_tracer;
|
||||
tracer.lod = lod;
|
||||
|
||||
Hit h;
|
||||
bool hit = tracer.trace(stack_index, h, r);
|
||||
|
||||
ToroidalStructureTableTracer.Cursor cursor = table_tracer.begin(r);
|
||||
Cell cell;
|
||||
|
||||
if (hit)
|
||||
// for (uint32_t i = 0; i < 100; i++)
|
||||
// {
|
||||
if (bvh.next(c, cell))
|
||||
{
|
||||
// Gather
|
||||
let hit_pos = h.hit_location;
|
||||
|
||||
let hit_normal = fetch_normal(h.node_index, h.child_index);
|
||||
var hit_albedo = float4(0.);
|
||||
hit_albedo = fetch_color(h.node_index, h.child_index).float_color;
|
||||
// let hit_albedo = hit.color;
|
||||
|
||||
gbuffer_position.Store(location.xy, float4(hit_pos, 1.));
|
||||
gbuffer_normal.Store(location.xy, float4(hit_normal, 1.));
|
||||
gbuffer_albedo.Store(location.xy, hit_albedo);
|
||||
}
|
||||
else
|
||||
{
|
||||
gbuffer_albedo.Store(location.xy, float4(0.));
|
||||
gbuffer_albedo.Store(location.xy, float4(0., 1., 0., 1.));
|
||||
return;
|
||||
}
|
||||
//}
|
||||
gbuffer_albedo.Store(location.xy, float4(0.));
|
||||
|
||||
/*
|
||||
ToroidalStructureTableTracer table_tracer;
|
||||
table_tracer.structure_table = table_parameters;
|
||||
table_tracer.extent =
|
||||
uint32_t3(constants.chunk_width, constants.chunk_alt, constants.chunk_height);
|
||||
table_tracer.base_slot = uint32_t3(
|
||||
constants.table_base_slot_x,
|
||||
constants.table_base_slot_y,
|
||||
constants.table_base_slot_z);
|
||||
|
||||
|
||||
|
||||
PixelFootprintLod lod = PixelFootprintLod.create((100.f * 3.14f) / 180.f, 1080.f, 2.f);
|
||||
|
||||
Tracer<ToroidalStructureTableTracer, VoxelCacheTracer<2, ColorHit<2>>, PixelFootprintLod> tracer;
|
||||
tracer.structure = table_tracer;
|
||||
tracer.cache = cache_tracer;
|
||||
tracer.lod = lod;
|
||||
|
||||
Hit h;
|
||||
bool hit = tracer.trace(stack_index, h, r);
|
||||
|
||||
ToroidalStructureTableTracer.Cursor cursor = table_tracer.begin(r);
|
||||
Cell cell;
|
||||
|
||||
if (hit)
|
||||
{
|
||||
// Gather
|
||||
let hit_pos = h.hit_location;
|
||||
|
||||
let hit_normal = fetch_normal(h.node_index, h.child_index);
|
||||
var hit_albedo = float4(0.);
|
||||
hit_albedo = fetch_color(h.node_index, h.child_index).float_color;
|
||||
// let hit_albedo = hit.color;
|
||||
|
||||
gbuffer_position.Store(location.xy, float4(hit_pos, 1.));
|
||||
gbuffer_normal.Store(location.xy, float4(hit_normal, 1.));
|
||||
gbuffer_albedo.Store(location.xy, hit_albedo);
|
||||
}
|
||||
else
|
||||
{
|
||||
gbuffer_albedo.Store(location.xy, float4(0.));
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
float2 box_intersect(float3 origin, float3 ray_direction, float3 box_min, float3 box_max)
|
||||
|
||||
Reference in New Issue
Block a user