temporal accumulation testing

This commit is contained in:
jacob 2025-07-20 14:06:39 -05:00
parent c6f500ebf4
commit cebb0dae46
7 changed files with 36 additions and 26 deletions

View File

@ -81,7 +81,8 @@ SH_ENTRY(ROOTSIG) struct ps_output ps(struct ps_input input)
/* Apply tone map */ /* Apply tone map */
if (g_constants.flags & SH_BLIT_FLAG_TONE_MAP) { if (g_constants.flags & SH_BLIT_FLAG_TONE_MAP) {
/* TODO: Dynamic exposure based on average scene luminance */ /* TODO: Dynamic exposure based on average scene luminance */
color.rgb = tone_map(color.rgb) * g_constants.exposure; color.rgb *= g_constants.exposure;
color.rgb = tone_map(color.rgb);
} }
/* Apply gamma correction */ /* Apply gamma correction */

View File

@ -54,7 +54,6 @@ SH_ENTRY(ROOTSIG) struct vs_output vs(struct vs_input input)
struct sh_material_instance instance = g_instances[input.SV_InstanceID]; struct sh_material_instance instance = g_instances[input.SV_InstanceID];
float2 vert = unit_quad_verts[input.SV_VertexID]; float2 vert = unit_quad_verts[input.SV_VertexID];
float2 world_pos = mul(instance.xf, float3(vert, 1)).xy; float2 world_pos = mul(instance.xf, float3(vert, 1)).xy;
struct vs_output output; struct vs_output output;
output.SV_Position = mul(g_constants.projection, float4(world_pos, 0, 1)); output.SV_Position = mul(g_constants.projection, float4(world_pos, 0, 1));
output.tex_nurid = instance.tex_nurid; output.tex_nurid = instance.tex_nurid;

View File

@ -102,6 +102,7 @@ SH_STRUCT(sh_material_constants {
/* ---------------------------------------------------- */ /* ---------------------------------------------------- */
SH_DECL(float4x4, projection); /* 16 consts */ SH_DECL(float4x4, projection); /* 16 consts */
/* ---------------------------------------------------- */ /* ---------------------------------------------------- */
}); });
SH_ASSERT_ROOT_CONST(struct sh_material_constants, 16); /* Expected to match num32BitConstants in shader's root signature */ SH_ASSERT_ROOT_CONST(struct sh_material_constants, 16); /* Expected to match num32BitConstants in shader's root signature */
@ -159,11 +160,12 @@ SH_STRUCT(sh_shade_constants {
/* ---------------------------------------------------- */ /* ---------------------------------------------------- */
SH_DECL(uint, emittance_tex_urid); /* 01 consts */ SH_DECL(uint, emittance_tex_urid); /* 01 consts */
SH_DECL(uint, emittance_flood_tex_urid); /* 01 consts */ SH_DECL(uint, emittance_flood_tex_urid); /* 01 consts */
SH_DECL(uint, read_tex_urid); /* 01 consts */
SH_DECL(uint, target_tex_urid); /* 01 consts */ SH_DECL(uint, target_tex_urid); /* 01 consts */
SH_DECL(uint, tex_width); /* 01 consts */
/* ---------------------------------------------------- */ /* ---------------------------------------------------- */
SH_DECL(uint, tex_width); /* 01 consts */
SH_DECL(uint, tex_height); /* 01 consts */ SH_DECL(uint, tex_height); /* 01 consts */
SH_DECL(uint3, _pad0); /* 03 consts (padding) */ SH_DECL(uint2, _pad0); /* 02 consts (padding) */
/* ---------------------------------------------------- */ /* ---------------------------------------------------- */
}); });
SH_ASSERT_ROOT_CONST(struct sh_shade_constants, 16); /* Expected to match num32BitConstants in shader's root signature */ SH_ASSERT_ROOT_CONST(struct sh_shade_constants, 16); /* Expected to match num32BitConstants in shader's root signature */

View File

