Skip to content

Commit 83ae06f

Browse files
committed
[qtAliceVision] FloatImageViewer: Clamp color values in fragment shader
Clamp negative values in the FloatImageViewer fragment shader before performing the successive `pow`. The result of `pow` is undefined when it is provided negative values. On Linux platforms, it still gives the expected result, but on Windows this leads to issues.
1 parent 3130c3e commit 83ae06f

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/qtAliceVision/FloatImageViewer.frag

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ layout(location = 0) in vec2 vTexCoord;
33
layout(location = 0) out vec4 fragColor;
44

55
layout(std140, binding = 0) uniform buf { // warning: matches layout and padding of FloatImageViewerMaterial::uniforms!
6-
mat4 qt_Matrix; // offset 0
7-
float qt_Opacity; // offset 64
6+
mat4 qt_Matrix; // offset 0
7+
float qt_Opacity; // offset 64
88
float _padding1;
99
float _padding2;
1010
float _padding3;
@@ -21,12 +21,19 @@ layout(binding = 1) uniform sampler2D tex;
2121
void main()
2222
{
2323
vec4 color = texture(tex, vTexCoord);
24-
color.rgb = pow(pow((color.rgb * vec3(gain)), vec3(1.0/gamma)), vec3(1.0 / 2.2));
24+
25+
// Clamp negative values after applying the gain as the
26+
// result of 'pow' is undefined when provided with negative values
27+
vec3 clampedColorWithGain = max(color.rgb * vec3(gain), vec3(0.0, 0.0, 0.0));
28+
29+
color.rgb = pow(pow(clampedColorWithGain, vec3(1.0 / gamma)), vec3(1.0 / 2.2));
30+
2531
fragColor.r = color[int(channelOrder[0])];
2632
fragColor.g = color[int(channelOrder[1])];
2733
fragColor.b = color[int(channelOrder[2])];
2834
fragColor.a = int(channelOrder[3]) == -1 ? 1.0 : color[int(channelOrder[3])];
2935
fragColor.a *= qt_Opacity;
36+
3037
if (distance(vec2(vTexCoord.x * aspectRatio, vTexCoord.y), vec2(fisheyeCircleCoord.x * aspectRatio, fisheyeCircleCoord.y)) > fisheyeCircleRadius && fisheyeCircleRadius > 0.0)
3138
{
3239
fragColor.a *= 0.001;

0 commit comments

Comments
 (0)