PPTonemapCommon.bslinc 3.4 KB

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