DisplayMapper.azsl 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. //
  9. // ACES implementation
  10. // This implementation is partially ported from NVIDIA HDR sample.
  11. // https://developer.nvidia.com/high-dynamic-range-display-development
  12. //
  13. #include <Atom/Features/SrgSemantics.azsli>
  14. #include <Atom/Features/PostProcessing/FullscreenPixelInfo.azsli>
  15. #include <Atom/Features/PostProcessing/FullscreenVertex.azsli>
  16. #include <Atom/Features/PostProcessing/PostProcessUtil.azsli>
  17. #include <Atom/Features/PostProcessing/Aces.azsli>
  18. ////////////////////////////////////////////////////////////////////////////////
  19. ShaderResourceGroup PassSrg : SRG_PerPass
  20. {
  21. Texture2D<float4> m_framebuffer;
  22. Sampler LinearSampler
  23. {
  24. MinFilter = Linear;
  25. MagFilter = Linear;
  26. MipFilter = Linear;
  27. AddressU = Clamp;
  28. AddressV = Clamp;
  29. AddressW = Clamp;
  30. };
  31. // ACES spline parameters
  32. SegmentedSplineParamsC9 m_acesSplineParams;
  33. // Color transformation matrix from XYZ to the display's color primaries
  34. row_major float3x3 m_XYZtoDisplayPrimaries;
  35. // Reference white and black luminance values
  36. float2 m_cinemaLimits;
  37. // Bit flag for control the ODT shader behavior
  38. int m_outputDisplayTransformFlags;
  39. // The ODT output mode
  40. int m_outputDisplayTransformMode;
  41. // Gamma adjustment to be applied to compensate for the condition of the viewing environment.
  42. // Note that ACES uses a value of 0.9811 for adjusting from dark to dim surrounding.
  43. float m_surroundGamma;
  44. // Optional gamma value that is applied as basic gamma curve OETF
  45. float m_gamma;
  46. }
  47. ////////////////////////////////////////////////////////////////////////////////
  48. // A entry point of pixel shader.
  49. PSOutput MainPS(VSOutput IN)
  50. {
  51. PSOutput OUT;
  52. OutputTransformParameters outputTransformParams;
  53. outputTransformParams.outputDisplayTransformFlags = PassSrg::m_outputDisplayTransformFlags;
  54. outputTransformParams.outputDisplayTransformMode = PassSrg::m_outputDisplayTransformMode;
  55. outputTransformParams.cinemaLimits = PassSrg::m_cinemaLimits;
  56. outputTransformParams.acesSplineParams = PassSrg::m_acesSplineParams;
  57. outputTransformParams.XYZtoDisplayPrimaries = PassSrg::m_XYZtoDisplayPrimaries;
  58. outputTransformParams.surroundGamma = PassSrg::m_surroundGamma;
  59. outputTransformParams.gamma = PassSrg::m_gamma;
  60. float3 color = PassSrg::m_framebuffer.Sample(PassSrg::LinearSampler, IN.m_texCoord).rgb;
  61. // Convert to ACEScg to ACES color space
  62. float3 aces = mul(AP1ToAP0Mat, color.rgb);
  63. float3 oces = ReferenceRenderingTransform(aces);
  64. OUT.m_color.rgb = OutputDeviceTransform(oces, outputTransformParams);
  65. OUT.m_color.w = 1;
  66. return OUT;
  67. }