libkwineffects/kwinglutils: handle alpha better with colormanagement

Alpha from clients is encoded in electrical values, and some of our code also relies
on compositing results being encoded in electrical values. To take care of this, we
need to undo the premultiplication of rgb values, convert to or from linear, and then
re-do the premultiplication. This doesn't result in exactly the same blending behavior
with linear blending, but it's close enough
This commit is contained in:
Xaver Hugl 2023-06-13 14:44:48 +02:00
parent c112bb5c56
commit debe76733c

View file

@ -856,7 +856,9 @@ QByteArray ShaderManager::generateFragmentSource(ShaderTraits traits) const
}
if (traits & ShaderTrait::TransformColorspace) {
stream << " if (sourceNamedTransferFunction == sRGB_EOTF) {\n";
stream << " result.rgb /= max(result.a, 0.001);\n";
stream << " result.rgb = sdrBrightness * srgbToLinear(result.rgb);\n";
stream << " result.rgb *= result.a;\n";
stream << " }\n";
stream << " result.rgb = doTonemapping(colorimetryTransform * result.rgb, maxHdrBrightness);\n";
}
@ -871,7 +873,9 @@ QByteArray ShaderManager::generateFragmentSource(ShaderTraits traits) const
}
if (traits & ShaderTrait::TransformColorspace) {
stream << " if (destinationNamedTransferFunction == sRGB_EOTF) {\n";
stream << " result.rgb /= max(result.a, 0.001);\n";
stream << " result.rgb = linearToSrgb(doTonemapping(result.rgb, sdrBrightness) / sdrBrightness);\n";
stream << " result.rgb *= result.a;\n";
stream << " } else if (destinationNamedTransferFunction == PQ_EOTF) {\n";
stream << " result.rgb = nitsToPq(result.rgb);\n";
stream << " }\n";