power_play/res/sh/shade.hlsl
2025-07-16 17:00:38 -05:00

44 lines
1.5 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 */
}
g_write_textures[g_constants.write_tex_urid][job_id.xy] += g_read_textures[g_constants.albedo_tex_urid][job_id.xy];
//g_write_textures[g_constants.write_tex_urid][job_id.xy] = float4(1, 0, 0, 1);
}