48 lines
1.6 KiB
HLSL
48 lines
1.6 KiB
HLSL
#include "sh/common.hlsl"
|
|
|
|
/* ========================== *
|
|
* Root signature
|
|
* ========================== */
|
|
|
|
#define ROOTSIG \
|
|
"RootConstants(num32BitConstants = 5, b0), " \
|
|
"DescriptorTable(SRV(t0, space = 0, numDescriptors = unbounded, flags = DESCRIPTORS_VOLATILE)), " \
|
|
"DescriptorTable(UAV(u0, space = 1, 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 g_read_textures[] : register(t0, space0);
|
|
RWTexture2D<float4> g_write_textures[]: register(u0, space1);
|
|
|
|
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)
|
|
{
|
|
uint3 job_id = input.SV_DispatchThreadID;
|
|
if (job_id.x >= g_constants.tex_width || job_id.y >= g_constants.tex_height) {
|
|
return; /* Overflow */
|
|
}
|
|
float4 old_color = g_read_textures[g_constants.write_tex_urid][job_id.xy];
|
|
float4 albedo = g_read_textures[g_constants.albedo_tex_urid][job_id.xy];
|
|
float4 emittance = g_read_textures[g_constants.emittance_tex_urid][job_id.xy];
|
|
float4 final_color = old_color + albedo + emittance;
|
|
|
|
g_write_textures[g_constants.write_tex_urid][job_id.xy] = final_color;
|
|
}
|