Skip to content

Commit bf5c94a

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 2f0fb35 commit bf5c94a

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/qtAliceVision/FloatImageViewer.frag

Lines changed: 6 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,15 @@ 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+
color.rgb = pow(pow(max(color.rgb * vec3(gain), vec3(0.0, 0.0, 0.0)), vec3(1.0 / gamma)), vec3(1.0 / 2.2));
26+
2527
fragColor.r = color[int(channelOrder[0])];
2628
fragColor.g = color[int(channelOrder[1])];
2729
fragColor.b = color[int(channelOrder[2])];
2830
fragColor.a = int(channelOrder[3]) == -1 ? 1.0 : color[int(channelOrder[3])];
2931
fragColor.a *= qt_Opacity;
32+
3033
if (distance(vec2(vTexCoord.x * aspectRatio, vTexCoord.y), vec2(fisheyeCircleCoord.x * aspectRatio, fisheyeCircleCoord.y)) > fisheyeCircleRadius && fisheyeCircleRadius > 0.0)
3134
{
3235
fragColor.a *= 0.001;

0 commit comments

Comments
 (0)