55 lines
2.2 KiB
HLSL
55 lines
2.2 KiB
HLSL
#include "sh/common.hlsl"
|
|
|
|
/* ========================== *
|
|
* Root signature
|
|
* ========================== */
|
|
|
|
#define ROOTSIG \
|
|
"RootConstants(num32BitConstants = 6, b0), " \
|
|
"DescriptorTable(SRV(t0, space = 0, numDescriptors = unbounded, flags = DESCRIPTORS_VOLATILE)), " \
|
|
"DescriptorTable(SRV(t0, space = 1, numDescriptors = unbounded, flags = DESCRIPTORS_VOLATILE)), " \
|
|
"DescriptorTable(UAV(u0, space = 2, numDescriptors = unbounded, flags = DESCRIPTORS_VOLATILE)), " \
|
|
\
|
|
\
|
|
"StaticSampler(s0, " \
|
|
"filter = FILTER_MIN_MAG_MIP_POINT, " \
|
|
"addressU = TEXTURE_ADDRESS_CLAMP, " \
|
|
"addressV = TEXTURE_ADDRESS_CLAMP, " \
|
|
"addressW = TEXTURE_ADDRESS_CLAMP, " \
|
|
"maxAnisotropy = 1)"
|
|
|
|
ConstantBuffer<struct sh_shade_constants> g_constants : register(b0);
|
|
Texture2D<float4> g_gbuff_textures[] : register(t0, space0);
|
|
Texture2D<uint> g_emittance_flood_textures[] : register(t0, space1);
|
|
RWTexture2D<float4> g_write_textures[]: register(u0, space2);
|
|
|
|
SamplerState g_sampler : register(s0);
|
|
|
|
/* ========================== *
|
|
* Compute shader
|
|
* ========================== */
|
|
|
|
struct cs_input {
|
|
DECLS(uint3, SV_DispatchThreadID);
|
|
};
|
|
|
|
[numthreads(8, 8, 1)]
|
|
SH_ENTRY(ROOTSIG) void cs(struct cs_input input)
|
|
{
|
|
uint2 id = input.SV_DispatchThreadID.xy;
|
|
if (id.x >= g_constants.tex_width || id.y >= g_constants.tex_height) {
|
|
return; /* Overflow */
|
|
}
|
|
float4 old_color = g_gbuff_textures[g_constants.write_tex_urid][id];
|
|
float4 albedo = g_gbuff_textures[g_constants.albedo_tex_urid][id];
|
|
float4 emittance = g_gbuff_textures[g_constants.emittance_tex_urid][id];
|
|
|
|
uint emittance_flood_packed = g_emittance_flood_textures[g_constants.emittance_flood_tex_urid][id];
|
|
uint2 emittance_flood = uint2(emittance_flood_packed >> 16, emittance_flood_packed & 0xFFFF);
|
|
emittance_flood *= emittance_flood_packed < 0xFFFFFFFF;
|
|
|
|
float4 final_color = old_color + albedo + float4(float(emittance_flood.x) / float(g_constants.tex_width), float(emittance_flood.y) / float(g_constants.tex_height), 0, 1);
|
|
|
|
g_write_textures[g_constants.write_tex_urid][id] = final_color;
|
|
}
|