Files
vxls/shaders/gi.slang
T
2026-11-15 12:00:08 +01:00

86 lines
2.2 KiB
Plaintext

struct PushConstants
{
float4x4 view_proj;
float3 cam_pos;
uint32_t frame_timestamp;
uint32_t width;
uint32_t height;
uint32_t chunk_width;
uint32_t chunk_height;
uint32_t chunk_alt;
uint32_t table_base_slot_x;
uint32_t table_base_slot_y;
uint32_t table_base_slot_z;
}
[[vk::push_constant]]
uniform PushConstants constants;
[[vk::binding(0, 0)]]
RWStructuredBuffer<uint32_t> structure_pool;
[[vk::binding(1, 0)]]
RWStructuredBuffer<uint32_t> attributes_pool[2];
[[vk::binding(2, 0)]]
RWStructuredBuffer<uint32_t> request_buffer;
[[vk::binding(3, 0)]]
RWStructuredBuffer<uint32_t> usage_buffer;
[[vk::binding(0, 1)]]
RWStructuredBuffer<uint32_t> structure_table_pointer;
[[vk::binding(1, 1)]]
RWStructuredBuffer<Atomic<uint32_t>> structure_table_request_buffer;
[[vk::binding(0, 2)]]
[[format("rgba32f")]]
WTexture2D<float4> target_texture;
[[vk::binding(1, 2)]]
[[format("rgba32f")]]
RWTexture2D<float4> gbuffer_position;
[[vk::binding(2, 2)]]
[[format("rgba32f")]]
RWTexture2D<float4> gbuffer_albedo;
[[vk::binding(3, 2)]]
[[format("rgba32f")]]
RWTexture2D<float4> gbuffer_normal;
float3 get_ray_direction(uint32_t2 pixel_loc)
{
let ndc_loc_x = (float)pixel_loc.x / (float)constants.width * 2. - 1.;
let ndc_loc_y = 1. - (float)pixel_loc.y / (float)constants.height * 2.;
var world_loc = mul(constants.view_proj, float4(ndc_loc_x, ndc_loc_y, 1., 1.));
world_loc /= world_loc.w;
return normalize(world_loc.xyz - constants.cam_pos);
}
[shader("compute")]
[numthreads(16, 16, 1)]
void gi(uint32_t3 location: SV_DispatchThreadID, uint32_t3 local_location: SV_GroupThreadID)
{
if (location.x >= constants.width || location.y >= constants.height)
{
return;
}
if (gbuffer_albedo.Load(location.xy).w == 0.)
{
target_texture.Store(location.xy, float4(0.));
return;
}
let pos = gbuffer_position.Load(location.xy);
let normal = gbuffer_normal.Load(location.xy);
let albedo = gbuffer_albedo.Load(location.xy);
// let floored_pos = floor(pos);
// let c = (floored_pos.x + floored_pos.y + floored_pos.z) % 2;
// target_texture.Store(location.xy, albedo * select(c == 0, 0.5, 1.));
target_texture.Store(location.xy, albedo);
return;
}