Skip to content

Fix colour values not being decoded/encoded #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/modules/capture/accumulate.comp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ 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);
Expand All @@ -23,6 +34,9 @@ void main() {
vec4 frameColor = imageLoad(image_frame, coords);
vec4 sampleColor = imageLoad(image_sample, coords);

vec4 newColor = sampleColor + frameColor * weight;
vec4 newColor = vec4(
sampleColor.rgb + sRGB_EOTF(frameColor.rgb) * weight,
sampleColor + frameColor * weight // alpha channel isn't encoded
);
imageStore(image_sample, coords, newColor);
}
Binary file modified src/modules/capture/accumulate.spv
Binary file not shown.
7 changes: 7 additions & 0 deletions src/modules/capture/color_conversion.comp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ layout (binding = 1) buffer OutputBuffer {
uint8_t output_buffer[];
};

// sRGB opto-electronic transfer function
vec3 sRGB_OETF(vec3 value)
{
return pow(value, vec3(1.0 / 2.2));
}

void main() {
vec2 size = textureSize(image_sample, 0);
uint width = uint(size.x), height = uint(size.y);
Expand All @@ -20,6 +26,7 @@ void main() {
return;

vec4 color = texture(image_sample, vec2(x + 0.5, y + 0.5));
color.rgb = sRGB_OETF(color.rgb);

// The OpenGL coordinate system is upside-down compared to the usual video coordinate systems.
// Let's invert it here in the shader.
Expand Down
Binary file modified src/modules/capture/color_conversion.spv
Binary file not shown.