diff options
| author | Vaxry <43317083+vaxerski@users.noreply.github.com> | 2026-03-04 19:50:28 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-04 19:50:28 +0000 |
| commit | 10754745a97c99449ef40db58bd425f5a91f9993 (patch) | |
| tree | 8aa9f57bcfb2157b9fbdc387c9021db6e6a38e46 /src/render/shaders | |
| parent | 8271cfc97b76d573f9122032d6cf5db256d63470 (diff) | |
render/cm: add ICC profile pipeline (#12711)
Adds an ICC profile pipeline, loading via config and applying via 3D LUTs.
Diffstat (limited to 'src/render/shaders')
| -rw-r--r-- | src/render/shaders/glsl/CM.glsl | 42 | ||||
| -rw-r--r-- | src/render/shaders/glsl/shadow.frag | 6 |
2 files changed, 35 insertions, 13 deletions
diff --git a/src/render/shaders/glsl/CM.glsl b/src/render/shaders/glsl/CM.glsl index 36c95a90..66d84885 100644 --- a/src/render/shaders/glsl/CM.glsl +++ b/src/render/shaders/glsl/CM.glsl @@ -6,6 +6,10 @@ uniform mat3 convertMatrix; #include "sdr_mod.glsl" +uniform int useIcc; +uniform highp sampler3D iccLut3D; +uniform float iccLutSize; + //enum eTransferFunction #define CM_TRANSFER_FUNCTION_BT1886 1 #define CM_TRANSFER_FUNCTION_GAMMA22 2 @@ -65,6 +69,24 @@ uniform mat3 convertMatrix; #define M_E 2.718281828459045 + +vec3 applyIcc3DLut(vec3 linearRgb01) { + vec3 x = clamp(linearRgb01, 0.0, 1.0); + + // Map [0..1] to texel centers to avoid edge issues + float N = iccLutSize; + vec3 coord = (x * (N - 1.0) + 0.5) / N; + + return texture(iccLut3D, coord).rgb; +} + +vec3 xy2xyz(vec2 xy) { + if (xy.y == 0.0) + return vec3(0.0, 0.0, 0.0); + + return vec3(xy.x / xy.y, 1.0, (1.0 - xy.x - xy.y) / xy.y); +} + // The primary source for these transfer functions is https://www.itu.int/dms_pubrec/itu-r/rec/bt/R-REC-BT.1361-0-199802-W!!PDF-E.pdf vec3 tfInvPQ(vec3 color) { vec3 E = pow(clamp(color.rgb, vec3(0.0), vec3(1.0)), vec3(PQ_INV_M2)); @@ -250,7 +272,7 @@ vec4 fromLinear(vec4 color, int tf) { return color; } -vec4 fromLinearNit(vec4 color, int tf, vec2 range) { +vec4 fromLinearNit(vec4 color, int tf, vec2 range) { if (tf == CM_TRANSFER_FUNCTION_EXT_LINEAR) color.rgb = color.rgb / SDR_MAX_LUMINANCE; else { @@ -267,12 +289,18 @@ vec4 fromLinearNit(vec4 color, int tf, vec2 range) { vec4 doColorManagement(vec4 pixColor, int srcTF, int dstTF, mat3 dstxyz) { pixColor.rgb /= max(pixColor.a, 0.001); pixColor.rgb = toLinearRGB(pixColor.rgb, srcTF); - pixColor.rgb = convertMatrix * pixColor.rgb; - pixColor = toNit(pixColor, srcTFRange); - pixColor.rgb *= pixColor.a; - #include "do_tonemap.glsl" - pixColor = fromLinearNit(pixColor, dstTF, dstTFRange); - #include "do_sdr_mod.glsl" + + if (useIcc == 1) { + pixColor.rgb = applyIcc3DLut(pixColor.rgb); + pixColor.rgb *= pixColor.a; + } else { + pixColor.rgb = convertMatrix * pixColor.rgb; + pixColor = toNit(pixColor, srcTFRange); + pixColor.rgb *= pixColor.a; + #include "do_tonemap.glsl" + pixColor = fromLinearNit(pixColor, dstTF, dstTFRange); + #include "do_sdr_mod.glsl" + } return pixColor; } diff --git a/src/render/shaders/glsl/shadow.frag b/src/render/shaders/glsl/shadow.frag index 71e96ddb..06aa605c 100644 --- a/src/render/shaders/glsl/shadow.frag +++ b/src/render/shaders/glsl/shadow.frag @@ -5,7 +5,6 @@ precision highp float; in vec4 v_color; in vec2 v_texcoord; -uniform int skipCM; uniform int sourceTF; // eTransferFunction uniform int targetTF; // eTransferFunction uniform mat3 targetPrimariesXYZ; @@ -18,8 +17,6 @@ uniform float roundingPower; uniform float range; uniform float shadowPower; -#include "CM.glsl" - float pixAlphaRoundedDistance(float distanceToCorner) { if (distanceToCorner > radius) { return 0.0; @@ -92,8 +89,5 @@ void main() { // premultiply pixColor.rgb *= pixColor[3]; - if (skipCM == 0) - pixColor = doColorManagement(pixColor, sourceTF, targetTF, targetPrimariesXYZ); - fragColor = pixColor; }
\ No newline at end of file |
