LumixEngine/data/pipelines/sss_blit.shd
2023-09-15 17:27:30 +02:00

37 lines
No EOL
1.1 KiB
Text

include "pipelines/common.glsl"
compute_shader [[
layout(std140, binding = 4) uniform Data {
vec2 u_size;
vec2 padding;
float u_current_frame_weight;
};
layout(local_size_x = 16, local_size_y = 16, local_size_z = 1) in;
layout (binding = 0) uniform sampler2D u_history;
layout (binding = 1) uniform sampler2D u_depthbuf;
layout (rgba8, binding = 0) uniform image2D u_gbuffer2;
layout (r8, binding = 1) uniform image2D u_sss;
void main()
{
ivec2 ij = ivec2(gl_GlobalInvocationID.xy);
if (any(greaterThanEqual(ij, ivec2(u_size.xy)))) return;
float depth = texelFetch(u_depthbuf, ij, 0).x;
vec2 uv = (vec2(ij) + 0.5) / u_size.xy;
vec2 uv_prev = cameraReproject(uv, depth);
float current = imageLoad(u_sss, ij).x;
if (all(lessThan(uv_prev, vec2(1))) && all(greaterThan(uv_prev, vec2(0)))) {
float prev = texture(u_history, uv_prev).x;
current = mix(prev, current, u_current_frame_weight);
imageStore(u_sss, ij, vec4(current));
}
vec4 gb2v = imageLoad(u_gbuffer2, ij);
gb2v.w = min(current, gb2v.w);
imageStore(u_gbuffer2, ij, gb2v);
}
]]