formatting
This commit is contained in:
parent
6de00915ea
commit
4aabab35e7
@ -40,15 +40,19 @@ SH_ENTRY(ROOTSIG) void cs(struct cs_input input)
|
||||
return; /* Overflow */
|
||||
}
|
||||
|
||||
Texture2D<float4> emittance_tex = g_emittance_textures[g_constants.emittance_tex_urid];
|
||||
RWTexture2D<uint2> read_flood_tex = g_flood_textures[g_constants.read_flood_tex_urid];
|
||||
RWTexture2D<uint2> write_flood_tex = g_flood_textures[g_constants.write_flood_tex_urid];
|
||||
|
||||
int step_len = g_constants.step_len;
|
||||
if (step_len == -1) {
|
||||
/* Seed */
|
||||
float4 emittance = g_emittance_textures[g_constants.emittance_tex_urid][id];
|
||||
float4 emittance = emittance_tex[id];
|
||||
uint2 seed = uint2(0xFFFF, 0xFFFF);
|
||||
if (emittance.a > 0) {
|
||||
seed = id;
|
||||
}
|
||||
g_flood_textures[g_constants.write_flood_tex_urid][id] = seed;
|
||||
write_flood_tex[id] = seed;
|
||||
} else {
|
||||
/* Flood */
|
||||
int2 read_coords[9] = {
|
||||
@ -67,7 +71,7 @@ SH_ENTRY(ROOTSIG) void cs(struct cs_input input)
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
int2 coord = read_coords[i];
|
||||
if (coord.x >= 0 && coord.x < (int)tex_size.x && coord.y >= 0 && coord.y < (int)tex_size.y) {
|
||||
uint2 seed = g_flood_textures[g_constants.read_flood_tex_urid][coord];
|
||||
uint2 seed = read_flood_tex[coord];
|
||||
int2 dist_vec = (int2)id - (int2)seed;
|
||||
uint dist_len_sq = dot(dist_vec, dist_vec);
|
||||
if (dist_len_sq < closest_seed_len_sq) {
|
||||
@ -76,6 +80,6 @@ SH_ENTRY(ROOTSIG) void cs(struct cs_input input)
|
||||
}
|
||||
}
|
||||
}
|
||||
g_flood_textures[g_constants.write_flood_tex_urid][id] = closest_seed;
|
||||
write_flood_tex[id] = closest_seed;
|
||||
}
|
||||
}
|
||||
|
||||
@ -114,7 +114,7 @@ SH_ASSERT_32BIT(struct sh_flood_constants, 6); /* Expected 32bit root constant
|
||||
* ========================== */
|
||||
|
||||
SH_STRUCT(sh_shade_constants {
|
||||
SH_DECL(float, time);
|
||||
SH_DECL(uint, tick);
|
||||
SH_DECL(uint, albedo_tex_urid);
|
||||
SH_DECL(uint, emittance_tex_urid);
|
||||
SH_DECL(uint, emittance_flood_tex_urid);
|
||||
|
||||
@ -39,15 +39,18 @@ struct cs_input {
|
||||
|
||||
INLINE float4 get_light_in_dir(uint2 ray_start, float2 ray_dir)
|
||||
{
|
||||
Texture2D<uint2> flood_tex = g_emittance_flood_textures[g_constants.emittance_flood_tex_urid];
|
||||
Texture2D<float4> emittance_tex = g_gbuff_textures[g_constants.emittance_tex_urid];
|
||||
|
||||
float4 result = AMBIENT;
|
||||
float2 at_float = ray_start;
|
||||
uint2 at_uint = ray_start;
|
||||
for (uint i = 0; i < MARCHES; ++i) {
|
||||
uint2 flood = g_emittance_flood_textures[g_constants.emittance_flood_tex_urid][at_uint];
|
||||
uint2 flood = flood_tex[at_uint];
|
||||
float2 dist_vec = at_float - (float2)flood;
|
||||
float dist = length(dist_vec);
|
||||
if (dist <= 1) {
|
||||
result = g_gbuff_textures[g_constants.emittance_tex_urid][flood];
|
||||
result = emittance_tex[flood];
|
||||
break;
|
||||
} else {
|
||||
at_float += ray_dir * dist;
|
||||
@ -101,13 +104,15 @@ SH_ENTRY(ROOTSIG) void cs(struct cs_input input)
|
||||
if (id.x >= g_constants.tex_width || id.y >= g_constants.tex_height) {
|
||||
return; /* Overflow */
|
||||
}
|
||||
float4 albedo = g_gbuff_textures[g_constants.albedo_tex_urid][id];
|
||||
|
||||
Texture2D<float4> albedo_tex = g_gbuff_textures[g_constants.albedo_tex_urid];
|
||||
RWTexture2D<float4> write_tex = g_write_textures[g_constants.write_tex_urid];
|
||||
|
||||
float4 albedo = albedo_tex[id];
|
||||
float4 lighting = get_light_at_pos(id);
|
||||
|
||||
float4 color = albedo * lighting;
|
||||
// float4 color = albedo + lighting;
|
||||
|
||||
/* Tonemap */
|
||||
/* Tone map */
|
||||
/* TODO: Dynamic exposure based on average scene luminance */
|
||||
color *= g_constants.exposure;
|
||||
color.rgb = tone_map(color.rgb);
|
||||
@ -115,5 +120,5 @@ SH_ENTRY(ROOTSIG) void cs(struct cs_input input)
|
||||
/* Gamma correct */
|
||||
color = pow(abs(color), 1/g_constants.gamma);
|
||||
|
||||
g_write_textures[g_constants.write_tex_urid][id] = color;
|
||||
write_tex[id] = color;
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
"maxAnisotropy = 1)"
|
||||
|
||||
ConstantBuffer<struct sh_ui_constants> g_constants : register(b0);
|
||||
Texture2D g_textures[] : register(t0, space0);
|
||||
Texture2D<float4> g_textures[] : register(t0, space0);
|
||||
StructuredBuffer<struct sh_ui_instance> g_instances : register(t0, space1);
|
||||
|
||||
SamplerState g_sampler : register(s0);
|
||||
@ -78,7 +78,8 @@ SH_ENTRY(ROOTSIG) struct ps_output ps(struct ps_input input)
|
||||
|
||||
/* Texture */
|
||||
if (input.vs.tex_nurid >= 0) {
|
||||
color *= g_textures[NURID(input.vs.tex_nurid)].Sample(g_sampler, input.vs.uv);
|
||||
Texture2D<float4> tex = g_textures[NURID(input.vs.tex_nurid)];
|
||||
color *= tex.Sample(g_sampler, input.vs.uv);
|
||||
}
|
||||
|
||||
output.SV_Target0 = color;
|
||||
|
||||
@ -2539,6 +2539,8 @@ struct render_sig {
|
||||
struct dx12_resource *emittance;
|
||||
struct dx12_resource *emittance_flood_a;
|
||||
struct dx12_resource *emittance_flood_b;
|
||||
|
||||
u32 tick;
|
||||
};
|
||||
|
||||
struct material_instance_desc {
|
||||
@ -2586,6 +2588,7 @@ INTERNAL struct render_sig *render_sig_alloc(void)
|
||||
sig->ui_rect_instance_descs_arena = arena_alloc(GIBI(1));
|
||||
sig->ui_shape_verts_arena = arena_alloc(GIBI(1));
|
||||
sig->ui_shape_indices_arena = arena_alloc(GIBI(1));
|
||||
sig->tick = 1;
|
||||
|
||||
return sig;
|
||||
}
|
||||
@ -2609,6 +2612,8 @@ INTERNAL void render_sig_reset(struct render_sig *sig)
|
||||
/* Reset grids */
|
||||
sig->num_material_grid_descs = 0;
|
||||
arena_reset(sig->material_grid_descs_arena);
|
||||
|
||||
++sig->tick;
|
||||
}
|
||||
|
||||
struct gp_render_sig *gp_render_sig_alloc(void)
|
||||
@ -2990,7 +2995,7 @@ struct gp_resource *gp_run_render(struct gp_render_sig *render_sig, struct gp_re
|
||||
/* Set constants */
|
||||
struct sh_shade_constants constants = ZI;
|
||||
/* TODO: Remove this */
|
||||
constants.time = sh_float_from_f32((f32)SECONDS_FROM_NS(sys_time_ns()));
|
||||
constants.tick = sh_uint_from_u32(sig->tick);
|
||||
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_flood_tex_urid = sh_uint_from_u32(emittance_flood_read->srv_descriptor->index);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user