@ -25,27 +25,33 @@ struct cs_input {
* Lighting * Lighting
* ========================== */ * ========================== */
#define SAMPLES 4 #define SAMPLES 1
#define MARCHES 16 #define MARCHES 16
#define AMBIENT float4(0, 0, 0, 0) #define AMBIENT float3(0, 0, 0)
float rand_angle(int2 pos, uint ray_index) { float rand_angle(uint2 pos, uint ray_index) {
Texture3D<uint> noise_tex = g_noise_textures[SH_BLUE_NOISE_TEX_ID]; Texture3D<uint> noise_tex = g_noise_textures[SH_BLUE_NOISE_TEX_ID];
uint3 noise_coord = uint3(abs(pos.xy), ray_index); int3 noise_coord = int3(1, 1, 1);
noise_coord += g_constants.frame_seed; noise_coord += int3(pos.xy, ray_index);
// noise_coord.xy += g_constants.frame_seed.xy;
// noise_coord.xy += g_constants.frame_index;
// noise_coord.xyz += g_constants.frame_seed.xyz;
// noise_coord.xyz += g_constants.frame_seed.xyz;
// noise_coord.z *= g_constants.frame_seed.w;
// noise_coord.xy
uint noise = noise_tex[noise_coord % uint3(SH_BLUE_NOISE_TEX_WIDTH, SH_BLUE_NOISE_TEX_HEIGHT, SH_BLUE_NOISE_TEX_DEPTH)]; uint noise = noise_tex[noise_coord % uint3(SH_BLUE_NOISE_TEX_WIDTH, SH_BLUE_NOISE_TEX_HEIGHT, SH_BLUE_NOISE_TEX_DEPTH)];
return ((float)noise / (float)0xFFFF) * TAU; return ((float)noise / (float)0xFFFF) * TAU;
} }
INLINE float4 get_light_in_dir(uint2 ray_start, float2 ray_dir) INLINE float3 get_light_in_dir(uint2 ray_start, float2 ray_dir)
{ {
Texture2D<uint2> flood_tex = g_textures_uint2[g_constants.emittance_flood_tex_urid]; Texture2D<uint2> flood_tex = g_textures_uint2[g_constants.emittance_flood_tex_urid];
Texture2D<float4> emittance_tex = g_textures_float4[g_constants.emittance_tex_urid]; Texture2D<float4> emittance_tex = g_textures_float4[g_constants.emittance_tex_urid];
float4 result = AMBIENT; float3 result = AMBIENT;
float2 at_float = ray_start; float2 at_float = ray_start;
uint2 at_uint = ray_start; uint2 at_uint = ray_start;
for (uint i = 0; i < MARCHES; ++i) { for (uint i = 0; i < MARCHES; ++i) {
@ -53,7 +59,7 @@ INLINE float4 get_light_in_dir(uint2 ray_start, float2 ray_dir)
float2 dist_vec = at_float - (float2)flood; float2 dist_vec = at_float - (float2)flood;
float dist = length(dist_vec); float dist = length(dist_vec);
if (dist < 1) { if (dist < 1) {
result = emittance_tex[flood]; result = emittance_tex[flood].rgb;
break; break;
} else { } else {
at_float += ray_dir * dist; at_float += ray_dir * dist;
@ -68,17 +74,16 @@ INLINE float4 get_light_in_dir(uint2 ray_start, float2 ray_dir)
return result; return result;
} }
INLINE float4 get_light_at_pos(int2 pos) INLINE float3 get_light_at_pos(uint2 pos)
{ {
float4 result = 0; float3 result = 0;
for (uint i = 0; i < SAMPLES; ++i) { for (uint i = 0; i < SAMPLES; ++i) {
float angle = rand_angle(pos, i); float angle = rand_angle(pos, i);
float2 dir = float2(cos(angle), sin(angle)); float2 dir = float2(cos(angle), sin(angle));
float4 light_in_dir = get_light_in_dir(pos, dir); float3 light_in_dir = get_light_in_dir(pos, dir);
result += light_in_dir; result += light_in_dir;
} }
result /= SAMPLES; result /= SAMPLES;
return result; return result;
} }
@ -92,6 +97,7 @@ SH_ENTRY(ROOTSIG) void cs(struct cs_input input)
uint2 id = input.SV_DispatchThreadID.xy; uint2 id = input.SV_DispatchThreadID.xy;
if (id.x < g_constants.tex_width && id.y < g_constants.tex_height) { if (id.x < g_constants.tex_width && id.y < g_constants.tex_height) {
Texture2D<float4> albedo_tex = g_textures_float4[g_constants.albedo_tex_urid]; Texture2D<float4> albedo_tex = g_textures_float4[g_constants.albedo_tex_urid];
Texture2D<float4> read_tex = g_textures_float4[g_constants.read_tex_urid];
RWTexture2D<float4> target_tex = g_target_textures[g_constants.target_tex_urid]; RWTexture2D<float4> target_tex = g_target_textures[g_constants.target_tex_urid];
float4 color = float4(1, 1, 1, 1); float4 color = float4(1, 1, 1, 1);
@ -99,7 +105,13 @@ SH_ENTRY(ROOTSIG) void cs(struct cs_input input)
color *= albedo_tex[id]; color *= albedo_tex[id];
/* Apply lighting */ /* Apply lighting */
color *= get_light_at_pos(id); color.rgb *= get_light_at_pos(id);
/* Apply temporal accumulation */
float hysterisis = 0;
// hysterisis = 0.2;
// hysterisis = 0.9;
color.rgb = lerp(color.rgb, read_tex[id].rgb, hysterisis);
target_tex[id] = color; target_tex[id] = color;
} }

View File

@ -84,6 +84,6 @@
/* TODO: Move these to user-configurable settings */ /* TODO: Move these to user-configurable settings */
#define VSYNC 0 #define VSYNC 1
#define AUDIO_ENABLED 0 #define AUDIO_ENABLED 0
#define FPS_LIMIT 300 #define FPS_LIMIT 300

View File

@ -3273,6 +3273,7 @@ struct gp_resource *gp_run_render(struct gp_render_sig *render_sig, struct gp_re
constants.albedo_tex_urid = sh_uint_from_u32(sig->albedo->srv_descriptor->index); constants.albedo_tex_urid = sh_uint_from_u32(sig->albedo->srv_descriptor->index);
constants.emittance_tex_urid = sh_uint_from_u32(sig->emittance->srv_descriptor->index); constants.emittance_tex_urid = sh_uint_from_u32(sig->emittance->srv_descriptor->index);
constants.emittance_flood_tex_urid = sh_uint_from_u32(sig->emittance_flood_read->srv_descriptor->index); constants.emittance_flood_tex_urid = sh_uint_from_u32(sig->emittance_flood_read->srv_descriptor->index);
constants.read_tex_urid = sh_uint_from_u32(sig->shade_read->uav_descriptor->index);
constants.target_tex_urid = sh_uint_from_u32(sig->shade_target->uav_descriptor->index); constants.target_tex_urid = sh_uint_from_u32(sig->shade_target->uav_descriptor->index);
constants.tex_width = sh_uint_from_u32(final_target_size.x); constants.tex_width = sh_uint_from_u32(final_target_size.x);
constants.tex_height = sh_uint_from_u32(final_target_size.y); constants.tex_height = sh_uint_from_u32(final_target_size.y);
@ -3324,13 +3325,8 @@ struct gp_resource *gp_run_render(struct gp_render_sig *render_sig, struct gp_re
ID3D12GraphicsCommandList_SetGraphicsRootSignature(cl->cl, blit_pipeline->rootsig); ID3D12GraphicsCommandList_SetGraphicsRootSignature(cl->cl, blit_pipeline->rootsig);
/* Set Rasterizer State */ /* Set Rasterizer State */
#if 1
D3D12_VIEWPORT viewport = viewport_from_rect(params.draw_target_viewport); D3D12_VIEWPORT viewport = viewport_from_rect(params.draw_target_viewport);
D3D12_RECT scissor = scissor_from_rect(params.draw_target_viewport); D3D12_RECT scissor = scissor_from_rect(params.draw_target_viewport);
#else
D3D12_VIEWPORT viewport = viewport_from_rect(RECT_FROM_V2(V2(0, 0), V2(final_target_size.x, final_target_size.y)));
D3D12_RECT scissor = scissor_from_rect(params.draw_target_viewport);
#endif
ID3D12GraphicsCommandList_RSSetViewports(cl->cl, 1, &viewport); ID3D12GraphicsCommandList_RSSetViewports(cl->cl, 1, &viewport);
ID3D12GraphicsCommandList_RSSetScissorRects(cl->cl, 1, &scissor); ID3D12GraphicsCommandList_RSSetScissorRects(cl->cl, 1, &scissor);

View File

@ -282,8 +282,8 @@ INTERNAL void test_spawn_entities2(struct sim_ent *parent, struct v2 pos)
} }
sim_ent_enable_prop(e, SEPROP_DYNAMIC); sim_ent_enable_prop(e, SEPROP_DYNAMIC);
e->mass_unscaled = 100; e->mass_unscaled = 50;
e->inertia_unscaled = 50; e->inertia_unscaled = 2;
#if 0 #if 0
e->linear_ground_friction = 100; e->linear_ground_friction = 100;
e->angular_ground_friction = 50; e->angular_ground_friction = 50;