DepthToLinearDepth.azsl 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. #include <viewsrg.srgi>
  9. #include <Atom/Features/PostProcessing/FullscreenVertex.azsli>
  10. ShaderResourceGroup PassSrg : SRG_PerPass
  11. {
  12. // D32_FLOAT_S8X24_UINT (Format:15) depthStencil texture
  13. Texture2D<float2> m_depthStencil;
  14. Sampler PointSampler
  15. {
  16. MinFilter = Point;
  17. MagFilter = Point;
  18. MipFilter = Point;
  19. AddressU = Clamp;
  20. AddressV = Clamp;
  21. AddressW = Clamp;
  22. };
  23. }
  24. struct PSOutput
  25. {
  26. float m_linearDepth : SV_Target0;
  27. };
  28. PSOutput MainPS(VSOutput IN)
  29. {
  30. PSOutput OUT;
  31. float zDepth = PassSrg::m_depthStencil.Sample(PassSrg::PointSampler, IN.m_texCoord).r;
  32. float linearDepth =
  33. abs(((ViewSrg::GetFarZTimesNearZ()) / (ViewSrg::GetFarZMinusNearZ() * zDepth - ViewSrg::GetFarZ())));
  34. OUT.m_linearDepth = linearDepth;
  35. return OUT;
  36. }