Revamped shader arch
This commit is contained in:
+62
-74
@@ -1,4 +1,8 @@
|
||||
import ray_cast;
|
||||
// import ray_cast;
|
||||
import voxel_cache;
|
||||
import fixed_structure_table;
|
||||
import voxel_tracing;
|
||||
import lod_policies;
|
||||
|
||||
struct PushConstants
|
||||
{
|
||||
@@ -33,74 +37,43 @@ public struct VertexOutput
|
||||
[[vk::push_constant]]
|
||||
uniform PushConstants constants;
|
||||
|
||||
struct ByteColor
|
||||
ParameterBlock<VoxelCacheParameters<2>> cache_parameters;
|
||||
ParameterBlock<FixedStructureTable> table_parameters;
|
||||
|
||||
public struct ColorHit<let N : uint32_t> : IVoxelHit<N>
|
||||
{
|
||||
uint32_t byte_color;
|
||||
public __init() {};
|
||||
|
||||
property uint32_t byte_r
|
||||
public bool shouldHit(VoxelCacheParameters<N> cache, uint32_t node_index, uint32_t child_index)
|
||||
{
|
||||
get {
|
||||
return byte_color & 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
property uint32_t byte_g
|
||||
{
|
||||
get {
|
||||
return (byte_color >> 8) & 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
property uint32_t byte_b
|
||||
{
|
||||
get {
|
||||
return (byte_color >> 16) & 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
property uint32_t byte_a
|
||||
{
|
||||
get {
|
||||
return byte_color >> 24;
|
||||
}
|
||||
}
|
||||
|
||||
property float4 float_color
|
||||
{
|
||||
get {
|
||||
return float4(
|
||||
float(byte_r) / 255.,
|
||||
float(byte_g) / 255.,
|
||||
float(byte_b) / 255.,
|
||||
float(byte_a) / 255.);
|
||||
}
|
||||
return ByteColor(cache.attributes_pool[0][node_index * 64 + child_index]).byte_a != 0;
|
||||
}
|
||||
}
|
||||
|
||||
[[vk::binding(0, 0)]]
|
||||
RWStructuredBuffer<StructurePoolElement> structure_pool;
|
||||
[[vk::binding(1, 0)]]
|
||||
RWStructuredBuffer<uint32_t> attributes_pool[2];
|
||||
[[vk::binding(2, 0)]]
|
||||
RWStructuredBuffer<RequestBufferElement> request_buffer;
|
||||
[[vk::binding(3, 0)]]
|
||||
RWStructuredBuffer<uint32_t> usage_buffer;
|
||||
|
||||
[[vk::binding(0, 1)]]
|
||||
RWStructuredBuffer<StructurePointer> structure_table_pointer;
|
||||
[[vk::binding(1, 1)]]
|
||||
RWStructuredBuffer<Atomic<uint32_t>> structure_table_request_buffer;
|
||||
// [[vk::binding(0, 0)]]
|
||||
// RWStructuredBuffer<StructurePoolElement> structure_pool;
|
||||
// [[vk::binding(1, 0)]]
|
||||
// RWStructuredBuffer<RequestBufferElement> request_buffer;
|
||||
// [[vk::binding(2, 0)]]
|
||||
// RWStructuredBuffer<uint32_t> usage_buffer;
|
||||
// [[vk::binding(3, 0)]]
|
||||
// RWStructuredBuffer<uint32_t> attributes_pool[2];
|
||||
//
|
||||
// [[vk::binding(0, 1)]]
|
||||
// RWStructuredBuffer<StructurePointer> structure_table_pointer;
|
||||
// [[vk::binding(1, 1)]]
|
||||
// RWStructuredBuffer<Atomic<uint32_t>> structure_table_request_buffer;
|
||||
|
||||
ByteColor fetch_color(uint32_t index, uint32_t child_index)
|
||||
{
|
||||
return ByteColor(attributes_pool[0][index * 64 + child_index]);
|
||||
return ByteColor(cache_parameters.attributes_pool[0][index * 64 + child_index]);
|
||||
}
|
||||
|
||||
float3 fetch_normal(uint32_t index, uint32_t child_index)
|
||||
{
|
||||
let a = asfloat(attributes_pool[1][index * 64 * 3 + child_index * 3]);
|
||||
let b = asfloat(attributes_pool[1][index * 64 * 3 + child_index * 3 + 1]);
|
||||
let c = asfloat(attributes_pool[1][index * 64 * 3 + child_index * 3 + 2]);
|
||||
let a = asfloat(cache_parameters.attributes_pool[1][index * 64 * 3 + child_index * 3]);
|
||||
let b = asfloat(cache_parameters.attributes_pool[1][index * 64 * 3 + child_index * 3 + 1]);
|
||||
let c = asfloat(cache_parameters.attributes_pool[1][index * 64 * 3 + child_index * 3 + 2]);
|
||||
return float3(a, b, c);
|
||||
}
|
||||
|
||||
@@ -141,6 +114,8 @@ void gi_march(uint32_t3 location: SV_DispatchThreadID, uint32_t3 local_location:
|
||||
}
|
||||
}
|
||||
|
||||
groupshared VoxelTraceStack stacks[256];
|
||||
|
||||
[shader("compute")]
|
||||
[numthreads(16, 16, 1)]
|
||||
void ray_march_compute(uint32_t3 location: SV_DispatchThreadID, uint32_t3 local_location: SV_GroupThreadID)
|
||||
@@ -152,33 +127,46 @@ void ray_march_compute(uint32_t3 location: SV_DispatchThreadID, uint32_t3 local_
|
||||
|
||||
let stack_index = local_location.x + local_location.y * 16;
|
||||
|
||||
var voxel_cache : VoxelCache;
|
||||
voxel_cache.structure_pool = structure_pool;
|
||||
voxel_cache.attributes_pool = attributes_pool;
|
||||
voxel_cache.request_buffer = request_buffer;
|
||||
voxel_cache.usage_buffer = usage_buffer;
|
||||
voxel_cache.structure_table_pointer = structure_table_pointer;
|
||||
voxel_cache.structure_table_request_buffer = structure_table_request_buffer;
|
||||
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>();
|
||||
|
||||
FixedStructureTableChunks table_tracer;
|
||||
table_tracer.structure_table = table_parameters;
|
||||
table_tracer.extent = uint32_t3(constants.chunk_width, constants.chunk_alt, constants.chunk_width);
|
||||
|
||||
let ray_direction = get_ray_direction(location.xy);
|
||||
|
||||
var ray_cast_context : RayCastContext;
|
||||
ray_cast_context.ray_direction = ray_direction;
|
||||
ray_cast_context.ray_origin = constants.cam_pos;
|
||||
ray_cast_context.bounds = uint32_t3(constants.chunk_width, constants.chunk_alt, constants.chunk_width);
|
||||
ray_cast_context.frame_timestamp = constants.frame_timestamp;
|
||||
ray_cast_context.cache_report = true;
|
||||
Ray r;
|
||||
r.origin = constants.cam_pos;
|
||||
r.direction = ray_direction;
|
||||
r.invDirection = 1.f / ray_direction;
|
||||
|
||||
let hit = ray_cast(voxel_cache, ray_cast_context, stack_index);
|
||||
PixelFootprintLod lod = PixelFootprintLod.create((100.f * 3.14f) / 180.f, 1080.f, 200.f);
|
||||
|
||||
if (hit.hit)
|
||||
Tracer<FixedStructureTableChunks, VoxelCacheTracer<2, ColorHit<2>>, PixelFootprintLod> tracer;
|
||||
tracer.structure = table_tracer;
|
||||
tracer.cache = cache_tracer;
|
||||
tracer.lod = lod;
|
||||
|
||||
Hit h;
|
||||
Span s;
|
||||
bool hit = tracer.trace(stacks[stack_index], h, r, s);
|
||||
|
||||
FixedStructureTableChunks.Cursor cursor = table_tracer.begin(r, s);
|
||||
Cell cell;
|
||||
|
||||
if (hit)
|
||||
{
|
||||
// Gather
|
||||
let hit_pos = hit.hit_pos;
|
||||
let hit_pos = h.hit_location;
|
||||
|
||||
let hit_normal = fetch_normal(hit.node_index, hit.child_index);
|
||||
let hit_normal = fetch_normal(h.node_index, h.child_index);
|
||||
var hit_albedo = float4(0.);
|
||||
hit_albedo = fetch_color(hit.node_index, hit.child_index).float_color;
|
||||
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.));
|
||||
|
||||
Reference in New Issue
Block a user