From 22154fa272201950a3d37e2a40d9dc3a9cc92329 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 16 Mar 2025 21:50:15 +0000 Subject: opengl: simplify cm pipeline fixes a few mistakes, and skips the CM shader in cpu instead of adding a costly branch ref #9641 --- src/render/shaders/CM.frag | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'src/render/shaders') diff --git a/src/render/shaders/CM.frag b/src/render/shaders/CM.frag index dd695d44..aa26f97d 100644 --- a/src/render/shaders/CM.frag +++ b/src/render/shaders/CM.frag @@ -8,7 +8,6 @@ uniform sampler2D tex; //uniform samplerExternalOES texture0; uniform int texType; // eTextureType: 0 - rgba, 1 - rgbx, 2 - ext -uniform int skipCM; uniform int sourceTF; // eTransferFunction uniform int targetTF; // eTransferFunction uniform mat4x2 sourcePrimaries; @@ -408,26 +407,28 @@ void main() { if (discardAlpha == 1 && pixColor[3] <= discardAlphaValue) discard; - if (skipCM == 0) { - pixColor.rgb /= max(pixColor.a, 0.001); - pixColor.rgb = toLinearRGB(pixColor.rgb, sourceTF); - mat3 srcxyz = primaries2xyz(sourcePrimaries); - mat3 dstxyz; - if (sourcePrimaries == targetPrimaries) - dstxyz = srcxyz; - else { - dstxyz = primaries2xyz(targetPrimaries); - pixColor = convertPrimaries(pixColor, srcxyz, sourcePrimaries[3], dstxyz, targetPrimaries[3]); - } - pixColor = toNit(pixColor, sourceTF); - pixColor.rgb *= pixColor.a; - pixColor = tonemap(pixColor, dstxyz); - if (sourceTF == CM_TRANSFER_FUNCTION_SRGB && targetTF == CM_TRANSFER_FUNCTION_ST2084_PQ) - pixColor = saturate(pixColor, srcxyz, sdrSaturation); - pixColor *= sdrBrightnessMultiplier; - pixColor = fromLinearNit(pixColor, targetTF); + pixColor.rgb /= max(pixColor.a, 0.001); + pixColor.rgb = toLinearRGB(pixColor.rgb, sourceTF); + mat3 srcxyz = primaries2xyz(sourcePrimaries); + mat3 dstxyz; + + if (sourcePrimaries == targetPrimaries) + dstxyz = srcxyz; + else { + dstxyz = primaries2xyz(targetPrimaries); + pixColor = convertPrimaries(pixColor, srcxyz, sourcePrimaries[3], dstxyz, targetPrimaries[3]); } + pixColor = toNit(pixColor, sourceTF); + pixColor.rgb *= pixColor.a; + pixColor = tonemap(pixColor, dstxyz); + + if (sourceTF == CM_TRANSFER_FUNCTION_SRGB && targetTF == CM_TRANSFER_FUNCTION_ST2084_PQ) + pixColor = saturate(pixColor, srcxyz, sdrSaturation); + + pixColor *= sdrBrightnessMultiplier; + pixColor = fromLinearNit(pixColor, targetTF); + if (applyTint == 1) pixColor = vec4(pixColor.rgb * tint.rgb, pixColor[3]); -- cgit v1.2.3