-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathaccumulate.comp
42 lines (33 loc) · 1.31 KB
/
accumulate.comp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#version 450
// Copied from the color conversion shader where it gave the best performance.
#define WORKGROUP_SIZE 4
layout (local_size_x = WORKGROUP_SIZE, local_size_y = WORKGROUP_SIZE, local_size_z = 1) in;
layout (binding = 0, rgba8) uniform readonly image2D image_frame;
layout (binding = 1, rgba16) uniform image2D image_sample;
layout (push_constant) uniform push_constants {
float weight;
};
// Transfer functions are the sRGB reference monitor EOTF of x^2.2, explicitly
// not the piecewise functions.
// https://en.wikipedia.org/wiki/SRGB#Transfer_function_(%22gamma%22)
// definitions of terms: https://cie.co.at/e-ilv
// sRGB electro-optical transfer function
vec3 sRGB_EOTF(vec3 value)
{
return pow(value, vec3(2.2));
}
void main() {
ivec2 size = imageSize(image_frame);
uint width = uint(size.x), height = uint(size.y);
uint x = gl_GlobalInvocationID.x, y = gl_GlobalInvocationID.y;
if (x >= width || y >= height)
return;
ivec2 coords = ivec2(x, y);
vec4 frameColor = imageLoad(image_frame, coords);
vec4 sampleColor = imageLoad(image_sample, coords);
vec4 newColor = vec4(
sampleColor.rgb + sRGB_EOTF(frameColor.rgb) * weight,
sampleColor + frameColor * weight // alpha channel isn't encoded
);
imageStore(image_sample, coords, newColor);
}