PPTonemapCommon.bslinc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. mixin PPTonemapCommon
  2. {
  3. code
  4. {
  5. static const float3x3 sRGBToXYZMatrix =
  6. {
  7. 0.4124564f, 0.3575761f, 0.1804375f,
  8. 0.2126729f, 0.7151522f, 0.0721750f,
  9. 0.0193339f, 0.1191920f, 0.9503041f,
  10. };
  11. static const float3x3 XYZTosRGBMatrix =
  12. {
  13. 3.2409699419f, -1.5373831776f, -0.4986107603f,
  14. -0.9692436363f, 1.8759675015f, 0.0415550574f,
  15. 0.0556300797f, -0.2039769589f, 1.0569715142f,
  16. };
  17. static const float3x3 D65ToD60Matrix =
  18. {
  19. 1.01303, 0.00610531, -0.014971,
  20. 0.00769823, 0.998165, -0.00503203,
  21. -0.00284131, 0.00468516, 0.924507,
  22. };
  23. static const float3x3 D60ToD65Matrix =
  24. {
  25. 0.987224, -0.00611327, 0.0159533,
  26. -0.00759836, 1.00186, 0.00533002,
  27. 0.00307257, -0.00509595, 1.08168,
  28. };
  29. static const float3x3 XYZToACES2065Matrix =
  30. {
  31. 1.0498110175, 0.0000000000,-0.0000974845,
  32. -0.4959030231, 1.3733130458, 0.0982400361,
  33. 0.0000000000, 0.0000000000, 0.9912520182,
  34. };
  35. static const float3x3 XYZToACEScgMatrix =
  36. {
  37. 1.6410233797, -0.3248032942, -0.2364246952,
  38. -0.6636628587, 1.6153315917, 0.0167563477,
  39. 0.0117218943, -0.0082844420, 0.9883948585,
  40. };
  41. static const float3x3 ACEScgToXYZMatrix =
  42. {
  43. 0.6624541811, 0.1340042065, 0.1561876870,
  44. 0.2722287168, 0.6740817658, 0.0536895174,
  45. -0.0055746495, 0.0040607335, 1.0103391003,
  46. };
  47. /**
  48. * Encodes a 10bit linear color into 8bits by converting it to log space.
  49. *
  50. * @param linearColor Linear color.
  51. * @return Encoded color in log space.
  52. */
  53. float3 LinearToLogColor(float3 linearColor)
  54. {
  55. float linearRange = 14.0f;
  56. float linearGrey = 0.18f;
  57. float exposureGrey = 444.0f;
  58. float3 logColor = log2(linearColor) / linearRange - log2(linearGrey) / linearRange + exposureGrey / 1023.0f;
  59. return saturate(logColor);
  60. }
  61. /**
  62. * Decodes a 8bit log encoded color back into linear space.
  63. *
  64. * @param logColor Log space color.
  65. * @return Color in linear space.
  66. */
  67. float3 LogToLinearColor(float3 logColor)
  68. {
  69. float linearRange = 14.0f;
  70. float linearGrey = 0.18f;
  71. float exposureGrey = 444.0f;
  72. return exp2((logColor - exposureGrey / 1023.0f) * linearRange) * linearGrey;
  73. }
  74. /**
  75. * Converts a linear color value in sRGB/Rec.709 color space into gamma space (applies Rec.709 transfer function).
  76. * Rec.709 values are suitable for HDTVs and projectors.
  77. *
  78. * @param linearColor Linear color in sRGB/Rec.709 color space.
  79. * @return Gamma corrected color.
  80. */
  81. float3 LinearToGammaRec709(float3 linearColor)
  82. {
  83. // TODO: Clamp lower end of linear color so it isn't denormalized?
  84. return min(linearColor * 4.5f, pow(max(linearColor, 0.018f), 0.45f) * 1.099f - 0.099f);
  85. }
  86. /**
  87. * Converts a linear color value in sRGB/Rec.709 color space into gamma space (applies sRGB transfer function).
  88. * sRGB values are suitable for PC displays.
  89. *
  90. * @param linearColor Linear color in sRGB/Rec.709 color space.
  91. * @return Gamma corrected color.
  92. */
  93. float3 LinearToGammasRGB(float3 linearColor)
  94. {
  95. // TODO: Clamp lower end of linear color so it isn't denormalized?
  96. return min(linearColor * 12.92f, pow(max(linearColor, 0.00313067f), 1.0f/2.4f) * 1.055f - 0.055f);
  97. }
  98. };
  99. };