您需要 登录 才可以下载或查看,没有账号?注册
x
gamma -> linear 转化:
-- 比较“官方”的转化:
if (C_srgb <= 0.04045)
C_lin = C_srgb / 12.92;
else
C_lin = pow((C_srgb + 0.055) / 1.055, 2.4);
-- 通常上面的近似使用 gamma2.2来转化:
C_lin_1 = pow(C_srgb, 2.2);
-- 更准确效果的转换 gamma = 2.233333333
C_lin_2 = pow(C_srgb, 2.233333333);
-- cubic转化,避免了pow函数的性能消耗,而且还有更好的近似:
C_lin_3 = 0.012522878 * C_srgb +
0.682171111 * C_srgb * C_srgb +
0.305306011 * C_srgb * C_srgb * C_srgb;
HLSL:
float3 RGB = sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878);
linear -> gamma转化:
-- 比较”官方“的转化
if (C_lin <= 0.0031308)
C_srgb = C_lin * 12.92;
else
C_srgb = 1.055 * pow(C_lin, 1.0 / 2.4) - 0.055;
-- 通常上面的近似使用 gamma2.2来转化:
C_srgb_1 = pow(C_lin, 0.4545454545); // 1/2.2 = 0.4545454545
-- 比官方更准确一点的转化:
C_srgb_2 = max(1.055 * pow(C_lin, 0.416666667) - 0.055, 0);
-- cubic转化,避免了pow函数的性能消耗,而且还有更好的近似:
C_srgb_3 = 0.585122381 * sqrt(C_lin) +
0.783140355 * sqrt(sqrt(C_lin)) -
0.368262736 * sqrt(sqrt(sqrt(C_lin)));
HLSL:
float3 S1 = sqrt(RGB);
float3 S2 = sqrt(S1);
float3 S3 = sqrt(S2);
float3 sRGB = 0.585122381 * S1 + 0.783140355 * S2 - 0.368262736 * S3;
|