diff --git a/src/helpers/cm/ColorManagement.hpp b/src/helpers/cm/ColorManagement.hpp index e970ff592..ecde9396d 100644 --- a/src/helpers/cm/ColorManagement.hpp +++ b/src/helpers/cm/ColorManagement.hpp @@ -89,6 +89,7 @@ namespace NColorManagement { } inline std::string tfToString(eTransferFunction tf) { switch (tf) { + case CM_TRANSFER_FUNCTION_LINEAR: return "TF:INTERNAL LINEAR NOT NORMALISED"; case CM_TRANSFER_FUNCTION_BT1886: return "TF:BT1886"; case CM_TRANSFER_FUNCTION_GAMMA22: return "TF:GAMMA22"; case CM_TRANSFER_FUNCTION_GAMMA28: return "TF:GAMMA28"; @@ -400,6 +401,17 @@ namespace NColorManagement { .primaries = NColorPrimaries::BT709, .luminances = {.min = 0, .max = 10000, .reference = 80}, }); + + // For internal use only + // not normalised to 0.0 - 1.0 + // luminance values should be set to default SDR settings in SDR mode and to output settings in HDR mode + // keep srgb primaries to avoid conversions for image exports + static const auto LINEAR_NN_IMAGE_DESCRIPTION = CImageDescription::from(SImageDescription{ + .transferFunction = NColorManagement::CM_TRANSFER_FUNCTION_LINEAR, + .primariesNameSet = true, + .primariesNamed = NColorManagement::CM_PRIMARIES_SRGB, + .primaries = NColorPrimaries::BT709, + }); } template diff --git a/src/render/shaders/glsl/cm_helpers.glsl b/src/render/shaders/glsl/cm_helpers.glsl index 0c7d3d510..ae4b63ae8 100644 --- a/src/render/shaders/glsl/cm_helpers.glsl +++ b/src/render/shaders/glsl/cm_helpers.glsl @@ -127,6 +127,7 @@ vec3 tfST240(vec3 color) { vec3 toLinearRGB(vec3 color, int tf) { switch (tf) { + case CM_TRANSFER_FUNCTION_LINEAR: return color; case CM_TRANSFER_FUNCTION_EXT_LINEAR: return color; case CM_TRANSFER_FUNCTION_ST2084_PQ: return tfInvPQ(color); case CM_TRANSFER_FUNCTION_GAMMA22: return pow(max(color, vec3(0.0)), vec3(2.2)); @@ -179,7 +180,7 @@ vec3 fromLinearRGB(vec3 color, int tf) { } vec4 fromLinear(vec4 color, int tf) { - if (tf == CM_TRANSFER_FUNCTION_EXT_LINEAR) + if (tf == CM_TRANSFER_FUNCTION_EXT_LINEAR || tf == CM_TRANSFER_FUNCTION_LINEAR) return color; color.rgb /= max(color.a, 0.001); @@ -189,6 +190,9 @@ vec4 fromLinear(vec4 color, int tf) { } vec4 fromLinearNit(vec4 color, int tf, vec2 range) { + if (tf == CM_TRANSFER_FUNCTION_LINEAR) + return color; + color.rgb = (color.rgb - range[0] * color.a) / (range[1] - range[0]); // @gulafaran color.rgb /= max(color.a, 0.001); color.rgb = fromLinearRGB(color.rgb, tf); @@ -231,7 +235,8 @@ vec4 pixColor.rgb *= pixColor.a; #else pixColor.rgb = convertMatrix * pixColor.rgb; - pixColor = toNit(pixColor, srcTFRange); + if (srcTF != CM_TRANSFER_FUNCTION_LINEAR) + pixColor = toNit(pixColor, srcTFRange); pixColor.rgb *= pixColor.a; #if USE_TONEMAP pixColor = tonemap(pixColor, dstxyz, maxLuminance, dstMaxLuminance, dstRefLuminance, srcRefLuminance); diff --git a/src/render/shaders/glsl/constants.h b/src/render/shaders/glsl/constants.h index bbab5284b..db8b2cc1d 100644 --- a/src/render/shaders/glsl/constants.h +++ b/src/render/shaders/glsl/constants.h @@ -1,6 +1,7 @@ #ifndef CONSTANTS_H #define CONSTANTS_H //enum eTransferFunction +#define CM_TRANSFER_FUNCTION_LINEAR 0 // not normalised #define CM_TRANSFER_FUNCTION_BT1886 1 #define CM_TRANSFER_FUNCTION_GAMMA22 2 #define CM_TRANSFER_FUNCTION_GAMMA28 3